Test 3 CSCI 130 Fall 2022

Name ______________________________________

  1. Boolean
    1. [2 points] What values can a boolean variable assume?
    2. [3 points] Name three operations unique to boolean values.
    3. [2 points] Name or provide two operations which take other types and produce a boolean value.

  2. If and If-Else statements
    1. [3 points] Provide the syntax for the if else statement.
    2. [3 points] Provide the preferred use case for the if else statement.
    3. [3 points] Describe the semantics for the if else statement.
    4. [3 points] Provide a code segment that illustrates the preferred use of the if else statement. Explain your code.
    5. [3 points] Explain why the following code could confuse a programmer and cause a logic error. What logic error will occur when this code is run? How should this error be avoided?
      if (age < 18)
        cout << "You are not old enough to enter." << endl;
        cout << "You are an adult." << endl;
        cout << "You may enter." << endl; 

  3. Else If construct
    1. [8 points] Use the if, else if, else construction described in the book and in class to write a code segment which takes a person's weight (stored in weight) along with a guess at the weight (stored in weightGuess) and prints "Too Low" if the guess is lower than the weight, "Too High" if the guess is higher than the weight or "Just Right" if the guess and the weight are equal.

  4. Common Errors
    1. [5 points] Explain the error and what will happen when the following code is executed. You should assume there are no syntax errors and cost and amountPaid have been assigned a value.
      if (cost = amountPaid) {
          changeDue = 0;
      } else {
          changeDue = cost - amountPaid;

  5. Testing
    1. [3 points] What is white box testing?
    2. [3 points] What is black box testing?
    3. [3 points] What are "good" cases to test for in a program if you do not have access to the code?
    4. [3 points] What are "good" cases to test for in a program if you do have access to the code?
    5. [3 points] Why is it best to automate the testing process?