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

h03: Homework 3

ready? assigned due points
true Thu 09/29 02:00PM Tue 10/04 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 (If you don’t have a copy of the textbook yet, there is one on reserve at the library under “COMP000-STAFF - Permanent Reserve”).

    1. (2 pts) Show 2 different ways to initialize variables in C++?
    2. (2 pts) Is this variable declaration statement in C++ a good one? Why or why not?

    double union=30;

    3. (2 pts) How do you write in ONE LINE in C++: Add a to b and subtract that sum from c, then divide that result by d?
    4. (2 pts) What will appear on the monitor/display when the following C++ statement is executed?

    cout << "My dog likes to eat\t" << 5 << " cans of dog food a day" << " !" << endl;

    5. (12 pts) Write a short program that asks the user to input three double type inputs from the keyboard, the program then shows the user what the 3 numbers entered were. It then multiplies them together, and displays the answer within 4 decimal places.
    6. (4 pts) Mark up this program to show what four things are missing from this program.

    #include <iostream>

    int main()

    int a(0),b(0),c(0);

    string quote;

    cout << "Enter 3 numbers separated by spaces: ";

    cin >> a,b,c;

    sum = a + b + c;

    quote = "The sum of these 3 numbers is: ";

    cout << quote << sum;

    return 0; }

    7. (4 pts) What is the resulting output display from the following C++ statements? AND EXPLAIN WHY.

    int x(35), y(5);

    bool v, w;

    v = (x >= y);

    w = ((x/y) == 7);

    cout << v << w << endl;

    8. (12 pts) Write a C++ program that takes as input from the user, their favorite integer number and their name. The program then, says "Hello, (user's name here), your favorite number is (user's favorit number here)!". Then the program will will multiply the number they gave you by 5, then multiply that result again by 5, then multiply THAT result AGAIN by 5. The program HAS to do so using one of the C++ shorthands we discussed in class.
    Finally, the program should say "I took your number and multiplied it by 5 THREE times and the result was: (the resulting number here)."
    IMPORTANT NOTE: You CANNOT write this program using ANY loop statements!