1
h05
CS16 F16
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu section
9am or 10:30am
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"

h05: Homework 5

ready? assigned due points
true Thu 10/06 02:00PM Tue 10/11 02:00PM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

MAY ONLY BE TURNED IN IN THE LECTURE/LAB LISTED ABOVE AS THE DUE DATE,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the three lowest scores (if you have zeros, those are the three lowest scores.)


Please:

  • No Staples.
  • No Paperclips.
  • No folded down corners.

Read Chapter 3.1 - 3.3 (If you do not have a copy of the textbook yet, there is one on reserve at the library under “COMP000-STAFF - Permanent Reserve”).

PLEASE MARK YOUR HOMEWORK CLEARLY, REGARDLESS OF IF YOU WRITE IT OUT IN INK OR PENCIL!

    1. (2 pts) What is a runtime error in C++?
    2. (6 pts) Use precedence rules to re-write the following expressions:
    x / 4 - 3 == 1 && 6 * x + y > 0
    a / b * b < 0.5 || --flag >= 0
    z * m + n / v >= 5 && b + c - d != 0 || f < g
    3. (4 pts) What is the output of the following statements?
    int p = 5;
    while (--p > 0)
         cout << p << " ";
    
    4. (4 pts) What is the output of the following statements?
    int s = 1;
    do
         cout << s << " ";
    while (s++ <= 5);
    
    5. (4 pts) Same question as above, but the last statement now reads:
    while (++s <= 5);
    
    6. (10 pts) Write a block of statements (like a function, but you don't have to write it like a function) that take three arguments of type int and returns true if the arguments are in ascending order; otherwise, it returns false. You can use any type of C++ statement types that we've gone over in class so far to accomplish this goal.
    7. (10 pts) Using a switch statement, re-write the program from the previous homework 4, question 7. As a reminder, your program first asks for the user's name, then asks the user to pick a shape to find the area to: a rectangle, a triangle, a trapezoid, or a circle. Based on the user's choice, the program then gets the pertinent parameters from user input, then it calculates the area of the shape, and finally, it reports the answer back to the user.
    Employ the same methods with this exercise as you did the homework 4, question 7 one: plan it, write it, compile and test it, and then finally, print this out separately and hand it in with this homework (just like what you did for homework 4).
    AGAIN, PLEASE REMEMBER TO PUT YOUR FULL NAME AND ID# ON THIS SHEET!