Key for Test 1 Form B Q A Reason ----------------------------------------------------------------------------------- 1 1 Hare is false, so !Hare is true; since T||T and T||F are both T the value of Burke doesn't matter. 2 2 Evaluates to F || F, which is false. 3 1 Precedence rules imply this evaluates as X || (Y && Z). Evaluates to T || (??) which is true, regardless of how the "and" works out. For questions 12 and 13, execution of the code results in: iFile >> ch1 // read '3' >> ch2 // read 'A' >> i1 // skip the tab and read the int 129 >> ch3; // read 'B' 4 6 5 7 6 1 5.0 / 2 == 2.5; assigning to an int truncates and stores the value 2 7 2 19 / 5 == 3; assigning to a double stores the value 3.0 8 3 5 / 2 * 2 + 1 == ((5 / 2) * 2) + 1 (precedence rules) == 2 * 2 + 1 9 2 7 / 5 + 4 / 5.0 ---> 1 + 0.8 (integer division) ---> 1.0 + 0.8 (mixed expression, int converts to double) For questions 5 through 7, execution of the code results in: In >> Zero >> One >> One >> Two; // 55, 25, 72 and 40 are read In.ignore(100, '\n'); // advance to beginning of second line In.ignore(100, '\n'); // advance to beginning of third line In >> Three >> Four >> Zero; // 6, 34 and 82 are read In.ignore(100, '\t'); // read the tab after the 82 In.ignore(100, '\t'); // read the 66 and the following tab In >> First; // read the string "Opie" 10 3 11 4 12 5 13 3 The call number is guaranteed to end with a tab. There is no guarantee it will not contain whitespace characters. 1 would only read to a whitespace character. 2 would read the entire line. 14 6 The category ends with a tab, and it is also guaranteed to not contain any whitespace characters. 2 would read the rest of the line, including the year. 15 9 Execution would result in: In >> CallNumber; // reads "QA271" and stops at the space In >> Title; // skips the space, reads "P983" and stops at the tab 16 1 Execution would result in: getline(In, CallNumber, '\t'); // read "QA271 P983" and stop at the tab getline(In, Title, '\t'); // read "How to Solve It" and stop In >> Category; // read "Mathematics" 17 4 Straight from the notes. 18 1 There is no case for '-8', so the default case is executed, setting Enter to -1. 19 3 First the body for case '1' is executed, setting Enter to -4. However, that case doesn't include a break, so execution falls through to the body for case '2' and Enter is set to -6. That case does include a break, so the switch is exited. 20 3 The condition for the outer if is true, so the if-clause is executed. The first statement increments Z, setting it to 2. The condition of the inner if is also true, so its if-clause is executed, decrementing Z back to 1. For questions 17 through 20, execution of the code results in: In >> aFloat1 >> anInt1; // reads 3.14 and 2 In >> aFloat2 >> aFloat3; // reads .76 and 828 21 2 22 7 The setw() setting causes the printing of a trailing '0'. 23 6 The setprecision() setting causes the value to be rounded to 1 digit after the decimal point. [The leading zero is default behavior.] 24 4 The setprecision() setting causes the printing of two trailing zeros. 25 2 Straight from the notes. 26 8 When the first if is reached, X % 2 == 1, so X is added to Delta, setting it to 3, and X is incremented to 4. When the second if is reached, X % 2 == 0, so X is added to Delta, setting it to 7, and X is incremented to 5; When the third if is reached, X % 2 == 1, so Delta is not changed. 27 4 The expression LName + "," + FName evaluates to "Leghorn,Foghorn" 28 2 The length of "Leghorn" is 7. 123456789012345678901234567890 29 7 1 would print: Leghorn 74 2 would print "Leghorn" and then print Age in a field of width 13. 3 would print "Leghorn" in a field of width 10 and then print Age in a field of width 10.