Practice Final Exam for ENGR 131

I did not make up these questions, so they may have errors or typos – if you find any, let me know.
For matching problems, some choices may be used more than once, and some may not be used at all.

4. The grammatical rules of a programming language are known as its:
A. Variable
B. Features
C. Syntax
D. Semantics
E. None of the above

6. Which of the following is NOT a C++ keyword?
A. int
B. main
C. const
D. void
E. None of the above

8. \n is an example of a(n)
A. File Declaration
B. Interface
C. Escape sequence
D. Named constant
E. None of the above

10. #include is an example of a(n):
A. Library
B. Implementation
C. Compiler directive
D. Interface
E. Data Type

14. Determine the value of the following C++ expression and select the corresponding answer: 25-6*2-3%13
A. 3
B. 0
C. 13
D. Not a valid expression
E. None of the above.

For questions 20-21 assume the following declarations:
int Num = 131;
char Ch = 'A',
Course[] = "ENGR";

and indicate the correct choice for the exact output produced by the following statements.

20. cout << Course << setw(5) << Num << Ch << endl;
A. "ENGR" 131     A/n
B. "ENGR"00131A
C. ENGR00131A
D. ENGR  131A
E. None of the above

21. cout << "\nCourse:" << Course << "-" << Num % 100 << "\n";
A. nCourse:ENGR-31
B. Course:ENGR-131%100
C. Course:ENGR-%100
D. Course:ENGR-31
E. None of the above

22. Assume that the following code is executed.
int I=3,
j=++I,
k=I++;
I*=3;

The value of I is now:
A. 12
B. 3
C. 9
D. 15
E. None of the above

For questions 23-24, assume that:

int M = 1;
bool P = true, Q = false;

23. Evaluate this expression:   M <= 5 && P || Q
A. true
B. false

24. Evaluate this expression:   (M <= 5) && (P && Q)
A. true
B. false

Use the choices below to answer questions 25-35:
A. if statement
B. do-while statement
C. for statement
D. while statement

25. Which of the above is a loop that is always executed at least once? B
29. Which of the above is a selection structure? A
31. Which of the above is often used to implement counting loops? C
32. Which of the above is a pretest loop? D
33. Which of the above is a post-test loop? B
34. Which of the above is the most general loop in that it can be used to implement a pretest loop, a post-test loop, or a test-in-the-middle loop? C

Assume the following function prototypes for questions 36-41:
void Fun1(int Num1, unsigned Num2, int& Num3);
double Fun2(int Num4, char& Ch1);
int Fun3(int Num5, char Ch2="A");

Use the choices below to answer questions 36-41:
A. Argument
B. Value parameter
C. Reference Parameter
D. Default value
E. Return Type

36. Num1 is a(n): B
37. Num3 is a(n): C
38. double is a(n): E
39. void indicates this for Fun1: E
40. In the function call: Fun1(Int1, Real1, Int2);
Int1 is a(n): A
41. "A" in the prototype of Fun3 is a(n): D

For questions 50-61, use the following program segments:

int Code; 
cin >> Code;

/* Part I */
if (Code == 1)
   cout << "Top\n";
else
   cout << "Bottom\n";

/* Part II */
if (Code > 0)
   if (Code < 7)c
      cout << "Left\n";
   else
      cout << "Middle\n";
else
   cout << "Right\n";

/* Part 3 */
switch (Code) {
case 0:
   cout << "Right\n";
   break;
case 1:
   cout << "Left\n";
   break;
default:
   cout << "Middle\n"; 
}

Assume the following answer choices:
A. Top
B. Bottom
C. Left
D. Middle
E. Right

For questions 50-52 assume that the value 0 is input for Code. Use the answer choices to indicate what output will be produced by each of the program parts:

50. /* Part I */ B
51. /* Part 2 */ E
52. /* Part 3 */ E

For questions 53-55 assume that the value 1 is input for Code. Use the answer choices to indicate what output will be produced by each of the program parts.

53. /* Part I */ A
54. /* Part 2 */ C
55. /* Part 3 */ C

For questions 56-58 assume that the value 8 is input for Code. Use the answer choices to indicate what output will be produced by each of the program parts.

56. /* Part I */ B
57. /* Part 2 */ D
58. /* Part 3 */ D

For questions 59-61 assume that the value 7 is input for Code. Use the answer choices to indicate what output will be produced by each of the following or why an error occurs:

59. /* Part I */ B
60. /* Part 2 */ D
61. /* Part 3 */ D

62. How many lines of output (if any) are produced by the program segment shown below:
for (int k=1; k<= 3; k++)
   for (int I=k; I<=3; I++)
      "Able was I ere I saw Elba\n";
A. 3
B. 6
C. 9
D. 12
E. None of the above

91. A function that calls itself would produce:
A. a compiler error
B. a linker error
C. a loader error
D. a run time error
E. None of the above

Use the following choices for questions 93-95:
A. counter
B. sentinel
C. EOF

93. If both the range of data values and the number of data values to be input is unknown, then the best way to control input is ____? C

94. If the number of data values to be input is known, then the best way to control input is ____? A

95. If the range of data values is known but the number of data values varies, the best way to control input is ____ ? B

Match the Definitions in problems 101-115 to the appropriate Definitions below:
1. !
2. ||
3. /
4. B
5. :
6. B--
7. " "
8. ;
9. =
10. &&
11. 11
12. ==
13. %
14. { }
15. \

101. This letter of the alphabet has an ASCII code of 66 4
102. Relational operator meaning equivalent to 12
103. Modulo division operation 13
104. Used to indicate division operation 3
105. Escape character for escape sequences 15
106. Logical OR operator 2
107. Logical AND operator 10
108. Statement delimiter 8
109. Logical NOT operator 1
110. Assignment operator 9
111. Compound or Block statement delimiter 14
112. String delimiter 7
113. Equivalent to B=B - 1 6