Problem Definition

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 him if he 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.

Note that there is a tab before each of the questions (ex: “Plural noun:”)

File Format

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

There once lived a [adjective] [creature] who wished he were [emotion] . Because [#] of his [adjective] looks , no one wanted to be his [noun_(singular)] . Then [#] one day a [adjective] [noun] found the [creature] [#] and thought [{] I'll be his [noun] . [}] From [#] that [unit_of_time] forward, they were [emotion] .

Notice the following traits of the file:

  • Every word, keyword, or punctuation is separated by a space or a newline. These are called tokens.
  • Tokens are surrounded by []’s. These are: See image.
  • If a prompt is encountered, convert the text inside the prompt to a more human-readable form. This means:
    • Sentence-case the text. This means capitalize the first letter and convert the rest to lowercase
    • Convert underscores to spaces.
    • Proceed the prompt with a tab
    • Put a colon and a space at the end
    • The user’s response to the text could include spaces.

Your program will not need to be able to handle files of unlimited length. The file is guaranteed to have the following properties:

  • There are no more than 1024 characters total in the file.
  • There are no more than 32 lines in the file.
  • Each line has no more than 80 characters in it.
  • There are no more than 256 words in the file.
  • Each word is no more than 32 characters in length.

Assignment: Design Document

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

  • Create a structure chart describing the entire Mad Lib® program.
  • Write the pseudocode for the function readFile. This function will read the data from the Mad Lib® file into some data structure (examples: a string, and array of something). Please put some thought as to how you will store the data from the Mad Lib®.
  • Write the pseudocode for the function askQuestions. This function will ask the user all the questions specified in the file and remember the user response to be displayed later. 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
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.