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 function 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
                               
    // Variable definitions
    int k = 3;
    double x = 3.8;
    string s = "The number of cookies I need: ";
    
    expressiontypevalue
    k + abs(-4)
    x + abs(-4)
    round(x) + k
    k = round(x)
    s + to_string(k + 5)
    to_string(int(round(x)))
    (3 + 10)/round(x - 1)
    k++ < x
    ++k < x
    k++ < x && k > x
  2. [80pts] Consider the following program hw.cpp (download it). The program reads an integer from the user and prints out its factorization into prime numbers. Unfortunately, I've been unable to figure out how to implement the function firstfactor:
    
    #include <iostream>
    using namespace std;
    
    //==========================================
    // Give the prototype of firstfactor below
    
    
    //==========================================
    // main function
    int main()
    {
      // Get integer n, n > 1, from user
      int n;
      cout << "Enter an integer larger than 1: ";
      cin >> n;
    
      // Print out factorization
      cout << "The factorization of " << n << " is ";
      while(n > 1)
      {
        // get & print next prime factor
        int f = firstfactor(n);
        cout << '(' << f << ')';
        n = n / f;
      }
      cout << endl;
    
      return 0;
    }
    
    
    //==========================================
    // Define firstfactor below
    
    
    As you see, the program is missing the prototype and 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)