{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Homework 2 Spec

Homework 2 Spec - original but the changed program uses a...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Spring 2009 CS 31 Homework 2 Time due: 9:00 PM Thursday, April 16 Prepare your solutions to these homework assignments as a single Word document named hw.doc or hw.docx , or a plain text file named hw.txt . Turn in this file as described in the Project 2 specification . What is the output produced by the following program segment: string grendel = "endl"; cout << "endl"; cout << grendel; cout << endl; cout << "grendel"; Consider the following program: #include <iostream> using namespace std; int main() { int len; cout << "Enter a number: "; cin >> len; for (int i = 0; i < len; i++) { for (int j = i+1; j < len; j++) { cout << ' '; } cout << "#" << endl; } } In a brief, simple English sentence, state what this program does (e.g. "It prints a picture of an aqueduct."). Copy the program in problem 2 and change it so that for any input number, the changed program behaves the same way as the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: original, but the changed program uses a while loop instead of a for loop for the inner loop. Copy the program you wrote for problem 3 and update it so that for any input number, it behaves the same way, but uses a do-while loop instead of a for loop for the outer loop. Be careful! (Hint: How does it behave if len is not positive? You may need to add a little additional code to make sure the program behaves identically to the program in problem 3.) Assume month has been previously declared as an int and given a meaningful value. Write a switch statement that for any value of month , produces exactly the same output as the following if statement. if (month == 6) cout << "summer solstice"; else if (month == 12) cout << "winter solstice"; else if (month == 3 || month == 9) cout << "equinox"; else cout << "nothing special";...
View Full Document

{[ snackBarMessage ]}