Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

See the bottom for how to submit your work.

  1. [10 pts] We would like you to self-test how much you retained from the lecture. Write the correct solution to the Practice Problem of
     The second simplest calculator
    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] Consider the following code:
    
    char next;
    int count = 0, total = 0;
    cin >> next;
           _______________a_______________________
          /                                       \
    while ((next == '0' || next == '1') && count < 3)      
    {      \_________/
                b               c
                               / \
      total = total*2 + next - '0';
              \__________________/
                       d
    
      count = count + 1;
      cin >> next;
    
    }
    cout << total << endl;
    \___________/
          e
    
    
    For each expression denoted left, fill in the type of the expression.
    type
    a
    b
    c
    d
    e

  3. [80pts] You have a cookie jar that you fill with cookies, and then you eat some every day. Write a program in a file hw.cpp to figure out how many days it took you to eat all of your cookies.

    Specifically, your program will first read in the total number of cookies to fill up the jar, and then read in the number of cookies eaten day-by-day, starting with day 1. Once the cookies in the jar are gone, you will display the total number of cookies eaten, the total number of days it took, and the number eaten on the user's piggiest day (i.e. when the most were eaten). If the user tries to eat more cookies than were in the jar originally, you should instead display the message "Not enough cookies!", and exit.

    Assume that all the numbers typed in will be positive integers. Your program should always say "cookies" and "days" even if there is one cookie or one day; grammar rules go out the window come exam time! Finally, you must follow the input and output conventions below exactly.

    ~/$ ./hw
    How many cookies? 11
    Cookies eaten on day 1: 2
    Cookies eaten on day 2: 5
    Cookies eaten on day 3: 1
    Cookies eaten on day 4: 3
    You ate 11 cookies over 4 days.
    On your piggiest day you ate 5 cookies.  
    	    
    ~/$ ./hw
    How many cookies? 5
    Cookies eaten on day 1: 5
    You ate 5 cookies over 1 days.
    On your piggiest day you ate 5 cookies.  
    	    
    ~/$ ./hw
    How many cookies? 19
    Cookies eaten on day 1: 5
    Cookies eaten on day 2: 10  
    Cookies eaten on day 3: 5
    Not enough cookies!
    	    

Turn in