Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [20pts] Assuming the following function prototypes and variable definitions, fill in the table. Note: each expression should be taken as independent. I.e. if one expression modifies some variable values, those modifications do not carry over to the next expression.
    // Function prototypes - each of these functions does what the name says it does
    int abs(int j); // returns "absolute value" of j.  defined in library cstdlib
    double round(double x); // returns x rounded to nearest integer. defined in library cmath
    string to_string(int val); // returns string representing val. defined in library string
                               // Note: only there in a newer version of C++ than we're using.
    // Variable definitions
    int k = 2;
    double x = 2.75;
    string s = "hello";
    
    expressiontypevalue
    k + abs(-2)
    x + abs(-2)
    round(x) + k
    k = round(x)
    s + to_string(k + 3)
    to_string(int(round(x)))
    (5 + 8)/round(x - 1)
    k++ < x
    ++k < x
    k++ < x && k > x
  2. [10pts] The prototype for the "get()" function for istream objects, as in cin.get(), or fin.get() when fin is an ifstream, looks like this (this is a bit of a funny function because of the "cin." in front of the name):
    int get();
    Given this, and what we know about cin.get() and fin.get() work from the previous class, what gets printed out for
    cout << cin.get() << endl;
    as opposed to
    char c = cin.get();
    cout << c << endl;
    when the user inputs Q? Explain why each gives the answer it does.
  3. [70pts] This program is missing the definition of the function firstfactor. Complete the program by defining the function (a description of what the function is supposed to do is given in the source code's comments). When your program is working correctly, a typical run might look like this:
    Enter an integer larger than 1: 60
    The factorization of 60 is (2)(2)(3)(5)
Turn in a printout of this cover sheet with your answers to the questions, your source code, and a screen capture of your program running the input 21978.
Challange modify the program so that it prints multiple factors with an exponent, rather than repeated, so that the factorization of 40 would be given as (2)^3(5) rather than (2)(2)(2)(5).