1 |
h05 |
CS16 S17 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | |||
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: Advanced Flow Control
ready? | assigned | due | points |
---|---|---|---|
true | Tue 04/18 12:30PM | Thu 04/20 12:30PM |
You may collaborate on this homework with AT MOST one person, an optional "homework buddy".
MAY ONLY BE TURNED IN IN THE LECTURE LISTED ABOVE AS THE DUE DATE. There is NO MAKEUP for missed assignments.
In place of that, we drop the two lowest scores (if you have zeros, those are the two lowest scores.)
PLEASE MARK YOUR HOMEWORK CLEARLY, REGARDLESS OF IF YOU WRITE IT OUT IN INK OR PENCIL!
-
1. (1 pts) What is a run-time error?
2. (2 pts) You are writing a program that keeps track of a bank account for your customers.
The program must print out a statement on the computer display that warns the customer that their
balance is below $25, but only if they are a "premiere" customer. Which of these choices is correct?
Explain WHY?
A. if (balance < 25) { cout << "Your balance is under $25 - be careful!"; }
B. if !((balance > 25) || (type != "premiere")) { cout << "Your balance is under $25 - be careful!"; }
C. if ((balance < 25) && (type == "premiere")) { cout << "Your balance is under $25 - be careful!"; }
D. if (!(balance > 25) && (type == "premiere")) { cout << "Your balance is under $25 - be careful!"; }
#include <iostream>
using namespace std;
int main () {
int x(12);
while (x >= 1) {
cout << x << " ";
if (!(x % 3)) {
cout << "Buzz! ";
if ((x % 2) == 0) cout << "Fizz!";
}
else cout << "...";
cout << endl;
x--;
}
return 0;
}
#include <iostream>;
use namespace std;
int main ()
int a(0);b(0);
cout << "Enter a number that is either 0 or 1: ";
cin >> a;
cout << "Enter another number that is less than 5: ";
cin >> b;
switch (a) {
case 0:
cout << "number is zero.\n";
for (int i = 5; i != b; i++) {
cout << "extra line " << i << endl;
}
break;
case 1:
cout << "number is one.\n";
if (b > 5) {
cout << "Han shot first!\n";
}
break;
}
return;