Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program will ask the user to answer a series of arithmetic problems and report on how the user performs. You will write this program

This program will ask the user to answer a series of arithmetic problems and report on how the user performs. You will write this program in phases as specified below. Make sure that each phase works correctly and uses good style before progressing to the following phase. The purpose of this assignment is to give you lots of practice with parameter passing without making you write a huge program. For this reason you must adhere to the following structure diagram. ( The diagram wont load but the function names should be doOneSet, doOneProblem, generateOperands, calculateCorrectAnswer, checkAnswer)

Structure Diagram Notes:

The doOneProblem function does exactly one problem, not one *type* of problem! This function will perform all of the tasks involved in finishing one complete problem, including printing the problem, checking the answer, etc.

CheckAnswer is the function that writes either "correct" or "incorrect"

You will receive a 0 on this assignment if you use global variables, arrays or structs

You will lose points if the code you put in one of your functions does not correspond to the name of the function given in the structure diagram.

Do not use value returning functions in this assignment. The purpose of this assignment is to give you practice with parameter passing, including pass-by-reference, and you could miss much of this experience if you use value returning functions instead.

Definitions: As a quick review of arithmetic, make sure you are clear that the "operands" in an expression are the things that appear on either side of the operator (numbers in this case). Don't get that mixed up with the operator. The operators are +, -, and *.

This is the first part of a two part assignment. You will complete phases 1 - 3 in this assignment, and phases 4 - 6 in the next assignment. For now you should ignore the parts of the structure diagram that refer to phases 4 - 6.

Phase 1: Your main() function for phase 1 must look exactly like this:

 int main() { srand(static_cast(time(0))); doOneSet(); } 

You must write the function doOneSet which will, for now, write out 5 addition problems. All of the numbers printed should be between 0 and 100, inclusive.

The numbers that are produced for these problems must be generated randomly by the computer. The numbers in the sample output are given only as an example. Refer to lesson 7.3 for more information about generating random numbers. The numbers must be different each time you execute the program.

Phase 2: Change your doOneSet function so that instead of just writing out the problems it also allows the user to enter an answer, and then tells the user whether the answer was correct or not. Do not change your main() function.

Before you move on to phase 3, refer to the structure diagram above and make sure that you have adhered to it for all of the functions indicated there for phase 2. This will probably mean dividing your doOneSet function up into functions, if you haven't done it already.

Phase 3: Now you will change your doOneSet function so that it will work for either addition, subtraction, or multiplication. For the purposes of this assignment, a set of problems is defined to be a group of problems that are all of the same type (all addition, all subtraction, or all multiplication). After completing this phase your program will give 5 addition problems, 5 subtraction problems, and 5 multiplication problems, for a total of 15 problems. Your main() function must look exactly like this:

 int main() { srand(static_cast(time(0))); doOneSet('+'); doOneSet('-'); doOneSet('*'); } 

The parameter tells doOneSet whether to do addition, subtraction, or multiplication. Notice that there is exactly one doOneSet function definition, not three!

At this point students often have trouble writing the parameter list for doOneSet(). As a hint, remember that a parameter is simply a declaration, and that the number and type of a function's parameters must match the arguments in the function call. In other words, the parameter(s) for doOneSet() are not a problem that you need to figure out. I've already told you exactly what the parameter(s) will be by providing you with example doOneSet() function calls.

I HAVE A WORKING PROGRAM, SEE IT BELOW, WHAT I AM MISSING IS USING THE FUNCTIONS LISTED IN THE FIRST PARAGRAPH. PLEASE HELP ME WRITE OUT MY PROGRAM USING THOSE FUNCTIONS INSTEAD OF JUST USING SWITCH LIKE I AM NOW.

#include

#include

#include

#include

using namespace std;

void doOneSet(char op) {

int num1, num2, result;

int answer;

for (int i = 0; i<5; i++) {

num1 = rand() % 101;

num2 = rand() % 101;

switch (op) {

case '+':

result = num1 + num2;

cout << num1 << "+" << num2 << "=";

break;

case '-':

result = num1 - num2;

cout << num1 << "-" << num2 << "=";

break;

case '*':

result = num1 * num2;

cout << num1 << "*" << num2 << "=";

break;

}

cin >> answer;

if (answer == result) {

cout << "correct" << endl;

}

else {

cout << "incorrect" << endl;

}

}

};

int main() {

srand(static_cast(time(0)));

doOneSet('+');

doOneSet('-');

doOneSet('*');

return 0;

}

 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Develop skills for building positive relationships.

Answered: 1 week ago

Question

Describe techniques for resolving conflicts.

Answered: 1 week ago

Question

Give feedback effectively and receive it appropriately.

Answered: 1 week ago