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

Question: C++, DEVCPP NOTE: Please provide the comment for each section//, I am

ID: 3747493 • Letter: Q

Question

Question: C++, DEVCPP NOTE: Please provide the comment for each section//, I am a beginner, I need to under...

C++, DEVCPP
NOTE: Please provide the comment for each section//, I am a beginner, I need to understand, how the program is working. Thanks.

1) Write code for a 3rd Grade math teacher program that provides simple addition questions. Use only numbers in the range 0 to 100 inclusive in the math problems. No number should exceed 100 in the questions or answers. Ask the student for how many questions to generate and provide that many questions. Use the code to generate random numbers.

2) Instead of asking for a number of questions, keep generating questions until the answer given is a sentinel value which ends the quiz. A negative number is a good sentinel because all valid answers are from 0 to 100. Do not ask: "Do you want another question? (y/n)" after each answer. This makes the quiz tedious for the user. Instead, provide a sentinel to quit. The quiz quits when the sentinel is entered.
3) Ask the user for a number of questions as in variation 1, but also allow the user to stop early as in variation 2. This provides more flexibility. The quiz quits when the total number of questions requested have been presented OR the sentinel was entered.

4) Provide a score at the end: number correct, number wrong, and percentage correct. CAUTION! Avoid divide by 0 if no questions are answered!

5)Generate addition, subtraction, multiplication, and division questions. Provide statistics on how the student did on each operation. Advise whether more study is recommended. Be very careful attempting this part. It is much more difficult to generate valid values for all 4 operations. Your program can crash if you allow divide be zero.
Provide a header comment block.
IMPORTANT! All numbers involved in the math problems should be in the range 0 - 100. This includes numbers for questions and answers. For example, if 81 / 9 is a valid question, but 56 / 13 is not, because the answer is a weird fraction – not suitable for a 3rd grader. 21 * 4 is a valid question, but 21 * 57 is not. The answers should be in the range of 0 - 100. Test your code with 5 questions and answers minimum.

Explanation / Answer

#include<iostream>

#include<time.h>

using namespace std;

int main()

{

srand(time(NULL));

int choice,op,num1,num2,result,ans= 0 ,correct =0 ,wrong=0,count=0;

//ask user how many questions he wants to generate

do

{

//generate random operation

op = rand() % 4 + 1;

//cout << "Op : " << op << endl;

//generate num1 and num2

num1 = rand() % 99 + 1;

num2 = rand() % 99 + 1;

switch (op)

{

case 1:

result = num1 + num2;

if (result > 100)

{

break;

}

else

{

cout << "Enter -1 to quit ";

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

cin >> ans;

count++;

if (ans == result)

correct++;

else

wrong++;

}

break;

case 2:

result = num1 - num2;

if (result > 100 || result < 0)

{

break;;

}

else

{

cout << "Enter -1 to quit ";

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

cin >> ans;

count++;

if (ans == result)

correct++;

else

wrong++;

}

break;

case 3:

result = num1 * num2;

if (result > 100)

{

break;

}

else

{

cout << "Enter -1 to quit ";

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

cin >> ans;

count++;

if (ans == result)

correct++;

else

wrong++;

}

break;

case 4:

if (num2 == 0)

{

break;

}

result = num1 / num2;

if (result > 100)

{

break;;

}

else

{

if (num1 % num2 != 0)

{

continue;

}

cout << "Enter -1 to quit ";

cout << num1 << " / " << num2 << " = ";

cin >> ans;

count++;

if (ans == result)

correct++;

else

wrong++;

}

break;

default:

cout << "Invalid operation" << endl;

}

if (ans == -1)

{

--wrong;

break;

}

} while (true);

cout << "Total questions: " << --count << endl;

cout << "Correct answers: " << correct << endl;

cout << "Wrong answers: " << wrong << endl;

cout << "Percentage : " << double(correct * 100.0)/count << endl;

}

/*output

Enter -1 to quit

97 - 14 = 83

Enter -1 to quit

3 + 37 = 40

Enter -1 to quit

62 + 17 = 79

Enter -1 to quit

58 - 35 = 23

Enter -1 to quit

97 - 89 = -1

Total questions: 4

Correct answers: 4

Wrong answers: 0

Percentage : 100

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote