Assignment 07

Due: Monday March 14, 2011, 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.

Background: Trogdor, now tired of burning peasants and all the red-tape that it generates with the Federal Burninations and Flaming Peasants Commission (FBFPC), the constant harassment of the various world armies sent to "save people" (hmmph, crybabies), and the yearly trials of replacing the tip of his nose which suffers "burn fatigue", has decided to enroll in S&T to get a good education so he can become a Burninations Engineer (BE). White-collar burninations is much easier than working in the trenches.

He has to learn arithmetic. He needs your help.

Specifications: Your program will be a "quiz-er" for the user. That is, your program will present the user with a quiz of arithmetic problems. Each "play" of the quiz will be 10 questions. The user will initially be presented with a short menu of options on difficulty level. It could look something like this:

DIFFICULTY LEVEL 1. Easy 2. Moderate 3. Advanced

The difficulty levels determine the number of digits in the operands to be added, subtracted, multiplied, or modulo-ed (moded?). Easy means only single digit numbers; moderate means double digit numbers; and advanced means 4-digit numbers. After the user picks the level they desire, your program presents another menu for the operation to be used in the problems. It could look like this:

OPERATOR CHOICE 1. I feel lucky - randomly chosen operators 2. Pick a particular operator

If option #1, then each problem will have an operation (+, -, *, %) chosen by your code randomly. If option #2, the user is prompted for an operator to be used for all 10 questions. Then your program starts presenting problems like this:

45 + 9 = _ etc

For each problem presented, the user is given a chance to answer. If the answer is correct, another problem is presented. If the answer is wrong, the user is to be given one more chance at that problem. Once your program has moved on to the next problem, the correctness/incorrectness of the preceeding problem is tallied. The number of correct and incorrect answers is to be presented at the termination of the quiz along with percentage correct.

You are to create a struct to contain a problem : the operands, the arithmetic operator, and the answer. (For the example shown just above, the operands would be 45 and 9, answer would be 54, and the arithmetic operator would be '+'.) Thus, this struct will have three int members for the two operands and answer, and a char member for the operator (presumably + or - or * or %). So, how are the problems produced? You will include an overloaded function called generate_problem. One version will return a bool and have a reference parameter of type problem. The other will also return a bool and have the problem parameter but will also have a second parameter of type char to represent a specific arithmetic operator. Both versions will need to have another parameter whose value will be some indication of the difficulty of the problem. I'll let you figure out this one. The function will produce the problem "wrapped up" in a problem object with randomly chosen operands and either a random operator or the operator passed, depending on which function. So what's the meaning of the return value? Well, it should return true if the problem is a valid problem, false otherwise. It is invalid if the operator that is used is bogus. Suppose someone passes '~' as a mathematical operator!

You will use functions in this program. You are to decide (you will be the "decider") on the structure of the main and what functions you are to use. You will be graded on how well you use functions and on your program layout.

Here is a suggested listing of other functions you can use in your program. You may include others if you see fit. You can opt not to use any of this; but you must use functions. It's up to you.

  • a displayMenu function that has no parameters and returns a char

  • a randomInt function that has 2 integer parameters (a minimum and a maximum) that returns a random integer between arguments min and max.

  • a generateOperands function that returns nothing but has three parameters. One parameter represents the difficulty level (char). The other two are reference parameters representing the operands of the arithmetic problem that the calling function will use.

  • a displayProblem function that returns a long int (the answer that the user inputs) and has a parameter you pass the problem to.

  • a isCorrect function that returns a bool (correct or not) and is passed enough information to reconstruct the problem for that determination. The return value is determined in this function by whether or not the user's answer is correct for the given problem.

  • a displayMessage function that returns nothing but outputs a correct answer message or an incorrect answer message, dependent on the value returned by the preceding function.

  • a displayFinalResults function that returns nothing and has two parameters: the number correct and the number wrong.

Once the user has finished the quiz, prompt them to see if they'd like to do it again. When you submit, play the quiz once and opt out of a second go round.

Optional: If this isn't enough for you, include a function that will choose at random from a list (your own)of 4 output messages for good answers and a list (your own) of 4 output messages for wrong answers. Of course, make the messages appropriate.

Another Optional: Make the number of tries at each problem a prompted for parameter for each run of the quiz at the beginning of the quiz.

Final Note: Don't underestimate the complexity and yaddi yaddi yaddi. Start to work on it NOW .

As always, if you have questions, don't hesitate to ask your instructor or the LEAD GUY if you need help. Don't ask your barber or hairdresser.