<< Back

Midterm 1 Review Supplements

Instructions

  1. Complete the following review handwritten on paper and make sure to put your name on your paper.
  2. Your work will be reviewed and graded, so make it presentable.
  3. The following problems are due before the test starts.
  4. Review of your work by another student is required for full credit. Add the following at the top of the first page of your paper:

    Reviewed by: reviewing student's name

    Discuss the issues and correct any problems found during the review.

Review Topics

^ top

A. Data Types (4m)

  1. Write the letter and heading for this problem on your paper.
  2. Review data types in lesson 3.1.3.
  3. On your paper, create three columns with these headings:
    Number Type/error Description of type/error
  4. For each of the following number examples in C++ code, write the information about the number under the above column headings. If there is an error, write "error" and explain why in the description. For example: (4m)
    3 int A positive integer
    1. 3
    2. -3
    3. 3.0
    4. 3.14
    5. 3 14/100
    6. 300,000
    7. 3e5
  5. Review your work with another student in the class and correct any problems.

Test Yourself (optional)

  1. The problem with the following code snippet is ________.
    int value;
    value = 1.23;
    
    1. The "value" variable is never initialized.
    2. The data type for the "value" variable is not specified.
    3. The "value" variable is never assigned a value.
    4. The "value" variable is assigned a decimal value, but it can store only a whole number value.
  2. In an airline reservation system, the cost of an airline ticket is required. The data type that should be used to store this value is a single ________.
    1. int
    2. long
    3. double
    4. short

B. Variables and Assignment

  1. Write the letter and heading for this problem on your paper.
  2. Review lesson 3.1.5: (Variable) Summary.
  3. On your paper, write the problem number (1a, 1b, ..., 2) and a solution to the following problems: (8m)
    1. Declare a single variable and assign the variable a value for storing each of the following types of data:
      1. Dollars and cents
      2. The count of the number of people in a room
      3. A single letter
      4. Whether or not a door is open or closed.
      5. A sequence of characters making up a person's name.
    2. Write the value of a and b on your paper after the following code snippet executes
      int a = 10;
      int b = 20;
      a = b;
      
      a is ________ b is ________
    3. Write the value of a and b on your paper after the following code snippet executes
      int a = 7;
      int b = 5;
      a = b;
      b = 3;
      
      a is ________ b is ________
  4. Review your work with another student in the class and correct any problems.

Test Yourself (Optional)

  1. The problem with the following code snippet is ________.
    int value;
    value = 1.23;
    
    1. The "value" variable is never initialized.
    2. The data type for the "value" variable is not specified.
    3. The "value" variable is never assigned a value.
    4. The "value" variable is assigned a decimal value, but it can store only a whole number value.

^ top

C. Counting and arithmetic (3m)

  1. Write the letter and heading for this problem on your paper.
  2. Review lesson 2.3.6: (Arithmetic) Summary.
  3. On your paper, write the problem number and a solution for the following problems:
    1. First operation performed in 1 + 2 * 3 / 4 % 5 is ________.
    2. The value of x after the following code executes is ________.
      double x = 9 / 4;
      
    3. The value of x after the following arithmetic expression and assignment is ________.
      double x = 1 + 2 * 3 / 4 % 5;
      
    4. Write the following math expression as C++ code: a + b all over 2
  4. Review your work with another student in the class and correct any problems.

    Hint: Verify your computations by trying them in C++.

Test Yourself (Optional)

  1. Of the following, the one that is NOT a complete statement for adding 1 to numAnts is ________.
    1. numAnts + 1;
    2. numAnts = numAnts + 1;
    3. numAnts = 1 + numAnts;
    4. numAnts = numAnts + 1 / 1;

^ top

D. Characters and ASCII

  1. Write the letter and heading for this problem on your paper.
  2. Review lesson 3.2.1: Type char.
  3. On paper, write the question numbers and the value of ch after executing each of the following statements. (3m)
    1. char ch = '0' + 3;;
    2. char ch = 'A' + 3;;
    3. char ch = 'd' - 'a' + 'A';;
    4. char ch = 'D' - 'A' + 'a';;
  4. Review your work with another student in the class and correct any problems.

    Hint: Verify your computations by displaying ch in C++.

^ top

E. Strings and Substrings

  1. Write the letter and heading for this problem on your paper.
  2. Review lesson 3.3.2: String Functions.
  3. On paper, write the question numbers and the code to extract the last word from each of the following strings. (3m)
    1. string str = "Do. Or do not. There is no try."; // George Lucas (Yoda);
    2. string str = "Whether You Believe You Can Do a Thing or Not, You Are Right."; // Henry Ford;
    3. string str = "It always seems impossible until it's done."; // Nelson Mandela;
    4. string str = "If you're going through hell, keep going."; // Winston Churchill;
    5. string str = "No one can make you feel inferior without your consent."; // Eleanor Roosevelt;
  4. Review your work with another student in the class and correct any problems.

    Hint: Verify your substring by displaying your code in C++.

^ top

F. Test Conditions

  1. Write the letter and heading for this problem on your paper.
  2. Review lesson 3.3.2: Relational Operators.
  3. On paper, write the question numbers and the value (true or false) of the following test conditions, given x = 3, y = 7. (3m)
    1. (x != y)
    2. (x == y)
    3. (x < y)
    4. (x >= y)
    5. (x <= 42)
  4. Review your work with another student in the class and correct any problems.

^ top

G. Tracing if-statements

  1. Write the letter and heading for this problem on your paper.
  2. Review the first half of section 3.3.6: (Conditional) Summary.
  3. On your paper, write the problem numbers and a solution to the following problems: (4m)
    1. The value of x after the following code executes is ________.
      int x = 7;
      if (x == 3) {
        x = 1;
      }
      
    2. The value of x after the following code executes is ________.
      int x = 3;
      int y = 4;
      if (x < y)
      {
        x = y;
      }
      
    3. The value of x after the following code executes is ________.
      int x = 5;
      if (x > 3)
      {
          x = x - 2;
      }
      else
      {
          x = x + 2;
      }
      
    4. The value of x after the following code executes is ________.
      int x = 1;
      if (x > 0)
      {
          x = x + 5;
      }
      else if (x > 1)
      {
          x = x + 2;
      }
      else
      {
          x = x + 7;
      }
      
  4. Review your work with another student in the class and correct any problems.

^ top

H. Tracing while Loops

  1. Write the letter and heading for this problem on your paper.
  2. Review the while loop in lesson lesson 4.3.3.
  3. For the following code, on your paper trace the value of variable repeat, including the initial value, and what is printed to the console if the user enters: y, y, n, y
    char repeat = 'y';
    while ('y' == repeat)
    {
        cout << "\nPlaying an exciting game!\n";
        cout << "Do you want to play again? (y/n) ";
        cin >> repeat;
    }
    
    repeat output

  4. After tracing, write the final number of repeats on your paper and circle the answer.
  5. Review your work with another student in the class and correct any problems.

Test Yourself (Optional)

  1. The first (initial) value of repeat is ___.
  2. The last value of repeat is ___.
  3. The message, "Playing an exciting game!", is displayed this many times: ___.

^ top

<< Back