CS 231 Lab 4: Introducing nested loops

Singing songs with accumulating verses

In this lab we will practice using arrays and loops. You should write a program which "sings a song", like the Old McDonald's Farm example from lecture. More specifically, your song should be one of those where the verses accumulate during the course of the song; for example, a typical verse structure might be:

A;		(pig says oink-oink)

B;		(cow says moo-moo)
A;		(pig says oink-oink)

C;		(horse says neigh-neigh)
B;		(cow says moo-moo)
A;		(pig says oink-oink)
(This sort of verse structure will naturally lead to a nested loop structure in the program, as demonstrated in lecture.)

You may choose any such song except for the lecture example: other popular songs of this form include The Twelve Days of Christmas (a bit early for this one, though), The Green Grows All Around, Chad Godya, There's a Hole in the Middle of the Sea, etc.

(You can find a list of lyrics for these and other children's songs, not all of which have this form, at this link. (Thanks to David H. for the pointer!) Unfortunately, on the page just cited, the song "Old MacDonald Had a Farm" is not given its proper repetition structure: see this page on a Kid's Song website for the intended structure of "Old MacDonald".

Your program should use arrays to hold (at least) the verse-relevant strings; if you can find a rationale for an intermediate object (farm animals, Christmas gifts, tree parts, etc.) that would be even better. You should also try to use a separate "singer" class (like "Main" from lecture) to do the overall job of printing at the outter level.

A picture of the program structure from lecture