1 |
h12 |
CS16 F16 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | section 9am or 10:30am |
||
Optional: name you wish to be called if different from name above. | ||||
Optional: name of "homework buddy" (leaving this blank signifies "I worked alone" |
h12: Homework 12
ready? | assigned | due | points |
---|---|---|---|
true | Thu 11/03 02:00PM | Tue 11/08 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 7.1 and 7.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!
FOR BEST RESULTS, PRINT THIS PAGE AS A PDF, THEN PRINT THE PDF
1.(5 pts) What is the output of the following code? If there’s an error that will not allow an output, point it out.
int arr[5];
for (int i = 0; i <= 10; i++) {
if (i < 3) arr[i] = 'a';
else arr[i] = 'z';
cout << arr[i] << endl; }
2.(5 pts) What is the output of the following code? If there’s an error that will not allow an output, point it out.
int arr[7] = {5};
for (int i = 0; i < 7; i++)
cout << arr[i] + i << endl;
3.(5 pts) What is the output of the following code? If there’s an error that will not allow an output, point it out.
int codes[] = {44, 66, 83, 973, -977};
for (int count : codes) {
if ( (count/2) < 50 )
cout << count << endl;
else cout << "invalid" << endl; }
4.(10 pts) Using the same formula from Lab 6, write a program that finds the standard deviation of the contents of this array of doubles:
nums[7] = {1.0, 3.2, 4.0, 4.0, 5.5, 9.0, 9.1}.
Give your answer in fixed point notation with 4 places after the decimal point showing. Print out your program and hand it in with this homework.
5.(15 pts) Write a program that takes 10 integer inputs from the user via keyboard and puts them in one array called myNums[]
, then prints them back out one at a time in this format: Number 1: 55
, and finally, computes the sum of these numbers and displays that in this format: Total sum: 922
.
Condition: The printing of the numbers and the calculation/printing of the sum MUST BE done with 2 functions, respectively, in which you pass the entire myNums
array. Print out your program and hand it in with this homework.