1 |
h03 |
CS16 W19 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | section |
||
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: Chapter 3: Boolean expressions, multiway branches, more loops
ready? | assigned | due | points |
---|---|---|---|
true | Thu 01/24 09:00AM | Mon 01/28 11:00PM |
Submit your homework as a pdf file through Gradescope before the due date listed above.
There is NO MAKEUP for missed assignments;
in place of that, we drop the lowest scores (if you have zeros, those are the lowest scores.)
For best results, save this page as a pdf, then print the pdf. Please write all your answers in the provided space. Homework submitted in a format different from the provided template will receive 0 points.
Please mark your homework clearly, regardless of if you write it out digitally, or in ink or pencil!
Please turn in the PDF copy of your homework on Gradescope. There are several posts on Piazza with helpful links for how to “write” on the PDF.
Read Ch 3.1 - 3.3, pages 112-118, 120-154.
-
1. (12 pts) Precedence rules determine how the compiler groups operators and operands when evaluating an expression in the absence of paranthesis. For each of the following expressions add parentheses to show how the expression is evaluated according to the C++ precedence rules. See the first line for an example.
x + 2 || !y - 3 -> (x + 2) || ((-y) - 3)
a) x == 2 || y > 20
b) !y && x < 9 * 2 || y < x
c) x + 7 > 10 || x + 23 < -7
int x = 17;
while ( x > 0) {
cout << x << endl;
x = x – 5;
}
int x = 0;
while ( x = 2 && x <10) {
cout << x << endl;
x+=2;
}
a) ____ (x == 6)
b) ____ !(y > 0)
c) ____ ((x == 2) || (y > 20))
d) ____ ((x >= 3) && (z <= 12))
e) ____ ((x > y) && (y < z))
f) ____ ((!(x < z) || (y > z)) && (z == 12) && (y == 10))
90 <= score <=100, grade = 'A'| 80 <= score < 90 , grade = 'B'| 70 <= score < 80 , grade = 'C'|
60 <= score < 70 , grade = 'D' | 0 <= score < 60 , grade = 'F'
…..a) Make your program easy to read and understand. Format your answers so that they are readable on the display. This means consider your use of “\n” characters.
…..b) Test this program out by compiling it and running it the same way you do with lab assignments. Write the code for a functionally correct program below.
int p = 5;
while (--p > 0)
cout << p << " ";
int s = 1;
do
cout << s << " ";
while (s++ <= 5);