Assignment 08

Due: Wednesday, April 16, 2014 at noon 100 pts For this assignment you will submit multiple files in the usual way. These files will contain a C++ program that you have named appropriately, each file with an appropriate name and appropriate extension. Be sure that your program compiles using the g++ compiler before you submit it. To compile a program with multiple files, use the usual fg++ command but instead of the single file you compiled before, compile *.cpp and the compiler will "grab" all the cpp files in that directory. Use cssubmit in the usual way. Background: The effect that your programming has had on Ralph is really notable. Ralph has a new appreciation for intelligence, thoughtfulness, and fame. So, with his new-found knowledge of computing, math, and critical thinking, Ralph has begun to see himself as a member of the intelligentsia, a guru of thought, a prophet of wisdom, a master of insight. And, so, Ralph is now selling this wisdom. He sees clients and dishes out words of wisdom for a price. BUT, knowing that you will be able to help out, he wants you to write a program that will answer questions from the public .... while he plays with his stupid plastic letters and his stupid plastic wookies.

Specifications: Your program is to greet the user, and repeatedly prompt for questions for Ralph to expound upon until there are no more questions. Your program, upon reading in a question (from the user) will generate a "random" Ralph-answer. Henceforth, we will refer to these answers as Ralphisms. I like that....Ralphisms. Each Ralphism will be one of two forms:

  • "My <noun1>'s <noun2> <verb> like <noun3>." or

  • A "stock" Ralphism chosen at random from a file of Ralphisms.

Details: The nouns noun1 and noun2 and noun3 will be chosen at random from lists of nouns that you will put in a data file for this program. (They are listed below.) Each of the three files will contain nothing but nouns. The verb will be chosen at random from a file containing the verbs listed below. Again, the file will contain only those verbs. Note: to create those files (and any other data files for this program), edit the files just as we do with any other file; do not try to do a copy and paste! I'd suggest naming the files something like noun1.dat and noun2.dat and noun3.dat and verb.dat. (When you copy and paste, spurious control characters can get copied and make your program not work as expected.) As stated above, a Ralphism is to be chosen at random from a file of Ralphisms (also listed below). Why not name that file ralphisms.dat. You will notice that I have put a 's after noun1. It is supposed to be possessive. So, once you choose the noun1 from the noun1 list, tack on 's to it.

So, how do you choose between option 1 and option 2 above? Randomly, of course. There is to be a 75% chance option 1 is output and a 25% chance option 2 is output.

Furthermore, Ralph, with his little brain, has it fixed in his mind that big words are not to be trifled with. So, he also occasionally uses the longest word in a question in his answer. In fact, there is a 50% chance he will use that longest word. So, part of your program is to identify the longest word in the question and (possibly) use it as either noun2 or noun3. Of course, you do this only if option1 above happens to be the format of the answer. Currently, there is a 75% chance it is used for noun2 and the rest of the times for noun3.

Important: You are required to null-terminated character arrays for this assignment for all the data. However, if you want to use standard strings for the names of the files, you may do that. You'll understand what this means after my lecture on files.

One more thing: We have tried and tried to get you to think about using constants this semester as you learned C++. For this assignment, there are parameters for the operation of the program; they should be constants. These are values like what percentage chance option 1 is chosen over option 2. We're going to test your dedication to making constants in the following way. approximately 24 hrs before the assignment is due, I will send out an email telling you that the parameters have changed in the assignment. IF YOU HAVE MADE CONSTANTS for the values you should have made them for, the changes will take you no more than 2 minutes to edit, recompile and resubmit. So, think constants!!

When you submit: Run the program 3 times, entering questions of your own choice (using big words!).

And as always, if you have any questions ..... the answer is "my cat's breath smells like cat food."

Now for the lists/files:

  • noun1

dog cat fish mother father wookie teacher playmate mailman caseworker head grammy

  • noun2

shoe arm brain car toy tooth mouth gun friend truck foot paste compiler sock hotdog

  • verb

eats smells looks funs feels tastes sounds oozes bites codes

  • noun3

catfood

paste

ink

donuts

star wars characters

a compiler

feet

worms

  • Ralphisms

    1. I bent my wookie!

    2. When I grow up, I want to be a principal or a caterpillar.

    3. I'm too scared to even wet my pants.

    4. This is my sandbox, I'm not allowed to go in the deep end.

    5. Go Banana!

    6. What's a diorama?

    7. Wheeeee....owe, I bit my tongue.

    8. My toys are all sticky.

    9. So, do you like .... stuff?

    10. I ated the purple berries.

    11. I found a moon rock in my nose.

    12. Oh boy, sleep! That's where I'm a Viking!

    13. I heard a Frankenstein lives there.

    14. My parents won't let me use scissors.