1 |
h05 |
CS16 S17 |
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" |
h05: Chapter 3: Loops
ready? | assigned | due | points |
---|---|---|---|
true | Mon 04/17 02:00PM | Mon 04/24 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.
Complete the reading of Chapter 3 and additionally read Chapter 4 section 4.1-4.2 (If you do not have a copy of the textbook yet, there is one on reserve at the library under “COMP000-STAFF - Permanent Reserve”).
PLEASE MARK YOUR HOMEWORK CLEARLY, REGARDLESS OF IF YOU WRITE IT OUT IN INK OR PENCIL!
-
1. (2 pts) What is a runtime error in C++?
2. (6 pts) Use precedence rules to re-write the following expressions:
(i) x / 4 - 3 == 1 && 6 * x + y > 0
(ii) a / b * b < 0.5 || --flag >= 0
(iii) z * m + n / v >= 5 && b + c - d != 0 || f < g
3. (4 pts) What is the output of the following statements?
int p = 5;
while (--p > 0)
cout << p << " ";
int s = 1;
do
cout << s << " ";
while (s++ <= 5);
while (++s <= 5);
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double s(0.0);
int k(0);
cout << "Enter k: ";
cin >> k;
for (____________________________________________________) {
s = ____________________________________________________; }
cout << "Series converges to: " << s << endl;
return 0;
}