1 |
h03 |
CS16 F17 |
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") |
h03: Advanced Flow Control and Functions
ready? | assigned | due | points |
---|---|---|---|
true | Thu 10/12 02:00PM | Thu 10/19 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 LISTED ABOVE AS THE DUE DATE. There is NO MAKEUP for missed assignments.
PLEASE MARK YOUR HOMEWORK CLEARLY, REGARDLESS OF IF YOU WRITE IT OUT IN INK OR PENCIL!
-
1. (3 pts) What is a run-time error?
2. (3 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" customers. 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(14);
while (x >= 3) {
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;
1 #include <iostream>
2 using namespace std;
3
4 bool isDivisibleBy(int a, int b);
5
6 int main() {
7 cout << "result for (15,5) is " << isDivisibleBy(5,15) << endl;
8 cout << "result for (15,5) is " << isDivisibleBy(5,15) << endl;
9 return 0;
10 }
11
12 bool isDivisibleBy(int a, int b) {
13 return ( a % b == 0 );
14 }
int a(1), b(2), c(2), d(2), e(2);
double f;
f = (a + b)*c / static_cast<double>(d + e); // (ex1)
f = static_cast<double>(a + b)*c / (d + e); // (ex2)
f = (a + b)*static_cast<double>(c) / (d + e); // (ex3)
f = static_cast<double>((a + b)*(c) / (d + e)); // (ex4)
#include <iostream>
using namespace std;
void times(int y, int &z) {
y = y * 9;
z = z + 9;
cout << "y=" << y << ", z=" << z << endl;
}
int main() {
int b = 7, d = 3;
times(b, d);
cout << "b=" << b << ", d=" << d << endl;
return 0;
}
int main(int argc, char *argv[])
~jimbo/cs16/myprog 12 dozen eggs
Answer the following questions carefully, using the proper quotation marks (where applicable).
What is the value of argc?
What is the value of argv[2][2]?
What is the value of argv[1] and what data type is it?
What is the value of argv[0]?
What is the value of argv[1]/4?