Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Can someone please help me with this problem! or at least have it set up the structures so I can finish up the rest

C++

Can someone please help me with this problem! or at least have it set up the structures so I can finish up the rest

TheMathGame:

Your task is to develop a program that will teach youngsters the basic math facts of addition, subtraction, multiplication and division. The program generates random math problems for students to answer. Students get a small reward for correct answers and suffer a small penalty for incorrect ones. User statistics need to be recorded in a text file so that they may loaded back into the program when the student returns to play the game again. In addition, the youngster should be allowed to see how (s)he is doing at any time while (s)he is playing the game. One of the MAJOR objectives of this assessment is for you to demonstrate your ability to use classes.

WARNING:

You must use the included .h files and you may not add or delete ANYTHING from the .h files.

You should also note that your main() function should consist of mostly function calls and not be greater than 100 lines in total; however, your entire program will consist of more lines of code!

PROGRAM REQUIREMENTS

The math problems generated must meet the following requirements:

Each class must have its own default constructor

Each class must generate and display a math problem

Each class must overload the

Each class must be able to check if the answer to the problem provided by the player is right or wrong

Each class must validate the user entry to ensure it is in fact an integer, dont let your program crash as this will cost a substantial loss of points!

You must use a class for each of the four problem types. Specifically, you must have:

h and corresponding Addition.cpp

h and corresponding Subtraction.cpp

h and corresponding Multiplication.cpp

h and corresponding Division.cpp

You must demonstrate use of classes, this means you:

Must have a separate .h file for each class prototype

Must have a separate .cpp file for each class prototype

You must use the included .h files, including the Game.h. You may not add or delete ANYTHING from the .h files

The operands must be randomly generated.

For the addition the total must be an integer >= 0

For the subtraction the difference must be an integer >= 0

For the multiplication the product must be an integer >= 0

For the division the quotient must be an integer >= 0

Validate user input at every opportunity. If your program crashes because you allow the user to make an invalid entry and you did not write code to handle such potential exceptions, you will NOT pass the midterm due to a substantial loss of points!

The program should keep track of the following statistics:

The users name

The total correct answers

The total wrong answers

The total earnings ($0.05 is awarded for every correct response and $0.03 is subtracted from every incorrect response)

A separate text file must be created for every user, the file name should be the players username:

Statistics are read from the file at the start of the game (if the user is a returning player).

Statistics are recorded in the text at the end of every game. Alternatively, you may want to store on to the text file after every problemit is up to you!

The program must be developed using functions so that the main() function consists mostly of function calls. Below is a list of most of the functions I used, you may add your own functions if you like:

credits //This function is used to display your name and what the program does

menu // This function is used to display the menu with various options

validateUserResponse // This function is used to validate user input from the menu

validateUserAnswer // This function is used to validate user input and ensure that ONLY numeric answers are entered by the user.

checkUserAnswer // given a math problem, this function is used to check if the answer the user entered is correct or incorrect

updateStats // This function is used to keep a running total of game statistics (in RAM)

displayStats // This function is used to display statistics on screen

retireveStats // This function is used to retrieve player statistics from external txt file when the game starts, assuming the player is a returning player, else create a text file to store the stats.

saveStats // This function is used to save player statistics on an external txt file.

You may also want to consider the following four functions: generateAddition, generateSubtraction, generateMultiplication and generateDivision // use these to generate a problem of the appropriate type.

All functions must be correctly prototyped.

All functions must be correctly defined.

You must use meaningful variable names.

You must comment your code.

You must use variables of the correct type and initialize them with a proper value.

GENERAL RESTRICTIONS

No global variables

No labels or go-to statements

No infinite loops, examples include:

for(;;)

while(1)

while(true)

do{//code}while(1);

No break statements to exit loops

--------------------------------------------------------------------------------

#ifndef Addition_h

#define Addition_h

#include

#include

using namespace std;

class Addition

{

//Overload the stream insertion and extraction operators

friend ostream& operator

public:

Addition();

//default constructor

//Postcondition: theAnswer=0; userResponse=0;

//invokes randomize();

void randomize();

//Function to generate two random numbers between 1 and 10.

//Postcondition: num1 and num2 are equal to between 1 and 10;

//and theAnswer = num1 + num2;

bool checkAnswer();

//Function to check userAnswer with problem answer (theAnswer)

//Postcondition: if theAnswer==userResponse appropriate feedback is displayed

// returns true if user answer is correct or returns false if user answer is incorrect;

void validate(string str1);

//Function to validate user response

//Postcondition: function accepts a string, validates it to be an int;

private:

int num1;//variable to store one of the operands

int num2;//variable to store one of the operands

int theAnswer;//variable to store the answer to the problem

int userResponse;//variable to store the user response to the problem in int format

};

#endif

--------------------------------------------------------------------------------

#ifndef Division_h

#define Division_h

#include

#include

using namespace std;

class Division

{

//Overload the stream insertion and extraction operators

friend ostream& operator

public:

Division();

//default constructor

//Postcondition: theAnswer=0; userResponse=0;

//invokes randomize();

void randomize();

//Function to generate two random numbers between 1 and 10.

//Postcondition: num1 and num2 are equal to between 1 and 10;

//and theAnswer = num1 / num2;

bool checkAnswer();

//Function to check userAnswer with problem answer (theAnswer)

//Postcondition: if theAnswer==userResponse appropriate feedback is displayed

// returns true if user answer is correct or returns false if user answer is incorrect;

void validate(string str1);

//Function to validate user response

//Postcondition: function accepts a string, validates it to be an int;

private:

int num1;//variable to store one of the operands

int num2;//variable to store one of the operands

int theAnswer;//variable to store the answer to the problem

int userResponse;//variable to store the user response to the problem in int format

};

#endif

--------------------------------------------------------------------------------

#ifndef Game_h

#define Game_h

#include

#include

#include

using namespace std;

class Game

{

public:

Game();

//default constructor

//Postcondition:

/*

userName = "";//variable to store the user name

totalWages = 0;//variable to store the total earning

totalCorrect = 0;//variable to store the total of correct responses

totalWrong = 0;//variable to store the total of incorrect responses

*/

void splashScreen ();

//Function to display credits and developer information.

void menu();

//Function to display the menu options and validate them.

void updateStats(bool correct);

//Function to update game statistics

//Postcondition: updates totalWages and totalCorrect and totalWrong;

void displayStats();

//Function to display player statistics

void requestName();

//Function to get userName

//This function also invokes the validate method which ensures that the userName is valid; that is, it is not numbers, blanks, non-alpha chars or a combination thereof

//Postcondition: creates a new text file if user is a first-time player or reads statistics from text file if user is a returniong player

//if the player is a "returning player", the statistics are read into: userName, totalWages, totalCorrect, and totalWrong

void saveStats();

//Function to save statistics into text file

//Postcondition:statistics saved are: userName, totalWages, totalCorrect, and totalWrong

void validate(string& str1);

//Function to validate userName

//userName is not allowed to be more than one word or numbers, blanks, non-alpha chars or a combination thereof

//Postcondition: userName is a single word made of alpha chars only

private:

string userName;//variable to store the user name

double totalWages;//variable to store the total earning

int totalCorrect;//variable to store the total of correct responses

int totalWrong;//variable to store the total of wrong responses

const double REWARD = 0.05;//constant to store 0.05 as a reward for every correct problem

const double PENALTY = 0.03;//constant to store 0.03 as a penalty for evry wrong problem

ofstream outData;//used to open file for saving stats

ifstream inData;//used to open file for retrieving stats

};

#endif

--------------------------------------------------------------------------------

#ifndef Multiplication_h

#define Multiplication_h

#include

#include

using namespace std;

class Multiplication

{

//Overload the stream insertion and extraction operators

friend ostream& operator

public:

Multiplication();

//default constructor

//Postcondition: theAnswer=0; userResponse=0;

//invokes randomize();

void randomize();

//Function to generate two random numbers between 1 and 10.

//Postcondition: num1 and num2 are equal to between 1 and 10;

//and theAnswer = num1 * num2;

bool checkAnswer();

//Function to check userAnswer with problem answer (theAnswer)

//Postcondition: if theAnswer==userResponse appropriate feedback is displayed

// returns true if user answer is correct or returns false if user answer is incorrect;

void validate(string str1);

//Function to validate user response

//Postcondition: function accepts a string, validates it to be an int;

private:

int num1;//variable to store one of the operands

int num2;//variable to store one of the operands

int theAnswer;//variable to store the answer to the problem

int userResponse;//variable to store the user response to the problem in int format

};

#endif

--------------------------------------------------------------------------------

#ifndef Subtraction_h

#define Subtraction_h

#include

#include

using namespace std;

class Subtraction

{

//Overload the stream insertion and extraction operators

friend ostream& operator

public:

Subtraction();

//default constructor

//Postcondition: theAnswer=0; userResponse=0;

//invokes randomize();

void randomize();

//Function to generate two random numbers between 1 and 10.

//Postcondition: num1 and num2 are equal to between 1 and 10;

//and theAnswer = num1 - num2;

bool checkAnswer();

//Function to check userAnswer with problem answer (theAnswer)

//Postcondition: if theAnswer==userResponse appropriate feedback is displayed

// returns true if user answer is correct or returns false if user answer is incorrect;

void validate(string str1);

//Function to validate user response

//Postcondition: function accepts a string, validates it to be an int;

private:

int num1;//variable to store one of the operands

int num2;//variable to store one of the operands

int theAnswer;//variable to store the answer to the problem

int userResponse;//variable to store the user response to the problem in int format

};

#endif

--------------------------------------------------------------------------------

image text in transcribed

image text in transcribed

Program Flow 1. At the start of the game, an initial "Splash screen must be displayed which includes: The game's title Your name a. b. TheHathGane By Prof. Flore yto continue, any other char to exit After the "Splash screen a prompt must ask the user for his/her name (validate input: no numbers, no blanks) Enter your nane and press KENTER> 2. Once you have the user's name, display a menu with the options listed in the graphic below (validate input only options 1, 2, 3, 4, 5, n and N must be allowed): 00SE A PROBLEMNMM WH 2. SUBTRACT 3. HULTIPLY 4. DIUIDE 5. STATS nN to QUIT 3. If the user chooses option 1 or 2 or 3 or 4 arandomly generated problem isdisplayed (validate input: only positive integers must be allowed): 4 + 6=? 6-3? Program Flow 1. At the start of the game, an initial "Splash screen must be displayed which includes: The game's title Your name a. b. TheHathGane By Prof. Flore yto continue, any other char to exit After the "Splash screen a prompt must ask the user for his/her name (validate input: no numbers, no blanks) Enter your nane and press KENTER> 2. Once you have the user's name, display a menu with the options listed in the graphic below (validate input only options 1, 2, 3, 4, 5, n and N must be allowed): 00SE A PROBLEMNMM WH 2. SUBTRACT 3. HULTIPLY 4. DIUIDE 5. STATS nN to QUIT 3. If the user chooses option 1 or 2 or 3 or 4 arandomly generated problem isdisplayed (validate input: only positive integers must be allowed): 4 + 6=? 6-3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions