CSE 232 Spring 2012 Name: __________________________________ Lab Exercise #3 -- C++ Control Structures A. Selective and Repetitive Control Constructs a) Examine the C++ program below, and answer the questions about that program in the blanks provided. =============================================================================== using namespace std; #include int main() { int A = 0, B = 0, C = 0, D = 0; // Give the value displayed by each of the output operations below. while (A <= 8) { A += 2; switch (A%3) { case 0: ++B; case 1: ++C; } ++D; } cout << endl; cout << "Value of A: " << A << endl; // Value of A: ____________ cout << "Value of B: " << B << endl; // Value of B: ____________ cout << "Value of C: " << C << endl; // Value of C: ____________ cout << "Value of D: " << D << endl << endl; // Value of D: ____________ A = B = C = 0; cout << "Enter the input sequence: 10 15 20 -1 25 -2" << endl; do { cin >> A; ++B; C += A; } while (A > 0); cout << endl; cout << "Value of A: " << A << endl; // Value of A: ____________ cout << "Value of B: " << B << endl; // Value of B: ____________ cout << "Value of C: " << C << endl << endl; // Value of C: ____________ A = B = C = 0; for (A=2; A<15; ++A) { ++B; if (A > 10) { ++C; } } cout << "Value of A: " << A << endl; // Value of A: ____________ cout << "Value of B: " << B << endl; // Value of B: ____________ cout << "Value of C: " << C << endl << endl; // Value of C: ____________ A = B = C = 0; for (A=13; A>3; A-=3 ) { if (A/2*2 == A) { ++B; } ++C; } cout << "Value of A: " << A << endl; // Value of A: ____________ cout << "Value of B: " << B << endl; // Value of B: ____________ cout << "Value of C: " << C << endl << endl; // Value of C: ____________ } =============================================================================== b) After completing (a) above, compile and execute the C++ program to check your answers. The source code for the program is available on the CSE system as "/user/cse232/Labs/lab03.partA.cpp". If any of your answers are incorrect, re-work the appropriate questions. B. The file "/user/cse232/Labs/lab03.partB.design" contains the design document for a program which will assist a teacher to compute statistics about a set of exam scores. The file "/user/cse232/Labs/lab03.partB.cpp" contains the outline of a C++ program which implements that design, which you are to complete and demonstrate to the your TA. Copy the skeleton program into your account and use the design document, as well as the comments in the source code, to guide your modifications and enhancements. Test the completed program using a variety of input values, then demonstrate the results to your TA.