1 |
h03 |
CS16 F19 |
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 10/10 09:00AM | Thu 10/17 12:30PM |
You may collaborate on this homework with AT MOST one person, an optional "homework buddy".
UPLOAD A PDF OF YOUR ANSWERS TO GRADESCOPE BEFORE THE DUE DATE. ASSOCIATE EACH QUESTION WITH A SPECIFIC PAGE IN YOUR HOMEWORK AT THE TIME OF SUBMISSION. There is NO MAKEUP for missed assignments;
Please:
- No Staples.
- No Paperclips.
- No folded down corners.
Read Ch 3.1 -3.3, pages 112-118,120 -154. Please turn in your homework in lecture.
PLEASE WRITE ALL YOUR ANSWERS IN THIS SHEET. HOMEWORKS 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 IN INK OR PENCIL!
-
1. (6 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 paranthesis to show how the expression is evaluated according to the C++ precedence rules?
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))
int s = 1;
do
cout << s << " ";
while (s++ <= 5);
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. When you are sure that you have a working program, write it out in the space provided below. You will be graded for programming style as well as having a functionally correct program.