1 |
h02 |
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" |
h02: Chapter 2: Variables and assignments, Input/output, Data types and expressions, Simple flow control
ready? | assigned | due | points |
---|---|---|---|
true | Thu 01/17 06:00PM | Tue 01/22 09:00AM |
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!
Complete your reading of Chapter 1, section 1.3 pages 27-32, Chapter 2 sections 2.1 thru 2.2, pages 39-59 .
Please turn in the PDF copy of your homework on Gradescope. Make sure your PDF does not contain any blank pages (remove them, if they are there, before submitting it).
-
1. (1 pt) If the following statement were in a C++ program, what would it do?
cout >> "I love oranges and apples";
2. (1 pt) If the following statement were in a C++ program, what would it do?
cout << "The world goes round and round"
3. (4 pts) Show 2 different ways to declare and initialize variables in C++? You may use multiple statements.
4. (2 pts) Is this variable declaration statement in C++ a good one? Why or why not?
double float=30;
#include <iostream>
int main(){
int a , sumPositive, sumNegative;
string promptContinue ="\nTo continue enter Y/y\n";
string promptNum = "\nEnter a number: ";
char response;
while (response = 'y'||`Y') {
cout << promptNum;
cin >> a;
if(a)
sumPositive+=a;
else
sumNegative+=a;
cout<< promptContinue;
}
cout<< "Sum of all the positive numbers is: "<< sumPositive<<endl;
cout<< "Sum of all the negative numbers is: "<< sumNegative<<endl;
return 0;
}
int x=20, y=5;
bool v, w;
v = (x != y);
w = ((x/=y) == 4);
cout << x << " " <<y << " "<< v << " "<< w << endl;