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. [10pts] For each of C++ statements below, give an equivalent C statement (or statements).
    C++C
    
    double* A = new double[10];
    
    
    
    
    
    
    
    
    delete [] A;
    
    
    
    
    
    
    
    
    string s; 
    s = "hello";
    
    
    
    
    
    
    
    
    char c;
    int n;
    double x;
    cin >> c >> n >> x;
    
    
    
    
    
    
    
    
    string s;
    cin >> s;
    
    
    
    
    
    
    
  3. [80pts] Write a program hw.c that works as follows:
    ~/$ ./hw
    N = 5
    10 5 20 15 25
    cmd: show
    [0] **********
    [1] *****
    [2] ********************
    [3] ***************
    [4] *************************
    cmd: swap 0 1
    cmd: show
    [0] *****
    [1] **********
    [2] ********************
    [3] ***************
    [4] *************************
    cmd: swap 2 3
    cmd: show
    [0] *****
    [1] **********
    [2] ***************
    [3] ********************
    [4] *************************
    cmd: quit
    
    The program processes the following commands:
    • show: The program shows the data as in the sample run.
    • swap i j: The program swaps the positions of the ith number and jth number.
    • quit: The program ends.

Turn in