Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [10 pts] We would like you to self-test how much you retained from the lecture. Write the correct solution to the Mandatory Practice Problems. Debug your code until it runs correctly. Circle below how you wrote your code.
    1. (10 pts) I was able to write the code without referring to anything.
    2. (10 pts) I had to look at the notes, but still I was able to write the code without looking at the solution.
    3. (10 pts) I had to look at solutions to finish to code.
    4. (0 pts) I didn't do this.
    If you had to look at the solution, briefly describe what you missed but understand now.
    
    
    
    
  2. [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!

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

    expressiontype (or error!)value (or error!)
    XN/A
    AN/A
    X[0]
    A[1] - x
    A[0] = X[n]
    ++A[2]
    B[1]
    A[1] + X[1]
    sqr(A[0])
    sqr(X[0])
    isneg(X[0])
  1. [70pts] Write a program hw.cpp that reads a number n from the user, reads an n-word sentence from the user, and then prints out the sentence forwards, followed by a question mark, then reversed, followed by an exclamation mark (but do not reverse the letters within the words). A typical run of the program might look like this:

    $ ./hw
    Number of words: 3
    Sentence: am I Sam
    am I Sam? Sam I am!
    $ ./hw
    Number of words: 4
    Sentence: places you drive cars
    places you drive cars? cars drive you places!
    

    Use arrays!

    Turn in