Name: ____________________________________________________ Alpha: ________________________

Describe help received: _____________________________________________________________________

See the bottom on 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 "Ceaser Shift Encryption" -- 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 the below, circle expression, statement or neither appropriately.
    expression / statement / neither
    double x;
    expression / statement / neither
    3 / x
    expression / statement / neither
    y = x*5
    expression / statement / neither
    4 + x /
    expression / statement / neither
    x = 4;
  3. [18pts] Assume the following declarations fill in the table.
    double a;
    int b;
    char c;
    a = 16.4;
    b = 3;
    c = 4*a + b;
    
    expressiontypevalue
    a + b
    'a'+ b
    'b'-'a'
    a / 4
    b / 4
    b % 4
    c
    int(c)
    b = a
  4. [2pts] What is the output of the following code?
    
    cout << (2.5*4)/5 << endl << 2.5*(4/5) << endl; 
    
  5. [60pts] Write a program hw.cpp that reads in two lengths in the format x' y'' (i.e. x feet y inches) and returns the difference in length between the two in the same format. You may assume that the first length is always larger than the second! Note that to represent the unit of inches, we use two single-quotation marks instead of one double-quotation mark.

    A typical run of your program should look like this (user input shown in red):

    Enter two lengths in feet and inches (larger first!)
    32' 6''
    15' 11''
    Difference is 16' 7''
    • Hint 1: First work on getting your program simply read the four measurement values, then work on getting it to print out the difference in inches, then work on getting the difference in feet and inches.
    • Hint 2: The string constant "'" works just fine, but to get the character constant of the apostrophe you must write '\'', which uses the backslash as an escape character.
    • Hint 3: For ideas on how to chop a length in inches into feet and inches, look at the Minutes and Seconds program, which has to deal with the similar problem of chopping a time in seconds up into minutes and seconds.
Warning!

Points will be deducted if you ignore the programming style guide and tips.

  • Your code should have good indentations and line breaks.
  • Give appropriate comments to your code.
  • Your variable names should be chosen well.

Turn in