Test 3 CSCI 130 Fall 2015

  1. If Statement
    1. [2 points] Give the syntax for the if-else statement
    2. [2 points] State the flow of control of the if-else statement
    3. [2 points] Give the preferred use case for an if-else statement
    4. [2 points] Critique the following code
      int age;
      cout << "Enter your age => " 
      cin >> age
      if (age <  DRIVING_AGE) {
          cout << "You are not old enough to drive legally" << endl;
      if (age >= DRIVING_AGE) {
          cout << "You are old enough to  drive legally." << endl;
  2. elseif
    1. [3 points] How can a programmer construct an if-then-else-if structure in C++? Give an example of the syntax.
    2. [2 points] Why would a programmer employ an if-then-else-if structure over a switch statement?
  3. Short Circuit Evaluation
    1. [2 points] What is short circuit evaluation of boolean expressions?
    2. [4 points] Give a short example of code where short circuit evaluation will occur. Explain your example.
  4. While Statement
    1. [2 points] Give the syntax for a while loop
    2. [3 points] Give three conditions necessary to build a successful loop.
  5. For Statement
    1. [2 points] Give the syntax for the for statement.
    2. [2 points] Give the flow of control for the for statement.
    3. [2 points] Given a segment of code showing how a for statement can be implemented as a while statement.
  6. String Functions
    1. [2 points] Describe the operation of the string at member function.
    2. [2 points] Describe the operation of the string find member function.
    3. [4 points] Write a small code segment which will convert the letters in the string inputPhrase to all uppercase characters.
  7. Testing
    1. [2 points] What is black box testing?
    2. [2 points] What is white box testing?
    3. [2 points] What is a test plan?
  8. Programming
    1. [6 points] Write a code fragment, including variable definitions, which will ask the user for a number between 0 and 5 and print the name of that number. Ie if the input is 0, print the word "zero". If the user inputs a nuber outside of the range, print "invalid input".