CSCI 201 Fall 1999

Assignment 1: Animals and Sounds

Program: Animal Sounds
(A modification of course material used in Spring 1998 at Duke University)

For this assignment, you will create a program iteratively, at each part adding more to the program. Be sure to save the source code that you create for each part of the assignment, you will be required to turn in each version of the program.

Part 1

Consider the following output (excerpts from a book by Martin and Carle) from the program called sounds:


   I hear a lion roaring in my ear.
   
   I hear a hippopotamus snorting in my ear.
   
   I hear a elephant trumpeting in my ear.

Write the program called sounds1.cpp to generate the output above. Make sure there is a blank line between each sentence. Your program should consist of one function called main. This function requires no parameters.

Part 2

Modify sounds1.cpp to be modular including at least one other function (besides the main function) with two parameters, one for an animal and one for a sound. Call the modified program sounds2.cpp. The program sounds2.cpp should produce the same output as sounds1.cpp.

Part 3

Modify sounds2.cpp to produce the following output, name the modified program sounds3.cpp. Your program should be modular and efficient. Note that the animal making noise on the second line of a verse should be the same as the first animal on the first line of the next verse.


   bear, bear, what do you hear?
   I hear a lion roaring in my ear.

   lion, lion, what do you hear?
   I hear a hippopotamus snorting in my ear.

   hippopotamus, hippopotamus, what do you hear?
   I hear a elephant trumpeting in my ear.

Submitting Programs

The programs written for all 3 parts of this assignment must be turned in by transferring the respective C++ source code file to your ftp directory for this class. For each part of the assignment, only the source code file (i.e., sounds1.cpp, sounds2.cpp and sounds3.cpp) should be turned in.