Assignment 08

HOMEWORK #8

CS 53

Due: Wednesday, Nov. 7, 2012, at noon, 100 points

For this assignment you will submit (in the usual way) multiple files. 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 g++ command but instead of the single file you compiled before, compile *.cpp and the compiler will "grab" all the cpp files in that directory. So, you see, it's important that you put all the files for a particular program in their own directory! You don't have to list the header files; that will happen automatically. Use cssubmit in the usual way.

Background: As you alll know by now, the presidential election is upon us ... like a mosquito on your neck, like a dog's teeth in your leg, like knife in your back! Yep, the presidential debates (NOT!) are here. Have you listened? Frankly, I find them annoying. I find them so because most often the "debaters" don't actually answer the questions directly. Mostly, they go on and on with their canned speaches. I was going to give you examples in this write up, but the answers that I read from transcripts of past debates were so long-winded I backed off from copying them here. I didn't want to bore you to death. But this sets the stage for what you will code in this assignment.

Krusty wants to run for public office. He's going to challenge Diamond Joe Quimby for the position as mayor of Springfield. So, he knows that the public will want to endure inane debates. In order to prepare for these so called debates, he wishes that you write a program that will simulate a debate between two candidates. In this way, Krusty will be able to practice (if indeed it's possible to practice nonsense) responding to questions in a real debate. So, your program will simulate a debate between two candidates. Each candidate will be given 4 questions (alternating candidates), and each candidate will respond to each question. Now, the term "respond" could be replaced by "jabber", "go on and on", "ramble", "blather", etc. In any case, that response is generated by your program. At the end of the debate, a score is tallied and a winner is announced. Yipppeeee! My candidate wins .... and we all lose!

Specifications: Your program is to ask the person at the keyboard to enter a question for each candidate, trading off, four times.

candidate #1: "What do you think ....." ans: ........... score = xxx candidate #2: "How will you .... " ans: .......... score = xxx etc

After each question, your program displays the answer, and the score for that question/answer pair. Of course, you can enter any question you wish. As you know, in a real debate the question doesn't matter because the candidate will say whatever he/she wants, relevent or not. At the end of the debate (after the 8 questions are stated and answered), the tallied score is displayed and the winner is declared! Yeeaaa! The lowest tally (sum of individual scores) wins.

That leads us to how the score is determined. For a given question and answer pair, you will:

    1. determine the number of times 'a' appears in the question and the number of times it appears in the answer. Subtract these two.

    2. repeat this with 'b', 'c', etc. Sum these, and that's the score for that question/answer. This is the ONLY reasonable way to guage how closely the answer matches the question. Sound stupid? You betchya! Just like the debate your program is going to generate....

So, how are the answers generated? At random, of course. Below is a list of answers. You will create a data file called answers.dat. Everytime you want to answer a question, you must access this file and pick at random one of the answers. This will be the answer to the question. But, you will notice that each answer has *noun* inserted in it at one or more places. When using this answer, you must replace the tag *noun* with a noun chosen at random from the list of nouns below. So, you also must create a file called noun.dat that contains this list.

You know the result is going to be very very funny. Beware: though it will be funny, don't run your completed program too many times as you may actually lose some points from your IQ by reading the answers.

Details:

    • You are required to use null-terminated character arrays (cstrings) in your program.

    • You may assume that no question or answer will exceed 700 characters.

    • You may assume that no word is longer than 20 characters.

    • When you create your nouns.dat and answers.dat files: right click on the link; choose "save link as:" and save it to your S drive in the file where your program is (I'd assume it is cs53/hw8). If you do a "copy and paste", you run the risk of introducing all sorts of hidden characters that will make your program mess up. I have placed a newline character at the end of each answer. This is something that your code will depend on. Don't format the file(s) any other way; don't introduce a newline ('\n') anywhere else in the sentences - like don't worry about the wraparound issue.

    • I'd suggest the following for developing your program: make your answers.dat and nouns.dat files by typing in one sentence with one *noun* in it and a "enter" at the end, and 3 or 4 nouns with "enters" at the end of each entry. Save just that much and work on your program. After you have it working, then remove the answers.dat and nouns.dat files and make the full files according to the instructions above. If it doesn't work then, you know there must be something wrong with the files....maybe.

    • Notice that there is an integer at the top of the answers file. That is the number of answers in the file. That you can count on for your code. However, there is no such number in the nouns file. Don't put one there. You have to write code that counts the data in that file and then use it in subsequent code.

When you submit: you will engage this exercise with relish. That means that you will have to ask the candidates a total of 8 questions. Make them good! But, don't be longwinded since you have to type them in.

The Data:

Warning: This assignment is NOT trivial. It will take time and careful coding. Don't underestimate it.

As always, if you have questions, don't hesitate to ask your instructor or the LEAD tutors.