1
h04
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"

h04: Homework 4

ready? assigned due points
true Tue 10/04 02:00PM Thu 10/06 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 2 and Ch 3.1 (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. (1 pts) Which Boolean operator, when used with 2 logic expressions, yields TRUE only if both expressions are TRUE?
    2. (1 pts) What is wrong with this C++ expression?
    if (size = 4)
       cout << "The size is too small";
    
    3. (2 pts) Write an if-else statement that outputs the word HI if the value of the variable score is greater than 100 and LO if the value of score is at most 100? Variable score is of type int.
    4. (2 pts) Show the output of this code if x is of type int.
    x = 10;
    while ( x > 0) {
       cout << x << endl;
       x = x – 3;
     }
    
    5. (2 pts) Write a while loop that prints out these 11 lines:
    COUNTDOWN TO ZERO: 10
    COUNTDOWN TO ZERO: 9
    ...
    COUNTDOWN TO ZERO: 1
    COUNTDOWN TO ZERO: LIFT OFF!
    
    6. (12 pts) What is the result (i.e. TRUE or FALSE) of the following Boolean operations in C++, given that: x = 7, y = 10, z = 12
    a) (x == 6)
    
    
    
    b) !(y > 0)
    
    
    
    c) ((x == 6) || (y < 20))
    
    
    
    d) ((x >= 3) && (z <= 12))
    
    
    
    e) ((x > y) && (y < z))
    
    
    
    f) ((!(x < z) || (y > z)) && (z == 12) && (y == 10))
    
    
    
    .	
    
    7. (20 pts) Write a program that 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.
    Plan this out well: what are the variables that you'll need? What type will each be? You MUST:
    .....a) Make your program easy to read and understand. This includes the use of comments in the program to tell us what you're doing.
    .....b) Declare at least one constant in the program.
    .....c) Format your answers so that they are readable on the display. This means consider your use of "\n" characters and the proper formatting of decimal places in the displayed numbers to the user.
    .....d) Test this program out by compiling it and running it the same way you do this with lab assignments.
    When you are sure that you have a working program, attach a print out of it to this homework sheet. You will be graded for programming style as well as having a functionally correct program.
    PLEASE REMEMBER TO PUT YOUR FULL NAME AND ID# ON THIS SHEET!