Question: C++ 1) Draw CORRECT and easy to read flow charts for the code examples 1, 3, 4 and 5 above in this lecture. Use a
C++
1) Draw CORRECT and easy to read flow charts for the code examples 1, 3, 4 and 5 above in this lecture. Use a program to draw them or draw them by hand. Use skinny lines with direction arrows to connect the diamonds(decisions), rectangles(actions), ovals(start or end), parallelograms(input or output).
Code Example 1 Try it #include using namespace std; int main( ) { // Sample program to print the value of i at each loop.. int i = 0; // 1st element of loop declare an initialize value while ( i < 10 ) { // 2nd element of loop condition/criteria cout << "i = " << i << endl; i++; // 3rd element of loop update value of condition variable } system ("pause"); return 0; }
Code Example 3 Try it #include using namespace std; int main ( ) { // Calculate grade average int numberGrades = 0; int sumGrades = 0; int aGrade = 0; cout << "How many grades to enter: "; cin >> numberGrades; int i = 1; // 1st element of loop - declare and set initial value while ( i <= numberGrades ) { // 2nd element of loop - condition cout << "Enter Grade: "; cin >> aGrade; sumGrades = sumGrades + aGrade; i++; // 3rd element of loop - update value } cout << "Grade Average = " << sumGrades/numberGrades << endl; system ("pause"); return 0; }
Code Example 4 Try it #include using namespace std; int main ( ) { // Print 10 by 10 square of diamonds // Declare and initialize loop variable. int i = 0; int j = 0; while ( i < 10 ){ i++; // Outside index while ( j < 10 ) { j++; // Inside index cout << "*"; } j=0; cout << endl; } system ("pause"); return 0; }
Code Example 5 Try it - This example runs ONCE #include using namespace std; int main( ) { // Sample program to print the value of i at each loop.. int i = 6; // 1st element of loop declare an initialize value do { cout << "i = " << i << endl; i = 11; // 2nd element of loop update value of condition variable to 11 } while ( i < 10 ); // 3rd element of loop check condition/criteria system ("pause"); return 0; }