
































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
During the course of work of the programming, we learn the core of the programming. The main points disucss in these lecture slides are:Additional Control Structures, Switch Statement, Multi-Way Branching, Do-While Statement, Do-While Statement, Break and Continue Statements, Selection Control Structure, Value of Integral Expression, Logical Errors
Typology: Slides
1 / 40
This page cannot be seen from the preview
Don't miss anything!

































4
float weightInPounds = 165.8; char weightUnit;
... // User enters letter for desired weightUnit switch (weightUnit) { case „P‟ : case „p‟ : cout << weightInPounds << “ pounds “ << endl; break; case „O‟ : case „o‟ : cout << 16.0 * weightInPounds << “ ounces “ << endl; break; case „K‟ : case „k‟ : cout << weightInPounds / 2.2 << “ kilos “ << endl; break; case „G‟ : case „g‟ : cout << 454.0 * weightInPounds << “ grams “ << endl; break; default : cout << “That unit is not handled! “ << endl; break; } 4
Do-While is a looping control structure in which the loop condition is tested after each iteration of the loop
SYNTAX
do { Statement
} while ( Expression );
Loop body statement can be a single statement or a block
8
void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response has been input // && response == „y‟ or „n‟ { do { cin >> response; // Skips leading whitespace if ((response != „y‟) && (response != „n‟)) cout << “Please type y or n : “; } while ((response != „y‟) && (response != „n‟)); }
Example of Do-While
8
When the expression is tested and found to be false, the loop is exited and control passes to the statement that follows the Do-while statement (^) 10
Statement
Expression
int num;
for (num = 1; num <= 3; num++)
{
cout << num << “Potato” << endl;
}
Example of Repetition
int num;
for (num = 1; num <= 3; num++) cout << num << “Potato” << endl;
14
num
Example of Repetition
int num;
for(num = 1; num <= 3; num++)
cout << num << “Potato” << endl;
16
num
true
Example of Repetition
int num;
for (num = 1; num <= 3; num++)
cout << num << “Potato” << endl;
17
num
1Potato
Example of Repetition
int num;
for(num = 1; num <= 3; num++)
cout << num << “Potato” << endl;
19
num
true
1Potato
Example of Repetition
int num;
for (num = 1; num <= 3; num++)
cout << num << “Potato” << endl;
20
num
1Potato
2Potato