Koofer Test 1 Key 1 6 2 6 3 1 The executable is produced by the linker; design logic is your responsibility. 4 1 5 2 There is no ** arithmetic operator in C++. 6 1 7 1 8 2 Single quotes are used to delimit a single character; this is a string of three characters, properly written as "abc". 9 2 Missing curly braces. The if-clause is just the single statement fred = zach; and so there is no uncompleted if to match the else. 10 1 11 2 The extract operator >> can only be used with an input stream; cout is an output stream. 12 3 12 / 3.0 + 5 / 2 == 4.0 + 2 == 6.0 13 6 10 % 1 + 3 / 5 == 0 + 0 = 0 14 2 10 / 3 * 9 == 3 * 9 == 27 15 1 9.0 - 6.0 / 2.0 + 3.0 == 9.0 - 3.0 + 3.0 == 9.0 16 4 5.0 / 3.0 == 1.666666..; assigning that to an int variable truncates it to 1 17 2 5 / 2.0 == 2.5 18 5 a char variable can hold only one character, not a character string 19 4 This is not a particularly good question. The expression (34 <= 50) is true, so the int variable anInt will be assigned a value representing true. That value may or may not be 1. 20 3 15 / 6 == 2; assigning that to a float variable promotes it to 2.0 For 21 and 22, the input statement will act as follows: cin >> i1 // reads the first integer value, 14 >> i2 // reads the next integer value, 7 >> i3; // fails since the next value in the // input stream is a period, which // cannot be part of an integer value 21 3 22 4 Again, not a very good question since the actual value of i3 after a failed read attempt targeting i3 depends on the implementation of your compiler. With Visual C++, i3 will be unchanged. With other compilers, the value of i3 may be random or 0. For 23 and 24, the input statement will act as follows: cin >> i1 // reads the first integer value, 14 >> i2 // reads the next decimal value, 7.9 >> c1 // reads the next nonwhitespace character, '1' >> c2; // reads the next nonwhitespace character, 'A' 23 2 24 3 For 25 and 26, the input statement will act as follows: cin >> i1 // reads the first integer value, 14 >> i2 // reads the next integer value, 7 >> c1 // reads the next nonwhitespace character, '.' >> i3; // reads the next integer value, 9 25 2 26 2 27 2 The expression 30 + 12 is evaluated and its value is printed; the setw() setting doesn't allow for any space between the end of the string "The answer is" and the following value. 28 3 29 ? Bad question -- should have setw() and setprecision() for formatting. The closest answer would be 2. 30 1 31 1 32 2 33 ? Not a syntax error. The expression is evaluated from left to right. C <= B is true; the value of true is then compared to A. If true is represented by 1, the value of the second comparison is then also true. 34 1 35 1 36 1 Remember: && evaluates before || in the absence of parens. 37 2 The ignore() reads and discards the first four characters. 38 2 The ignore() reads and discards the first line. 39 3 40 4 41 3 42 2 Hard question: consider the case J >= K. 43 5 One line for each endl printed. 44 8 1a1a1a1a1a starts with a digit; if is a reserved word 45 3 46 3 47 4,5 Badly chosen answers. A syntax error would prevent compilation (that includes undeclared identifiers). Answer 2 is not a useful option. Missing curly braces might cause a compile-time error; missing curly braces could also simple cause the code to operate incorrectly, perhaps producing a run-time error, perhaps producing incorrect results. 48 3 The else goes with the first if, because of the curly braces. 49 3 50 3