Test 3 CSCI 130 Fall 2013


  1. Boolean Type
    1. [2 points] Describe the boolean type.
    2. [3 points] Describe the operations unique to the boolean type.
  2. If statements
    1. [1 point] Give the syntax for the if statement. Not if else.
    2. [2 points] Give the flow of control for the if statement. State this in English, not as a diagram.
    3. [2 points] Give an example of an if statement.
  3. While statements
    1. [1 point] Give the syntax for the while statement.
    2. [2 points] Give the flow of control for a while statement.
    3. [2 points] Give the preferred use for the while statement.
  4. Loops
    1. [3 points] State the three general rules fro constructing a successful loop.
    2. [3 points] Give an example loop, label each of the three points mentioned above in your example. (as comments)
    3. [2 points] Give the syntax for the C/C++ for control structure.
    4. [2 points] How does the C/C++ for syntax assist programmers when creating a loop?
  5. Strings
    1. [2 points] Describe the syntax of the string length member function.
    2. [2 points] Describe the operation of the string find member function.
    3. [2 point] What is string::npos?
    4. [2 point] How does a programmer access an individual character within a string?
  6. [7 points] Write a code segment which will print the string stored in the string variable phrase out in revers order. If phrase = "hello world!", your should print !dlrow olleh.
  7. [10 points] Write a program which empirically proves Gauss's method for summing the first n integers. Gauss discovered that 1 + 2 + 3 + ... + n = n(n+1)/2. Your program should compute this sum, both by adding and by using the formula for the n between 1 and 20. You should provide a statement which checks the results and prints Good if they are both the same and Wrong if they are not. Your output should be of the form
    N       Sum      Formula     Check
    ----------------------------------
    1        1          1         Good
    2        3          3         Good
    ....
    20       210        210       Good