1 |
h03 |
CS16 Su17 |
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 2: Data types and expressions, Simple flow control
ready? | assigned | due | points |
---|---|---|---|
true | Tue 07/04 02:00PM | Tue 07/11 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.
Read Chapter 2, sections 2.3 - 2.5 (If you don’t have a copy of the textbook yet, there is one on reserve at the library under “COMP000-STAFF - Permanent Reserve”).
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. (4 pts) Explain via an example what a "type mismatch" is. Also explain how compilers handle C++ statements that have a type mismatch?
2. (4 pts) What does the keyword 'auto' do for the programmer in the C++11 declaration:
auto x = 2.73;
#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;