{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

09 Exam 2 Review - Engineering101 Exam2Review QuoteoftheDay...

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

View Full Document Right Arrow Icon
Click to edit Master subtitle style Engineering 101 Exam 2 Review
Background image of page 1

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

View Full Document Right Arrow Icon
Quote of the Day - Overheard in  WoW There are 10 types of people who understand  binary, those who do and those who don’t.
Background image of page 2
Outline n Lectures 1 through 5 (you still need to know them) n Lecture 6 – Selection n Lecture 7 – Predicates and Intro to Loops n Lecture 8 – Loops
Background image of page 3

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

View Full Document Right Arrow Icon
Outline n Lecture 6 – Selection n Lecture 7 – Predicates and Intro to Loops n Lecture 8 – Loops n Lecture 9 – Data Types
Background image of page 4
Selection n Allows the selective execution of a portion  of your code depending on some condition. n Syntax in C++: if (condition)   statement_t else statement_f
Background image of page 5

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

View Full Document Right Arrow Icon
Selection n Allows the selective execution of a portion  of your code depending on some condition. n Syntax in C++: if ( condition )   statement_t else statement_f The statements can either be single line expressions or multiple expressions enclosed in braces.
Background image of page 6
Selection n Allows the selective execution of a portion  of your code depending on some condition. n Syntax in C++: if ( condition )   statement_t The else can be entirely removed.
Background image of page 7

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

View Full Document Right Arrow Icon
Selection n Allows the selective execution of a portion  of your code depending on some condition. n Syntax in C++: if ( condition1 )   statement_t1 else if ( condition2 ) statement_t2 else Or you can add more else conditions in the form of ‘else if’.
Background image of page 8
Using Selection To Check  n Streams are a particular case in point since  whenever you try to open or read from a file you  don’t know if the file might not exist or be  finished. ifstream infile(“myfile.data”); if(  infile.fail()  ){ cerr << “Problem with file” << endl; exit(EXIT_FAILURE); } stream.fail() can be used with any stream and returns true if the last action failed.
Background image of page 9

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

View Full Document Right Arrow Icon
fail() can also be used to read int x, n=0; ifstream infile(“myfile.data”); infile >> x; while (! infile.fail() ){ cout << x; n = n + 1; infile >> x; } cout << “read in “ << n << “ integers.” << endl;
Background image of page 10
Switch Statements n A switch statement is used to decide between a  number of cases n switch ( integer_expression ){ case  value expression case  value expression default:  expression } n The integer expression is evaluated and the thread of execution  starts from the matching case.  If none matches it starts from 
Background image of page 11

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

View Full Document Right Arrow Icon
switch (weekday){ case 1:  cout << “Monday”; break ; case 2: cout << “Tuesday”; break ; case 3:  cout << “Wednesday”;
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 46

09 Exam 2 Review - Engineering101 Exam2Review QuoteoftheDay...

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

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