Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [20pts] Assume the following delcarations and function definitions fill in the table. Note: "error" is a possiblity! Note: each question is independent, i.e. no side effects of one expression shoudl be taken to carry over to the next.
    Tip: If necessary, write a code and test it!

    
    double x = 2.25;
    int n = 2;
    string s = "hard";
    int *A = new int[3]
    A[0] = 6; A[1] = 9; A[2] = 8;
    string *B = new string[2];
    B[0] = "hi"; B[1] = "bye";
    double *X = new double[3];
    X[0] = 5.1; X[1] = 5.4; X[2] = 5.7;
    
    double sqr(double z) { return z*z; }  
    
    int absme(int k) {
      if( k < 0 )
        return -1 * k;
      return k;
    }
    

    expressiontype (or error!)value (or error!)
    X[0]
    A[1] - x
    A[0] = X[n]
    ++A[2]
    B[1][0]
    A[1] + X[1]
    sqr(A[0])
    sqr(X[0])
    absme(A[0])
    absme(A[3])
  2. [80Pts] Write a program that reads a number n from the user, reads an n-word sentence from the user, and then prints out the sentence in reverse (but not the words). A typical run of the program might look like this:
    ~/$ ./prog
    Number of words: 3
    Sentence: Sam I am
    am I Sam
    
    ~/$ ./prog
    Number of words: 11
    Sentence: Write a program that reads a number n from the user
    user the from n number a reads that program a Write
    

    Use arrays not recursion! Turn In this cover sheet and a printout of your program along with a screen capture with the above runs.