Question
c++ A Tutorial Program for Basic Math We need a program that can be used by elementary school students to practice and improve their basic
c++ A Tutorial Program for Basic Math We need a program that can be used by elementary school students to practice and improve their basic arithmetic skills in addition, subtraction, and multiplication. The purpose of the program is to display a randomly generated arithmetic problem and ask the student to enter the answer. The program should check the students answer and output an appropriate message. Each time the program is run, a different problem should be displayed. The program will implement the following algorithm. 1. Generate two random numbers in the range 1-20 inclusive and save them in variables num1 and num2. 2. Make sure num1 is greater than num2. If num1 is less than num2, then initialize num1 to 20. 3. Display a problem for addition, subtraction, or multiplication as follows: generate a random number r between 0 and 2 inclusive. If r is equal to 0, display the problem num1 + num2 = Then, compute the correct answer and save it in a variable called correctAnswer. If r is equal to 1, display the subtraction problem num1 num2 = and compute the correct answer. If r is equal to 2, repeat the same for multiplication. 4. Input the studentAnswer. If the studentAnswer is equal to the correctAnswer, display an encouraging message; otherwise, display another message and show the student the correctAnswer. Sample session for several runs $ ./a.out 18 x 5 = 80 students answer Sorry, the correct answer is 90 $ ./a.out 9 + 7 = 16 Correct, well done! $ ./a.out 20 - 13 = 9 Sorry, the correct answer is 7 Program Outline //-------------------------------------------------------------------------------------------------------------------------- // Programmer: your name // Program: 3 // Date: // Description: This program provides tutoring for addition, subtraction and multiplication. // The program generates a random math problem using numbers in the range 1-20. //-------------------------------------------------------------------------------------------------------------------------- #include #include // for setw() #include // for rand() and srand() using namespace std; int main() { // Variable declarations for num1, num2, r, correctAnswer, studentAnswer // The srand() statement to reset the random number generator // Generate two random numbers for num1 and num2 in the range 1 to 20 inclusive. // If num1 is less than num2, change num1 to 20. // Generate a random number in the range 0 to 2 and save it in r. // If r is equal to 0 { Output an addition problem in the form num1 + num2 = Then, compute the correctAnswer. } // If r is equal to 1 { Output a subtraction problem in the form num1 - num2 = Then, compute the correctAnswer. } // If r is equal to 2, write a similar code for multiplication. // Input the students answer and save it in studentAnswer. // Check the studentAnswer and output an appropriate message (see the sample session). } Other requirements 1. You should remove the comment statements inside the main function above; they are included to help you with writing the code. NOTE: the curly braces in the if-statements that check the value of the variable r are important. 2. Save this program in a file called prog3XX.cpp. (XX your initials) 3. Make sure you use the proper style guidelines for spacing, indentation, and use of blank lines. 4. After you run the program several times and completely verify its correctness, use the WinSCP program to transfer the source code prog3.cpp to your personal computer. 5. Upload the source code to blackboard. Optional If you wish to extend this program, you are welcome to make the following changes. 1. Display each problem using the vertical format. For example, 18 x 5 ----- 80 students answer Sorry, the correct answer is 90 9 + 7 ----- 16 Correct, well done! 2. Allow the program to also generate division problems(integer division). For example, 18 / 5 ----- 3 students answer Correct, well done!
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