Project 08 : Mad Lib

Due Saturday at 5:00 PM MST

Write a program to implement Mad Lib®. According to Wikipedia:

Mad Libs is a word game where one player prompts another for a list of words to substitute for blanks in a story; these word substitutions have a humorous effect when the resulting story is then read aloud.

The program will prompt the user for the file that describes the Mad Lib®, and then prompt him for all the substitute words. When all the prompts are complete, the program will display the completed story on the screen.

Interface Design

The program will prompt the user for the filename of his Mad Lib®, allow him to play the game, then ask the user if he/she wants to play another. Consider the following Mad Lib® with the filename madlibZoo.txt:

Zoos are places where wild :plural_noun are kept in pens or cages :! so
that :plural_noun can come and look at them :. There is a zoo :! in the park 
beside the :type_of_liquid fountain :. When it is feeding time, :! all 
the animals make :adjective noises. The elephant goes :< :funny_noise 
:> :! and the turtledoves go :< :another_funny_noise :. :> My favorite 
animal is the :! :adjective :animal :, so fast it can outrun a/an 
:another_animal :. :! You never know what you will find at the zoo :. 

An example of the output is:

Please enter the filename of the Mad Lib: madlibZoo.txt
        Plural noun: boys
        Plural noun: girls
        Type of liquid: lemonade
        Adjective: fuzzy
        Funny noise: squeak
        Another funny noise: snort
        Adjective: hungry
        Animal: mouse
        Another animal: blue-fin tuna

Zoos are places where wild boys are kept in pens or cages
so that girls can come and look at them. There is a zoo
in the park beside the lemonade fountain. When it is feeding time,
all the animals make fuzzy noises. The elephant goes "squeak"
and the turtledoves go "snort." My favorite animal is the
hungry mouse, so fast it can outrun a/an blue-fin tuna.
You never know what you will find at the zoo.

Do you want to play again (y/n)? n
Thank you for playing.

An executable version of the project is available at:

/home/cs124/projects/prj10.out

File Format

Consider the following user's file called madLibExample.txt:

This is one line with a newline at the end. :!
Here we have a comma :, and a period :. :!
We can have :< quotes around our text :> if we want :!
This will prompt for :< My favorite cat :> is :my_favorite_cat :. :!

Notice the following traits of the file:

Several examples of the file format are available at:

/home/cs124/projects/madLib*.txt

Assignment

The first part of the project is the design document. This consists of three parts:

  1. Create a structure chart describing the entire Mad Lib® program.
  2. Write the pseudocode for the function readFile(), a function to read the Mad Lib® file into some data structure (examples: a string, and array of something). You will need to include the logic for reading the entire story into the data-structure and describe how the story will be stored.
  3. Write the pseudocode for the function askQuestion(). This need to describe how to turn ":grandma's_name" into "\tGrandma's name: " and also describe how to put the user's response back into the story. If, for example, the file had the tags :favorite_car and :first_pet's_name, then the following output would result:
            Favorite car: Ariel Atom 3
            First pet's name: Midnight
    

Assessment

The only deliverables for this project are two pseudocode functions and one structure chart.

Turning it in

Please turn this in through I-Learn using Assignment Submission. This should be a single document submission.

Grading

The grading criteria are:

  Exceptional
100%
Good
90%
Acceptable
70%
Developing
50%
Missing
0%
Structure Chart
30%
Design is elegant and well thought out Design will solve the problem A bug exists or parts of the design are not described in enough detail Structure chart not showing the connection between the functions, name of the functions, or the data passed between the functions No structure chart
readFile: Storing the story
20%
The best possible data storage strategy was chosen Design is workable, correctly reading the file and storing it in a data structure There is a flaw in the design or one part of the data storage strategy not adequately described Large parts of the data storage strategy not described or a "fundamental flaw" exists No mention of how to store the story in memory
readFile: Reading the data
10%
All possible error conditions are handled in the design No bugs are presented in the readFile function A bug exists in the algorithm or some part of the algorithm not sufficiently described Pseudocode insufficient quality to help in the design process No pseudocode for the readFile function
askQuestion: Create a prompt
20%
A very efficient algorithm is described in the pseudocode Design is workable, correctly prompting the user A bug exists in the algorithm or some part of the algorithm not sufficiently described Not enough detail to tell how to turn the text in the <>s into a prompt No pseudocode describing how the text in the <>s is turned into a prompt
askQuestion: Insert answer into story
20%
Design is elegant and well thought out User input is correctly inserted into the story A bug exists in the algorithm or some part of the algorithm not sufficiently described An attempt was made to put user data in the story No pseudocode describing how to put the user response in the story