Question
In this exercise we will write a simple application for practicing basic arithmetic operations (addition and subtraction). Question 1 (20%) Write a class namedExercise. The
In this exercise we will write a simple application for practicing basic arithmetic operations (addition and subtraction).
Question 1 (20%)
Write a class namedExercise. The class will represent an arithmetic exercise. The class will contain the following privacy features:
leftOperandof int, represents the first (left) argument in the arithmetic exercise.
rightOperand of int, represents the second (right) argument in the arithmetic exercise.
op of typeint, represented the operator of the exercise, where 1 represented addition and 2 represented subtraction.
maxValue of the int type, the maximum number from which the arguments in the exercise can be.
minValue of the int type, the minimum number from which can be the arguments in the exercise.
Define the builder in the department:
Exercise(int min = 0, max = 10) The constructor has created a new arithmetic exercise. The constructor will receive the ranges of numbers. If min is not less than max, the constructor is stable 0 in min and 10in max . The constructor will randomly draw numbers for both arguments, in the domain [min, max].
Add the following functions to the class:
int eval()) The function will return the result of the expression.
string toString() Returns a string containing the details of the expression. The string consists of the first argument, the operator, the second argument, and the = symbol. For example, if the first argument is 5, the second is 7, and the operator is an addition, the function returns the string:
"5 + 7 = "
Note that there is a single space after each statistic, including the '='.
Question2(60%)
Write a class named ExGeneratorto represent a pool of arithmetic exercises. The class will contain the following attributes:
exercises Exercise** attribute, representing an array of Exercise objects.
numOfEx A property of type int, will represent the amount of exercises in the array.
Current int, will save the current exercise given to the user.
Write the builder in the department
ExGenerator(int size = 10, int min = 0, max = 10) The constructor will receive as parameters the desired test size (how many exercises will be in it) and the range of numbers. By default, the size is 10. The constructor will create a size-sizedarray and fill its cells with sizeExerciseobjects according to the given domain.
Add the following functions to the class:
int getNumOfEx() const The function will return the number of exercises in the array.
int getCurrent() const The function will return the number of the current exercise.
Exercise*next() const Returns the next exercise object in the array, and advancescurrentby one. If the drills are finished, the function returnsNULL.
bool endOfEx() The function will returntrueif the exercises in the buffer are over and falseif not.
~ExGenerator() The destructorof the department, do not forget to releaseallallocated memory.
Question 3 (20%)
Write a class namedMathQuizto represent an arithmetic exercises questionnaire. You can design the class and decide on its attributes, but the class must contain the following public functions:
Constructor:
MathQuiz(int size = 10, int min = 0, int max = 10) The constructor will receive as parameters the desired test size, and the range of arguments and create a new object.
void startQuiz() The function will start the test the function will show the user the exercises one after the other. For each exercise, the function will receive the answer from the user, issuing a message whether the answer is correct or not, and moving on to the next exercise. At the end of the test, the function will notify the user that the test is over, what his final score is (calculated as the number of exercises that the user answered correctly out of the total number of exercises) and ask the user whether to save the results to a file. If the user chooses to save, The function will ask the user for the file path, create a new file calledresultsplus a random three-digit number, and save the test exercises in the following format into it each exercise will appear on a separate line. The exercise itself will appear, its correct answer and the user's answer. At the end of the file will appear a summary of how many exercises were answered correctly.
At the end of the exercise you will see an example of a possible run of the program.
Comments and guidelines
1.Pay attention to memory leaks release dynamically allocated memory.
2.Do not add public functions beyond what is given in the exercise. You are allowed to add as many private functions as you like.
3.Make sure that the format of the strings is exactly as defined in the exercise.
4.To generate random numbers, you can use the RAND() function. The function is in the cstdlib directory that needs to be done include. The function draws an integer random number between 0 and any maximum number. Note that the function selects the numbers according to a predetermined series, so if you want to generate a real random number, turn on thesrand Before calling rand. The function takes as a parameter an integer that "mixes" the series. You can see an example of how to activate the functions here -https://www.geeksforgeeks.org/rand-and-srand-in-ccpp/
Submission Guidelines
You must submit a link to the source code you wrote on the onlineGDB website. See guidelines for working with the editor on the course website.
Do not serve in pairs.
Pay attention to the exercise submission guidelines published on the course website.
Submit the assignment in the assignment system by December 31, 2022 by 23:59.
An example of a possible launch of the application
The following mainruns the program:
#include
#include "MathQuiz.h"
using namespace std;
int main() {
cout<<"Welcome to the math quiz"< cout<<"You'll get 3 exercises"< MathQuiz mq(3); mq.startQuiz(); return 0; } The output of the program (bold represents the input from the user): Welcome to the math quiz You'll get 3 exercises 3 + 4 = 7 correct 7 2 = 1 wrong 4 5 = -1 correct The quiz has ended. You got 2 correct answers out of 3. Would you like to save the results? (press y or n) y please enter file path: c:/ Your results where saved in c:/results536.txt Goodbye! Theresults536.txt file contains the following text: Results for the quiz: 3 + 4 = 7 your answer 7 7 2 = 5 your answer 1 4 5 = -1 your answer -1 You got 2 correct answers out of 3 exercises.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started