home / study / engineering / computer science / computer science questions and a
ID: 3747491 • Letter: H
Question
home / study / engineering / computer science / computer science questions and answers / c++, devcpp note: please provide the comment for each section//, i am a beginner, i need to ...
Your question has been answered
Let us know if you got a helpful answer. Rate this answer
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<cstdlib> //for random function we can use <cstdlib> or <ctime>
#include<process.h> // for exit(0) that exit the program from anywhere
using namespace std; //namespace is a declarative region that intakes a predefined library std.
int main()
{ void evaluator; //function prototype to aware the compiler that we are going to use it.
int a,b,n,z;
int correct=0; //initialises the variable correct to count the total no. of coorectly answered questions
randomize(); // function prototype awares compiler that we are going to use random() function.
cout<<"How many questions you want to generate? please write it and press enter";
cin>>n;
if(n>=0)
{ for(int i=1;i<=n;i++)
{a=random(100); // we can also use only on random statement with "a" and can left the another.
b=random(100);
cout<<a<<"+"<<b<<"="; // display a+b=
cin>>z;
evaluator();
cout<<"/n" // next question starts from next line
}
}
else
return 0; //simply termination of the program. if user enters some sentinel valuelike -1
if(n!=0) // avoid score if no question is answered.
{cout<<"*******YOUR SCORE******.";
cout<<"correct ans="<<correct<<"incorrect ans="<<n-correct<<"correct%"<<(correct*100)/n;
}
else
{ cout<<"sorry no question get answered";
exit(0); // exits the program ,it requires process.h header file.
}
return 0; // Quiz terminates after all the generated question get displayed in the normal manner.
}
void evaluator()
{ int p;
p=a+b;
if(p==z) // check that the anwer entered by person is correct or not.
correct++
}
NOTE1:Please change the settings of your Dev C++ GNU compiler to run this code.Otherwise you have to use some alternative of random() i.e. srand() {randomize seed initiator}.
or you can run it on Turbo C7 by adding .h extensions to header files and removing "using namespace std".
Note2: part 5 of this question have the same logic and code.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.