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 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
Hint: You can create an array of characters type char in C with elements and
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
and 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 singledigit integer, that is an integer in the range
If the operator is either division or remainder, generate the second operand as a nonzero singledigit
integer, that is an integer in the range otherwise, generate the second operand as a singledigit
integer in the range
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 inputoutput:
what is
true
And another sample inputoutput:
what is
true
Lastly, one more sample inputoutput:
what is
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
Then generate the first operand.
Finally, generate the second operand.
The first approach involves using the rand from the
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
