Assignment 08

Due: Friday, November 2, 2018, 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 all know by now, the mid-term elections are upon us ... like a mosquito on your neck, like a dog's teeth in your leg, like knife in your back! Yep, the candidate 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 speeches. 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, relavent 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 gauge 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. I've created a list of answers and put them in a data file. You will get that data file, called answers.dat., from me and store it in your hw 8 directory. 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 a file of nouns that I've also created. So, you also must get the file called noun.dat that contains this list. How to obtain these files will be revealed to you below.

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) everywhere 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.

    • 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.

Special Note: You are to use only null-terminated character arrays (NTCAs) for the coding in this assignment. You can use the standard string only for file names if you need/want. Think carefully how your code will read and handle the data. Remember that you have been taught how to read in char-by-char, word-by-word, and line-by-line. Also, you are allowed to work in a group of no more than two people if you want. A group of two is optimal and can make an optimal coding team. We encourage that. Your partner must have the same cs 1570 instructor. Put both names on every file for this program. Submit under ONLY ONE NAME so that we print only one copy. Groups of one person is ok. Groups of 0 are strictly forbidden as this tends to suggest sympathetic Zombie behavior.

Also, the answers you generate and output can be rather long. You don't need to worry about losing points for "wrap-around" in the output (going past the 80th column).

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 long-winded since you have to type them in.

The Data: The data for the files is extensive. For you to type in all the answers and nouns to create the files would be odious (oooooh, I like that word). Thus, we are providing those files for you and a very simple way to "download" them. Create the directory where you are going to make your hw8 program, and then change to that directory. Then, at the unix prompt, type

    • wget http://web.mst.edu/~price/1570/answers.dat

    • wget http://web.mst.edu/~price/1570/nouns.dat

Doing this will copy the files from my directory into yours named answers.dat and nouns.dat. You'll see them when you issue the unix command ls. This will save you a LOT of time. You will notice that the first datum in answers.dat is the number of lines in that file. You can use that to your advantage. However, the nouns file does not have that information and you are NOT to put it in there. Your program's code will have to deal with that unknown. You can assume that there is a newline character at the end of each line in both files.

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. You can also ask the candidate...or your congressman...but there's no telling what they might say.