Assignment 11
Due Thursday, November 3 at 3:20pm on Catalyst


Assignment 11.1: Humpty Dumpty (10 pts)
  • Open up CodeBlocks and create a new C++ file called humpty.cpp.
  • Write a program that uses a while loop to print the numbers from 1 to 150, with each number printed on its own line.
  • For multiples of five print "Humpty" instead of the number
  • For the multiples of seven print "Dumpty" instead of the number.
  • For numbers which are multiples of both five and seven print "Had a Great Fall".
  • You must use a while loop for full credit.
  • Hint: Test for numbers that are multiples of both 7 and 5 first.
  • When you are finished, and your output looks like mine, upload your assignment to Catalyst.
Your Output Should Look Like the Following. Note that some values have been omitted for brevity.

1
2
3
4
Humpty
6
Dumpty
8
9
Humpty
11
12
13
Dumpty
Humpty
...
34
Had a Great Fall
36
...
149
Humpty


Assignment 11.2: 99 Bottles of Beer (10 pts)

  • The goal of your program is to print out the lyrics to the song "99 Bottles of Beer on the Wall."
  • Your program will take as user input the number of bottles.
  • Then, you will use a while loop to print out the lyrics to the song. (See sample output below)
  • Start your program by declaring a variable for the number of bottles of beer, welcoming the user, and prompting the user for input about the number of bottles. At this point, when you run your program, it should look identical to the sample output below (except user input will vary). 
  • Make sure that you have a blank line under the prompt and before the lyrics to the song start. (See sample output below)

 

  • Important: How did I get the double quotes around the name of the song?
  • Next, create a while loop to print out the lyrics of the song.
  • What goes into the condition of the while loop? (Hint: Think counting down to 0 bottles of beer)
  • You should have four cout statements in the body of your while loop at this moment.
  • Your lyrics should be printed out as blocks of four sentences, each sentence on a separate line, with a blank line separating each block. In other words, they should look like this:


  • How am I getting the number of bottles to go down by one each time I print a new block of lyrics?
  • Once you have this portion of the loop working, you need to handle the special cases of:
    • 1 bottle of beer
    • 0 bottles of beer
  • Note that at the end of the song, the lyrics change as follows:
  • When you print "1 bottle of beer on the wall!", you need the singular version of bottle.
    • "1 bottle of beer on the wall!"
    • You don't want to say "1 bottles"
  • Also, when you get down to 0 bottles, you need to end the song by printing out "No more bottles of beer on the wall."
  • In other words, your output at the end of the song should look identical to this:

  • To print the correct lyrics for your song, you will need to use if statements. 
  • Note that there are alternate ways to write your program so that it prints out the correct lyrics.
  • You don't necessarily have to put all your if statements inside the while loop. It is up to you how you approach this problem.
  • Note that some of the lyrics will be cut off by the console window if you input too high of a number for the number of bottles of beer. However, that does not mean that there is anything wrong with your program. The problem comes from the limits of the console window.
  • When your output is identical to my sample output (including spelling, punctuation and capitalization), submit your source code to Catalyst.
The output of your program should look identical to the output below (except user input will vary):