Revise your program to test arithmetic skills of children so that it uses file i
ID: 3638188 • Letter: R
Question
Revise your program to test arithmetic skills of children so that it uses file input and functions. The program will ask the student to solve a set of arithmetic problems. The problems will be contained in a file. The last line of the file will be0 0 0
and will signal that there are no more problems to be worked.
For each problem, the program will read the question from the file, display it on the terminal, and expect the student to enter the answer. If the answer is correct, it will randomly display (on the terminal) one of the following messages: “Nice Job!”, “Congratulations! Your answer is correct.” and “Yes! You are right!”. It will then write to an output file the problem number (1,2,3,…), the problem, whether or not the student got the correct answer, and the number of attempts the student made. Then it will get the next problem from the file. However, if the answer is not correct, the program will display “Sorry, wrong answer. Please try to enter the correct answer again:”, and read the answer and check again, until the correct answer is entered. (You can limit the number of attempts to 5 if you choose).
When all problems have been entered, the program should write to the file the number of problems, the number the student eventually got correct, and the average number of tries.
The arithmetic problems will look like the following:
99 + 55 = ?
33 - 11 = ?
43 * 23 = ?
71 / 12 = ?
Basically, each problem consists of two integer operands and one operator, all of the problems will be in the input file. The operands should be between 10-99. The student is expected to perform a floating point calculation, so you will need to do some type conversion. As long as the answer is correct to at least two digits after the decimal point, it is counted as a correct one. For example, 11/33 = 0.333333.... In such a case, 0.33 or 0.331 or 0.335 will be counted as a correct answer but 0.34 is not.
Your program should use the following functions:
findanswer(number1, number2, operator): calculates the correct answer to a given problem
check (answer1, answer2): decides if the student entered the correct answer
printmessage( goodanswer): if the answer is correct, randomly choose one of the positive messages; if the answer is incorrect, print the appropriate message
example input file:
99 55 +
33 11 -
43 23 *
71 12 /
0 0 0
Example output file:
arithmetic practice
problem # op1 operator op2 correct? # attempts
1 99 + 55 yes 1
2 33 - 11 yes 1
3 43 * 23 yes 2
4 71 / 12 no 5
#attempted #correct average # tries
4 3 2.25
Explanation / Answer
#include #include #include #include #include using namespace std; double findanswer(int,int,char); bool check(double,double); void printmessage(bool); int main() { ifstream in; ofstream out; char filename[80]; int num1,num2,tries,problems=0,totaltries=0,gotright=0; bool good; char op; double correct,user; srand(time(0)); coutfilename; in.open(filename); if(in.fail()) { coutnum2>>op; correct=findanswer(num1,num2,op); tries=0; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.