1
h12
CS16 S17
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu
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: Arrays

ready? assigned due points
true Tue 05/23 12:30PM Thu 05/25 12:30PM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

MAY ONLY BE TURNED IN IN THE LECTURE LISTED ABOVE AS THE DUE DATE. There is NO MAKEUP for missed assignments.
In place of that, we drop the two lowest scores (if you have zeros, those are the two lowest scores.)


PLEASE MARK YOUR HOMEWORK CLEARLY, REGARDLESS OF IF YOU WRITE IT OUT IN INK OR PENCIL!

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}. In other words, instead of reading the numbers from a file, read the numbers from the array.

Give your answer in fixed point notation with 4 places after the decimal point showing. Print out your program and staple it to 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 staple it to this homework.