Question: Write a C + + main function to accomplish the following tasks and name the source code arithmetic.cpp . Select an operator randomly from addition

Write a C++ main function to accomplish the following tasks and name the source code arithmetic.cpp.
Select an operator randomly from addition ('+'), subtraction ('-'), multiplication ('*'), division ('/'),
and remainder (1%').
Hint: You can create an array of characters (type char in C++) with elements '+','-','*','//', and
1%1. Generate a random integer to represent a valid index in this array. Retrieve the operator located
at the chosen index in the array.
Warning: To ensure accurate grading in Gradescope, save operators in the order of '+','-',''*',1/',
and 1%'. If the chosen operator differs from the grading script's expectation, you may not receive
credits for your work.
Generate the first operand as a single-digit integer, that is, an integer in the range 0,9.
If the operator is either division or remainder, generate the second operand as a non-zero single-digit
integer, that is, an integer in the range 1,9, otherwise, generate the second operand as a single-digit
integer in the range 0,9.
Perform the operation on the operands based on the chosen operator and save the result.
Prompt the user with the problem, receive a reply from the user. If the reply is correct, print "true";
otherwise, print "false".
Here is a sample input/output:
what is 7%6?1
true
And another sample input/output:
what is 19?0
true
Lastly, one more sample input/output:
what is 7%3?2
false
There are two approaches to generate a random integer in a given range. To ensure compatibility with
Gradescope, it is necessary to use the first approach. Furthermore, generate random integers in the
following order:
Choose an integer representing a valid index in the character array with elements '+?',?'?1,?3?',11,1%'.
Then generate the first operand.
Finally, generate the second operand.
The first approach involves using the rand() from the
 Write a C++ main function to accomplish the following tasks and

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!