EE 312 Project 2 - Problem Decomposition & Program Structure


You must complete this project by yourself. You cannot work with anyone else in the class or with someone outside the class. Request help from the instructor and TAs.

Due: By 11 pm, Monday, Sept 17

The purpose of this assignment is for you to:
1. To practice creating structured programs
2. To practice removing redundancy from programs
3. To practice good program hygiene

Fill in this header with your own information and place it at the top of your Song.c file:
// Song.c -- EE 312 Project 2

/* Student information for project:
 *
 * Replace <NAME> with your name.
 *
 * On my honor, <NAME>, this programming project is my own work
 * and I have not provided this code to any other student.
 *
 * Name:
 * email address:
 * UTEID:
 * Section 5 digit ID:
 * Number of slip days used on this assignment.
 */
You are required to follow the EE 312 Style Guide on this project. If you do not, you will lose points.

After you read the project description, you may think that this project is easy. The goal is for you to focus solely on program structure. Due to the simplicity, this project is worth half as much as your other projects. The intention of this assignment is to encourage a mindset about software design that you carry forward into your other projects in EE 312 and beyond.

It is not sufficient to produce the correct output. Correct output is necessary, but not sufficient, to score well on this assignment. Use procedural decomposition to break the problem into meaningful subtasks and to eliminate redundancy. Read the instructions very carefully.

Complete a C program that, when run, produces the following output (the lyrics of the song There Was an Old Woman Who Swallowed a Fly):

There was an old woman who swallowed a fly.
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old woman who swallowed a spider,
That wriggled and iggled and jiggled inside her.
She swallowed the spider to catch the fly,
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old woman who swallowed a bird,
How absurd to swallow a bird.
She swallowed the bird to catch the spider,
She swallowed the spider to catch the fly,
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old woman who swallowed a cat,
Imagine that to swallow a cat.
She swallowed the cat to catch the bird,
She swallowed the bird to catch the spider,
She swallowed the spider to catch the fly,
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old woman who swallowed a dog,
What a hog to swallow a dog.
She swallowed the dog to catch the cat,
She swallowed the cat to catch the bird,
She swallowed the bird to catch the spider,
She swallowed the spider to catch the fly,
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old woman who swallowed a goat,
She just opened her throat to swallow a goat.
She swallowed the goat to catch the dog,
She swallowed the dog to catch the cat,
She swallowed the cat to catch the bird,
She swallowed the bird to catch the spider,
She swallowed the spider to catch the fly,
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old woman who swallowed a cow,
I don't know how she swallowed a cow.
She swallowed the cow to catch the goat,
She swallowed the goat to catch the dog,
She swallowed the dog to catch the cat,
She swallowed the cat to catch the bird,
She swallowed the bird to catch the spider,
She swallowed the spider to catch the fly,
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old woman who swallowed a horse,
She died of course.

Here is the output file the graders will use on Project 2 (Project2_Song_Output.txt). Your output must match this exactly or you may lose points for correctness. Use a diff tool such as the one at this website ( www.quickdiff.com) to ensure your program produces the correct output. Please note, if you view the output above via a web browser, the browser will very likely remove the last newline character. This causes a minor difference between the expected output and your output. The last line of the song, "She died of course.", is printed out with a newline character at the end of the statement, just like all the other lines of the song. I recommend you download the file by putting your cursor over the link and bringing up a context menu (right click on Windows, control click on Macs) and select the option to download the file.

You may only write functions with no parameters and no return values. Other than the functions you write yourself, the only function you will call is printf.

Every call to printf in your program should have \n at the end of the format string.  Do not use variables, parameters, loops, conditional statements, return values, etc. 

Use functions to capture the structure of the song.  You should, for example, have a different function for each of the eight verses of the song (verses are separated by blank lines in the output).

Make use of functions to avoid redundancy.  In particular, you are to make sure that you use only one printf statement for each distinct line of the song.  For example, this line:

Perhaps she'll die.

appears several times in the output.  You are to have only one printf statement in your program for producing this line. On the other hand, do not make functions with a single printf statement and no other statements or function calls. Functions such as those take program decomposition too far. It is likely you will have functions with a single printf statement in addition to other function calls or statements.

In other words this is bad:

void someFunction() {
    printf("SOME STUFF\n");
}

but this is okay and necessary in some cases:

void someFunction() {
    printf("SOME STUFF\n");
    callAnotherFunction();
}

There is a more complex redundancy that comes up with pairs of lines like these:

    There was an old woman who swallowed a horse,
  There was an old woman who swallowed a dog,

and like these:

    She swallowed the dog to eat the cat,
  She swallowed the cat to eat the bird,

It is not possible to avoid this redundancy using just functions without parameters and simple printf statements, so you are not expected to do so. 

In other words the lines

    There was an old woman who swallowed a horse,
  There was an old woman who swallowed a dog,

are very similar. The only difference is the last word. It is okay to have one printf for the line

    There was an old woman who swallowed a horse,

and another printf for the line

    There was an old woman who swallowed a dog,

even though it seems redundant.

There is, however, a structural redundancy that you can eliminate with functions.  The key question to ask yourself is whether or not you have repeated lines of code or statements that could be eliminated if you structured your functions differently. These lines of codes could be calls to functions instead of printf statements.

For this assignment, you shall limit yourself to functions and printf statements containing format strings that end with a newline. Do not use other kinds of print statements or other C language features.

Submission: Turn in your Song.c file on Canvas. If you do not turn in the correct file with the correct name, you will very likely waste slip days or get a 0 on the assignment. Your submission must be named Song.c

Note: You may turn in the file multiple times via Canvas. Canvas adds a "-1" to the file name. So if you turn in the program a second time before the due date, the file name will be Song-1.c. That is fine. Our grading scripts will adjust for the extra cruft Canvas adds to the file name.

Checklist: Did you remember to: