Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include \"stdafx.h\" #include <iostream> #include <cstdlib> #include <iomanip>

ID: 3859659 • Letter: #

Question

#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main()
{
   //declare variables
   const int MAX_RANGE = 100;
   int randomNumber1, randomNumber2;
   double result;
   int choice;
   int answer;
   bool selection = true;

   //continue loop till user quits
   do
   {
       unsigned seed = time(0);
       srand(seed);
       //generate random numbers
       randomNumber1 = 1 + rand() % MAX_RANGE;
       randomNumber2 = 1 + rand() % MAX_RANGE;

       //menu
       cout << "----MENU---- " << "1. Addition " << "2. Subtraction " << "3. Multiplication " << "4. Division " << "5. QUIT ";
       cout << "Enter your choice (1/2/3/4/5)";
       cin >> choice;

       switch (choice)
       {
       case 1:
           cout << "Addition" << endl;
           cout << setw(5) << randomNumber1 << endl;
           cout << "+" << setw(3) << randomNumber2 << endl;
           cout << "----" << endl;
           result = randomNumber1 + randomNumber2;
           break;
       case 2:
           cout << "Subtraction" << endl;
           cout << setw(5) << randomNumber1 << endl;
           cout << "-" << setw(3) << randomNumber2;
           cout << "----" << endl;
           result = randomNumber1 - randomNumber2;
           break;
       case 3:
           cout << "Multiplication" << endl;
           cout << setw(5) << randomNumber1 << endl;
           cout << "*" << setw(3) << randomNumber2;
           cout << "----" << endl;
           result = randomNumber1 - randomNumber2;
           break;
       case 4:
           cout << "Division" << endl;
           cout << setw(5) << randomNumber1 << endl;
           cout << "/" << setw(3) << randomNumber2;
           cout << "----" << endl;
           result = randomNumber1 - randomNumber2;
           break;
           //Quit
       case 5:
           system("pause");
           exit(0);
       default:
           cout << "Enter a choice from the menu (1/2/3/4/5)" << endl;
           selection = false;
       }
       if (selection)
       {
           cout << "Enter your answer.";
           cin >> answer;
           if (answer == result)
               cout << "Good Job! Your answer is correct!" << endl;
       }
       else {
           cout << "Sorry, your answer is wrong. Thecorrect answer is: " << setw(3) << result << endl;
       }
       selection = true;
       cout << endl;
   } while (selection);
   system("pause");
   return 0;
}

Extend the C++ math program above so it includes the following:

-Gives instructions

-Displays previous user’s name and score from file

-Prompts for the current user’s name

-Provides a menu of math choices (e.g., +. -, *, /), plus exit

-Asks users how many questions they want to answer

-Asks user for highest number to use

-Displays appropriate math questions with random numbers

-Keeps track of right and wrong answers

-Provide at least 10 randomly chosen correct and incorrect answers for feedback

-Gives feedback on how many questions answered and percent right for that group

-Returns to menu for possible additional problems

-When exit chosen shows grand total statistics – correct, attempted, and percent right

-Writes name and results to file

-When running again displays name and results of last person to use the program

-Break program into appropriate functions

-Write and use data validation functions in a private library of your creation that includes generic functions for getString, getInt, and getFloat.

#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main()
{
   //declare variables
   const int MAX_RANGE = 100;
   int randomNumber1, randomNumber2;
   double result;
   int choice;
   int answer;
   bool selection = true;

   //continue loop till user quits
   do
   {
       unsigned seed = time(0);
       srand(seed);
       //generate random numbers
       randomNumber1 = 1 + rand() % MAX_RANGE;
       randomNumber2 = 1 + rand() % MAX_RANGE;

       //menu
       cout << "----MENU---- " << "1. Addition " << "2. Subtraction " << "3. Multiplication " << "4. Division " << "5. QUIT ";
       cout << "Enter your choice (1/2/3/4/5)";
       cin >> choice;

       switch (choice)
       {
       case 1:
           cout << "Addition" << endl;
           cout << setw(5) << randomNumber1 << endl;
           cout << "+" << setw(3) << randomNumber2 << endl;
           cout << "----" << endl;
           result = randomNumber1 + randomNumber2;
           break;
       case 2:
           cout << "Subtraction" << endl;
           cout << setw(5) << randomNumber1 << endl;
           cout << "-" << setw(3) << randomNumber2;
           cout << "----" << endl;
           result = randomNumber1 - randomNumber2;
           break;
       case 3:
           cout << "Multiplication" << endl;
           cout << setw(5) << randomNumber1 << endl;
           cout << "*" << setw(3) << randomNumber2;
           cout << "----" << endl;
           result = randomNumber1 - randomNumber2;
           break;
       case 4:
           cout << "Division" << endl;
           cout << setw(5) << randomNumber1 << endl;
           cout << "/" << setw(3) << randomNumber2;
           cout << "----" << endl;
           result = randomNumber1 - randomNumber2;
           break;
           //Quit
       case 5:
           system("pause");
           exit(0);
       default:
           cout << "Enter a choice from the menu (1/2/3/4/5)" << endl;
           selection = false;
       }
       if (selection)
       {
           cout << "Enter your answer.";
           cin >> answer;
           if (answer == result)
               cout << "Good Job! Your answer is correct!" << endl;
       }
       else {
           cout << "Sorry, your answer is wrong. Thecorrect answer is: " << setw(3) << result << endl;
       }
       selection = true;
       cout << endl;
   } while (selection);
   system("pause");
   return 0;
}

Extend the C++ math program above so it includes the following:

-Gives instructions

-Displays previous user’s name and score from file

-Prompts for the current user’s name

-Provides a menu of math choices (e.g., +. -, *, /), plus exit

-Asks users how many questions they want to answer

-Asks user for highest number to use

-Displays appropriate math questions with random numbers

-Keeps track of right and wrong answers

-Provide at least 10 randomly chosen correct and incorrect answers for feedback

-Gives feedback on how many questions answered and percent right for that group

-Returns to menu for possible additional problems

-When exit chosen shows grand total statistics – correct, attempted, and percent right

-Writes name and results to file

-When running again displays name and results of last person to use the program

-Break program into appropriate functions

-Write and use data validation functions in a private library of your creation that includes generic functions for getString, getInt, and getFloat.

Explanation / Answer

Answer:

In order to include the given points in your program do as below:

i. Gives Instructions:

include an output statement before those statements where input from the user is being asked. For example,

cou<<"Please select from the below menu the operation you want to perform ";

cout << "----MENU---- " << "1. Addition " << "2. Subtraction " << "3. Multiplication " << "4. Division " << "5. QUIT ";

ii. Displays previous user’s name and score from file

include the below statements:

int score = 0; //this will in the initialization section

char name[20];

cout<<"Enter you name::";

cin>>name;

if (answer == result){

score ++;
               cout << "Good Job! Your answer is correct!" << endl;
       }

//before moving to the next user

cout<<name<<" your score is "<<score<<". ";

iii. Prompts for the current user’s name:

inclued the below statements in the code:

char cur_name[20];

cout<<"Enter your name::";

cin>>cur_name;

iv. Provides a menu of math choices (e.g., +. -, *, /), plus exit

include the below statements:

char choice;

cout << "----MENU---- " << "1. Addition " << "2. Subtraction " << "3. Multiplication " << "4. Division " << "5. QUIT ";
cout << "Enter your choice (+, -, *, / or q)";
cin >> choice;

//in switch

case '+' :

case '-' :

//and so on

v. Asks users how many questions they want to answer

int num_qn;

cout<<" Enter the number of questions you want to answer::";

cin>>num_qn;

//run the do-while loop for num_qn times