Due: Wednesday, Nov. 9, 2016, 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 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 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.
Lisa wants to run for public office. She's going to challenge Diamond Joe Quimby for the position as mayor of Springfield. So, she knows that the public will want to endure inane debates. In order to prepare for these so called debates, she wishes that you write a program that will simulate a debate between two candidates. In this way, Lisa 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 (clown) candidate will say whatever he/she wants, relevant 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.
So, now let's state how your program is to build the answer. You will follow these directives:
You will have 5 files of string data. Each candidate will have two files dedicated to their responses: one file contains sentences used to build answers; the other will contain common interjections associated with that candidate. The 5th element of this insanity is a file containing introductory/accusatory phrases that might be appended to the beginning of either candidates' answers.
The chance of appending to the beginning of an answer is 50%. If you are to append one of these phrases, then you are to choose one at random from that fifth file (described above).
For each answer, you are to choose a number randomly from 2 to 4, inclusive (pretty much, that means 2 or 3 or 4). Use that value to choose at random that many sentences from the corresponding candidates sentence file, divide each sentence into that many roughly equal parts (break at white space), then construct the answer by taking the first portion of the first sentence, second portion of the second sentence, and so on, and concatenating them. This will effectively emulate the garbage you hear on TV.
Furthermore, since this isn't enough, between each sentence portion, you will insert an interjection from that candidate's interjection file with a probability of 25%. The interjection should be randomly chosen.
If a phrase is added to the beginning of the answer, you should de-capitalize the first letter of the answer-sentence.
You will replace the (sentence) ending punctuation so that there is a
40% chance it is a period
30% chance it is a question mark
30% chance it is a exclamation point
We'll describe below how to get the files of sentences, etc.
That leads us to how the score is determined. For a given question and answer pair, you will score it much like scrabble is scored:
Each alphabetic character in an answer is given a score determined by this assignment: 1 pt for: e, a, i, o, n, r, t, l, s, u; 2 pts for: d, g; 3 pts for: b, c, m, p; 4 pts for: f, h, v, w, y; 5 pts for k; 8 pts for: j, x; 10 pts for: q, z.
Non-alpha chars are not scored. Both upper and lower case letters get the same score....e.g. 'A' is scored the same as 'a'.
Each character has a 2% chance that it is given a triple-letter score - meaning its value is tripled.
Each character has a 3% chance that it is given a double letter score.
Each word has a 5% chance that it's score is doubled in value.
Each word has a 2% chance that it's score is tripled in value.
Any word score will include any double or triple letter scores.
No individual character can be both double and triple.
Likewise with words (can't be both double and triple).
The score for an answer is the sum of the word scores for that answer divided by the number of characters in the corresponding question.
Details: This program is NOT easy!! But
You are allowed to work with a partner (encouraged) if you want. Only groups of two can make a coding team. 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.
You MUST USE ONLY null-terminated character arrays (c-strings) for the code. However, you may use standard strings for the names of files if you wish.
The data for the files is extensive. For you to type in all the answers, phrases, etc. 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/candidate1_sentences.dat
wget http://web.mst.edu/~price/1570/candidate2_sentences.dat
wget http://web.mst.edu/~price/1570/candidate1_interjections.dat
wget http://web.mst.edu/~price/1570/candidate2_interjections.dat
wget http://web.mst.edu/~price/1570/prefix_expressions.dat
Doing this will copy the files from my directory into yours named candidate1_sentences.dat, etc. 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 all but the last file is the number of lines in each file. You can use that to your advantage. However, the last 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 may assume the following:
no sentence or answer will exceed 1000 chars
no word will exceed 20 chars
all sentence-ending punctuation will be . or ! or ?
there is only one space between words (contiguous non-whitespace chars); that includes the space between sentences.
When you submit: Run the program and type in 8 questions for the idiots ... uh, candidates. You ask any question you wish. Let's see how they do!
As always, ask if you need help.