CS 1044 Test 1 Form A Key Fall 1998 Q A Explanation 1 2 8/5 + 3 == 1 + 3 == 4 2 3 18.0/6.0 + 6.0 == 3.0 + 6.0 == 9.0 3 3 11%4 + 1 == 3 + 1 == 4 4 4 7.1*3 - 1 == 21.3 - 1 == 20.3 5 2 9%4 == 1; assign to float, so value is 1.0 6 2 16/2.5 == 6.4 (computed as a double) 7 1 15 - 5.8 == 9.2; truncated to 9 when assigned to an int 8 1 9 2 There is no ** arithmetic operator in C++ 10 1 11 1 This is an equality comparison -- syntactically correct but useless. For questions 12-15: infile >> uno >> uno; // reads values 12 and 13 infile.ignore(100, '\n'); // skips to beginning of second line infile >> deuce >> trey; // reads values 7 and 20 infile.ignore(100, '\n'); // skips to beginning of third line infile >> deuce >> trey; // reads values 9 and 28 infile.ignore(100, '/n'); // skips to end of input file; // '/n' should be '\n' if (!infile.eof()) infile >> quad; // reads nothing 12 2 13 5 14 2 15 4 For questions 16-17: ifile >> i1; // reads value 432 ifile.get(ch1); // reads value 'b' ifile.get(ch2); // reads tab '\t' after 'b' 16 3 17 6 For questions 18-19: the program reads three values per pass, computing the sum of those three values and printing the sum. So, it will print the following lines of output: 9 17 7 16 18 4 19 6 For questions 20-22: ifile >> ch1 // reads '4' >> i1 // reads 32 >> ch2 // reads 'b' >> ch3; // reads '1' (>> skips over whitespace) 20 1 21 5 22 5 For questions 23-28: fred >> anInt1 // reads 43 >> anInt2 // reads -21 >> aFloat1 // reads 17.9 >> anInt3; // reads 19 fred.ignore(80, '\n'); // skips to beginning of second line fred >> aFloat2 // reads 2.4 >> anInt3; // reads 1 fred.ignore(4, '\n'); // skips ".8 -", not to next line fred >> anInt2; // reads 12 23 2 24 3 25 4 26 10 27 4 28 7 29 2 0 + 1 < 1 is false 30 1 -(-7) >= 7 is true 31 1 Components evaluate ato: F && F || T; no parentheses, so the AND is evaluated before the OR; we get F || T which is true 32 2 !true == false 33 3 "!==" is a syntax error 34 2 2*A >= B is true, so go into first if-clause; D is reset to 1; C < B +2*D is false now, so go to else-clause 35 7 The else goes with the second if; the code is equivalent to: if (score >= 95) { if (rank <= 5) cout << "Nice job!"; else cout << "good job!"; } 36 3 i%2 == 0 if and only if i is even, so only the second if has any effect 37 8 38 1 goes to default 39 4 goes to case 3 but then falls through to case 5 40 4