Test 2 CSCI 130 Fall 2021

  1. Integers
    1. [3 points] List three DIFFERENT integer types.
    2. [1 points] Describe how these three types differ.
    3. [2 points] How does a programmer decide what integer type to employ?
    4. [2 points] unsigned is a type modifier. Describe what this modifier does.
    5. [2 points] Why would a programmer decide to use the unsigned modifier?
  2. Floating Point Types
    1. [3 points] Name the three different floating point types discussed in class.
    2. [4 points] Name two distinct types of numbers that can be represented as floating point types.
    3. [2 points] By default all literal floating point constants are of what type?
    4. [1 point] what does the f in the following line of code accomplish?
      x = 3.2f; 
  3. Type conversion
    1. [3 points] What is type coercion and what entity performs this?
    2. [3 points] What is type casting and what entity performs this?
    3. [2 points] What happens when a floating point type is converted to an integer type.
    4. [4 points] On line 4 of the following code, the compiler will convert from one type to another.
      1. To what type will values in the expression be converted?
      2. How will the compiler select the final type?
      float x;
      int y;
      cout << "The sum is " << x + y << endl; 
    5. [4 points] The programmer wishes the output from the previous example to be an integer, properly rounded. Provide the replacement code for line 4 to accomplish this.
  4. Functions
      int pow(float base, float exponent); 
    1. [2 points] What are the parameters to this function?
    2. [2 points] What is the return type of this function?
  5. Programming
    1. [10 points] Write a program that asks the user for a number of pennies and dimes. You program should
      • Print the total value in pennies.
      • Print the minimum number of pennies and dimes needed to represent that value. (IE the number of pennies should be less than 10.)