1
h08
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")

h08: Homework 8: Designing & Debugging Loops

ready? assigned due points
true Tue 05/02 12:30PM Thu 05/04 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.(4 pts) What is a flag in a program and of what use is it?
    2.(4 pts) What is variable tracing and how can it be of value to a programmer?
    3.(4 pts) If you have to use a conditional branch in your program, when would you choose to use a switch statement?
    4.(4 pts) Consider the statement: "Every time the code of a loop in a program is changed, it should be retested". Is this good advice? Why or why not?
    5.(4 pts) In regards to using tabbed/indented code: why bother with it in C++ if most compilers do not care about it? (or is this actually a *trick question*?)
    6.(20 pts) The following code is intended to calculate the sum of the six consecutive odd numbers, starting from the number 1. However, it fails at doing so. You have to fix it so that it does what it is intended to do. Start by copying this code into a full C++ program and debug via variable tracing. Submit the fixed code WITH your variable tracing.
    int sum(1), count(1); 
    while (count <= 6) { 
    	sum += (2*count + 1); 
    	count++; 
    } 
    cout << "sum = " << sum << endl;