Selected Midterm Questions

Day Class

1. Logic errors are

  1. Detected by the preprocessor
  2. Detected at run time
  3. Detected at compile time
  4. Not detectable by the computer

More information: Lesson 2.4.2

2. Given a single C++ program, which of the following functions can it have?
A. foo(int a)
B. foo(int a, int b)
C. foo(double a)
D. foo(double a, double b)
E. foo(int b)

  1. All of the functions
  2. A, B, D, E
  3. A, B, C, D
  4. A, C, D, E

More information: Lesson 6.1

Evening Class

1. Which of the following is a valid identifier?

  1. big-number
  2. 50Percent
  3. double
  4. $SalesTax

More information: Lesson 2.1.6

2. What is the output from the following loop:

int i = 10;
while (i >= 0)
   cout << i << endl;
   i--;
  1. No output
  2. The numbers 0 through 10 will be output
  3. The number 10 will be output exactly one time
  4. The number 10 will be output infinitely

More information: Lesson 4.4.5

3. What is the output of the following function and function call?

void calculateCost(int count, float& subTotal, float taxCost);

float tax = 0.0,
subTotal = 0.0;

// start of fragment
calculateCost(15, subTotal, tax);
cout << "The cost for 15 items is " << subTotal
    << ", and the tax for " << subTotal << " is "
    << tax << endl;
// end of fragment

void calculateCost(int count, float& subTotal, float taxCost) {
   if ( count < 10) {
       subTotal = count * 0.50;
   } else {
       subTotal = count * 0.20;
   }
   taxCost = 0.1 * subTotal;
}
  1. The cost for 15 items is 3.00, and the tax for 3.00 is 0.30
  2. The cost for 15 items is 0.00, and the tax for 3.00 is 0.00
  3. The cost for 15 items is 0.00, and the tax for 3.00 is 0.30
  4. The cost for 15 items is 3.00, and the tax for 3.00 is 0.00

More information: Lesson 6.3