Lecture-4 - ECE 3090 Software for Engineering Systems Prof....

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ECE 3090 Software for Engineering Systems Prof. Hongwei Wu School of Electrical and Computer Engineering Georgia Institute of Technology (Savannah) Some useful links SGIs Standard Template Library (http://www.sgi.com/tech/stl/) This archive of the Standard Template Library, or STL, is a C++ library of container classes, algorithms, and iterators; it provides many of the basic algorithms and data structures of computer science. http://www.cplusplus.com/ A good on-line reference for the C runtime library is dinkumware.com (http://www.dinkumware.com/manuals/). On this web page, you have to click the graphical icon with the puppy-feet on it to enter the reference. Todays topics: Making decisions Relational Operators IF ELSE statement IF ELSE IF ELSE statement Nested IF statements Logical operators More about variable definitions and scope Comparing strings Conditional operator SWITCH statement Rational Operators To compare numbers to determine relative orders. Operators > Greater than < Smaller than >= Greater than or equal to <= Smaller than or equal to == Equal to (Dont be confused with = ) != Not equal to Value of a relationship: true of false , can be assigned to a boolean variable; Relational expressions have a higher precedence than the assignment operator. int x = 8; bool compareResult; compareResult = (x == 8); cout << compareResult; compareResult = (x > 8); cout << compareResult; compareResult = (x >= 8); cout << compareResult; IF statement Allows statements to be conditionally executed or skipped over General format: Either if ( relational expression ) { statements; } or if ( relational statement ) statement; When relational expression is true, the statement(s) are executed, and skipped over otherwise 1. // This program averages three test scores 2. #include <iostream> 3. #include <iomanip> 4. using namespace std; 5. int main() 6. { 7. int score1, score2, score3; // To hold three test scores 8. double average; // TO hold the average score 9. // Get the three test scores. 10. cout << "Enter 3 test scores and I will average them: "; 11. cin >> score1 >> score2 >> score3; 12. 13. // Calculate and display the average score. 14. average = (score1 + score2 + score3) / 3.0; 15. cout << fixed << showpoint << setprecision(1); 16. cout << "Your average is " << average << endl; 17. 18. // If the average is greater than 95, congratulate the user. 19. char GPA; 20. if (average > 95) 21. { 22. GPA = 'A'; 23. cout << "Congratulations! That's a high score!\n"; 24. } 25. return 0; 26. } IF ELSE statement Provides two possible paths of execution Performs one statement or block if the relational expression is true, otherwise performs another statement or block....
View Full Document

This note was uploaded on 10/24/2009 for the course ECE 3090 taught by Professor Staff during the Fall '08 term at Georgia Institute of Technology.

Page1 / 21

Lecture-4 - ECE 3090 Software for Engineering Systems Prof....

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online