Test 2 CSCI 130 Fall 2015


  1. Integers
    1. [3 points] Name three different integer types. What is the relationship between these types?
    2. [1 point] Under normal circumstances which integer type should be used?
    3. [2 points] What does the unsigned reserved word do when used with an integer type? Why would this be used?
    4. [1 point] What does the modulus operator do?
    5. [2 points] Describe integer division. Give a code example where integer division produces unexpected results.
    6. [3 points] Describe the operation of the postfix increment operator. Give a small code example using the postfix increment operator and explain what your example does.
  2. Input/Output
    1. [2 points] Describe how the stream extraction operator works with a floating point variable as the destination.
    2. [2 points] Give an example of input for which using the stream extraction operator with a floating point variable as the destination will fail. Explain why this input will cause a failure.
    3. [2 points] What happens when a stream failure occurs?
  3. Floating Point
  4. Coercion and Type Casting
    1. [2 points] Define coercion and type casting.
    2. [3 points] Why should a program perform type casting over coercion?
    3. [3 points] Give a small code segment, including variable declarations, which illustrates how to perform type casting.
  5. I/O Manipulators
    1. [2 points] Describe the syntax of the setw operator.
    2. [2 points] Describe the semantics of the setw operator.
    3. [2 points] Give a short example using the setw operator, expalin what your example does.
    4. [1 point] Why would a programmer use the setw operator?
  6. Flow of control
    1. [2 points] What is the flow of control in a program?
    2. [2 points] What is a control structure?
  7. Boolean Datatype
    1. [4 points] Describe the boolean datatype.
    2. [2 points] Discuss the difference between the = operator (1 = sign) and the == operator (2 = signs).
  8. [5 points] Program: Write a complete program which reads in the temperature in Fahrenheit and prints the result in Celsius. C = 5/9(F-32)