CS 1044 Test 1 Form A Key Fall 1999 Q A Explanation 1 4 9 - 6/4 == 9 - 1 == 8 2 3 4.0 + 24.0 / 4.0 == 4.0 + 6.0 == 10.0 3 2 32 - 14 % 5 == 32 - 4 == 28 4 2 5.5 * 4 + 2 == 22.0 + 2 == 24.0 5 2 16 / 5 == 3; assign to float, so value is 3.0 6 2 12 / 2.4 == 5.0 (computed as a double) 7 1 5 + 2.7 == 7.7; truncated to 7 when assigned to an int 8 1,2 ^ is the C++ XOR logical bitwise operator 9 1 F indicates a float literal constant 10 1 (han * darth) == (0) == logically false in C++ 11 1 -- is a unary operator. For questions 12-16: infile >> zero >> one >> zero; // reads values 55, 23 and 72 infile.ignore(100, '\n'); // skips to beginning of second line infile >> one >> two >> three >> four; // reads values 17, 30, 95 and 28 infile.ignore(100, '\n'); // skips to beginning of third line infile.ignore(100, '\n'); // skips to beginning of fourth line infile >> three >> three >> three; // reads values 19, 92 and 36 infile.ignore(100, '\n'); // skips to beginning of fifth line if (!infile.eof()) infile >> four; // reads value 8 12 4 13 1 14 3 15 5 16 2 For questions 17-18: ifile.get(ch1); // reads value 6 ifile >> i1; // reads value 97 ifile.get(ch2); // reads value c 17 6 18 4 For questions 19-20: the program reads four values per loop execution, computing the sum of the odd terms in sumo and computing the sum of the even terms in sume. It prints the even pair subtotals each time through the loop and printing the odd sum after the loop. So, it will print the following lines of output: 10 13 16 38 19 5 20 5 For questions 20-23: ifile >> ch1 >> ch2 >> i1 >> ch3; //reads '6' '9' 7 'c' 21 1 22 3,10 single quotes around 7 make it a char, but acceptable 23 4 For questions 24-28: bill >> aFloat1 >> aFloat2; // reads values 3.14 and 2.71828 cout << aFloat1 << aFloat2; bill.ignore(4, '\n'); //skips the next 4 chars " 43 " bill >> anInt1 >> anInt2 >> anInt3; // reads values 0, 27 and 24 bill.ignore( 80, '\n'); // skips to beginning of third line cout << anInt1 << anInt2 << anInt3; bill >> anInt4; // reads the value 45 cout << anInt4; 24 2 25 2 26 3 27 4 28 6 29 1 1 - 1 <= 0 == 0 <= 0 whihc is true 30 1,3 missing semicolon, otherwise NOT(false) is true 31 3 the math operator "not equals to" is not a C++ operator 32 1 (-(-3) >= 3) == (3) >= 3) which is true 33 2 Components evaluate to: (2==3 || 1<0 && 0-3<=-3) == ( F || F && T ) == ( F || F ) == false, the AND is evaluated before the OR; 34 3 (7 % 9 >= 2+5) == 7 >= 7 is true, so go into first if-clause; Z is reset to 2; 9-3*5 >= -7 == 9-15 >= -7 is true, so go into 2nd if-clause, Z is reset back to 1; 35 2 The else goes with the first if since the {} force the first if to complete before the else; the code is equivalent to: if (87 >= 95) { if (rank <= 5) cout << "Nice job!"; } else cout << "Good job!"; 36 5 3/2 == 1 is true so execute first if clause, reset delta to 3; x decrements to 2; 2/2 == 0 is false, so skip second if clause x decrements to 1; 1/2 == 0 is true so execute last if clause, reset delta to 4; 37 7 The logical negation of (R <=T) is (R > T) thus 1 is equivalent since it is the opposite and operations are switched. 3 is equivalent since it expresses the if else as separate ifs. 38 4 goes to case 2 but then falls through to case 6 39 4 goes to case 4 but then falls through to case 6 40 1 no match, goes to the default case