SUNY Geneseo Department of Mathematics
Math 230 02
Spring 2015
Prof. Doug Baldwin
Complete by Tuesday, May 5
Grade by Tuesday, May 12
This exercise helps develop your ability to design data structures to represent complex abstract concepts. It also gives you some practice working with Matlab strings, string input and output, and files.
Mad Libs is a word game involving a short story or other piece of text with some words missing. Players suggest words to insert for the missing ones, but without knowing the story. The result is an often-funny mangled story. See http://www.madlibs.com/ for more information. Your goal in this project is to write a Matlab program that manages a game of Mad Libs.
Your solution to this exercise will probably rely heavily on strings (i.e., vectors of characters). We will talk about strings in lecture on April 27, and you can find a discussion in chapter 7 of Attaway’s text.
One thing we did notice about strings is that you can’t easily make ordinary vectors of them (see our lecture notes from April 22). Cell arrays are the usual way around this problem. They were discussed in the April 22 class, and in section 8.1 of the textbook.
In order to play an interactive game of Mad Libs, your program will need to input
strings from the user, and output strings to the user. Matlab’s input
and
fprintf
functions will be helpful for this. Section 3.3 of
Attaway’s text discusses both.
Finally, you will need to save Mad Libs to files and load them from files. Attaway talks about such file operations in section 9.3, and we discussed them in class on April 24.
Write a Matlab function that takes a representation of a Mad Lib as its argument, and that “plays” that Mad Lib with its user. In particular, your function should…
Note that your Mad-Lib-playing function will have no explicit return variable, since it produces its result by printing the completed Mad Lib.
In addition to the function that plays a Mad Lib with the user, you should also be able to save a Matlab representation of a Mad Lib into a file, and load it back from its file. Note that this may be more a matter of knowing single Matlab commands for saving and loading relevant variables than of writing substantial amounts of Matlab code.
The central problem in this exercise will probably be to think of a “representation” of a Mad Lib as Matlab data. To get you started, consider that a Mab Lib is basically an alternating sequence of text fragments and blanks. Each blank has a cue for the kind of word that should fill that blank. The sequence starts and ends with text fragments. For example…
Text Fragments | Cues for Blanks |
---|---|
Once upon a time there lived a | |
Noun | |
who was very | |
Adjective | |
But luckily, he/she/it met a | |
Noun | |
and lived happily ever after. |
There are several ways you could represent such an alternating sequence in Matlab.
I will grade this exercise in a face-to-face meeting with you. During this meeting I will look at your solution, ask you any questions I have about it, answer questions you have, etc. Please bring a written solution to the exercise to your meeting, as that will speed the process along.
Sign up for a meeting via Google calendar. If you worked in a group on this exercise, the whole group should schedule a single meeting with me. Please make the meeting 15 minutes long, and schedule it to finish before the end of the “Grade By” date above.