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

Code in C++ Please code in more basic C++ (im still learning the basics) a) The

ID: 3730956 • Letter: C

Question

Code in C++ Please code in more basic C++ (im still learning the basics)

a) The use of computers in education is referred to as computer-assisted instruction (CAI). Write a program that will help an elementary school student learn multiplication. Use the rand function to produce two positive one-digit integers. The program should then prompt the user with a question, such as How much is 6 times 7?

The student then inputs the answer. Next, the program checks the student’s answer. If it’s correct, display the message "Very good!" and ask another multiplication question. If the answer is wrong, display the message "No. Please try again." and let the student try the same question repeatedly until the student finally gets it right. A separate function should be used to generate each new question.

This function should be called once when the application begins execution and each time the user answers the question correctly.

b) One problem in CAI environments is student fatigue. This can be reduced by varying the computer’s responses to hold the student’s attention. Modify the program of "part a" so that various comments are displayed for each answer as follows:

Possible responses to a correct answer:

Very good!

Excellent!

Nice work!

Keep up the good work!

Possible responses to an incorrect answer:

No.

Please try again.

Wrong.

Try once more.

Don't give up!

No. Keep trying.

Use random-number generation to choose a number from 1 to 4 that will be used to select one of the four appropriate responses to each correct or incorrect answer. Use a switch statement to issue the responses. Use two functions: one for responses to a correct answer and another for responses to an incorrect answer.

c) More sophisticated computer-assisted instruction systems monitor the student’s performance over a period of time. The decision to begin a new topic is often based on the student’s success with previous topics. Modify the program of "part b" to count the number of correct and incorrect responses typed by the student. After the student types 10 answers, your program should use a function to calculate the percentage that are correct. If the percentage is lower than 75%, display "Please ask your teacher for extra help.", then reset the program so another student can try it. If the percentage is 75% or higher, display "Congratulations, you are ready to go to the next level!", then reset the program so another student can try it.

d) Part c" developed a computer-assisted instruction program to help teach an elementary school student multiplication. Modify the function you create in "part a" to allow the user to enter a difficulty level. At a difficulty level of 1, the program should use only single-digit numbers in the problems; at a difficulty level of 2, numbers as large as two digits, and so on.

e) Modify the program of "part d" to allow the user to pick a type of arithmetic problem to study. An option of 1 means addition problems only, 2 means subtraction problems only, 3 means multiplication problems only, 4 means division problems only and 5 means a random mixture of all these types.

Explanation / Answer

PART A:

#include<iostream>
#include<string>
#include<stdlib.h>
#include<time.h>
#define mp make_pair
#define pi pair<int,int>
using namespace std;

pi que()
{
int a=rand()%10; //random no between 0 and 9
int b=rand()%10;
pi p=mp(a,b);
return p;
}
string message(int ans,int exp)
{
string s;
if(ans==exp)
s="Very Good";
else
s="No,please try again";
return s;
}
int main()
{
srand(time(NULL));
bool correct;
pi p=que();
//continue to ask questions infinitely
while(true)
{
int exp=p.first*p.second; //expected answer

cout<<"How much is "<<p.first<<" times "<<p.second<<"? ";

int ans;
cin>>ans;
cout<<message(ans,exp)<<endl;
if(ans==exp)
correct=true;
else
correct=false;

//if answer is correct generate a new question
if(correct)
p=que();
}
}

PART B:

Just replace the message() function in part A by:

string message(int ans,int exp)
{
string s;
if(ans==exp)
{
int r=rand()%4+1; //random no between 1 and 4
switch(r)
{
case 1: s="Very good!"; break;
case 2: s="Excellent!"; break;
case 3: s="Nice Work!"; break;
case 4: s="Keep up the good work!"; break;
}
}
else
{
int r=rand()%6+1; //random no between 1 and 6
switch(r)
{
case 1: s="No"; break;
case 2: s="Please try again"; break;
case 3: s="Wrong"; break;
case 4: s="Try once more"; break;
case 5: s="Don't give up!"; break;
case 6: s="No. Keep trying"; break;
}
}
return s;
}

PART C:

Add a new function result() and change the main() function:

#include<iostream>
#include<string>
#include<stdlib.h>
#include<time.h>
#define mp make_pair
#define pi pair<int,int>
using namespace std;

pi que()
{
int a=rand()%10; //random no between 0 and 9
int b=rand()%10;
pi p=mp(a,b);
return p;
}
string message(int ans,int exp)
{
string s;
if(ans==exp)
{
int r=rand()%4+1; //random no between 1 and 4
switch(r)
{
case 1: s="Very good!"; break;
case 2: s="Excellent!"; break;
case 3: s="Nice Work!"; break;
case 4: s="Keep up the good work!"; break;
}
}
else
{
int r=rand()%6+1; //random no between 1 and 6
switch(r)
{
case 1: s="No"; break;
case 2: s="Please try again"; break;
case 3: s="Wrong"; break;
case 4: s="Try once more"; break;
case 5: s="Don't give up!"; break;
case 6: s="No. Keep trying"; break;
}
}
return s;
}
string result(int cnt,int tot)
{
double per=(double)cnt/tot*100;
if(per>=75)
return "Congratulations, you are ready to go to the next level! ";
else
return "Please ask your teacher for extra help. ";
}
int main()
{
srand(time(NULL));
bool correct;
//continue to ask questions for every students
while(true)
{
cout<<"Welcome New student to the portal ";
//ask 10 questions to each student
pi p=que();
int cont_cor=0; //count for correct answers
for(int i=1;i<=10;i++)
{
int exp=p.first*p.second; //expected answer

cout<<"How much is "<<p.first<<" times "<<p.second<<"? ";

int ans;
cin>>ans;
cout<<message(ans,exp)<<endl;
if(ans==exp)
correct=true;
else
correct=false;

//if answer is correct generate a new question and increment count of correct answers
if(correct)
{
cont_cor++;
p=que();
}
}
//print result for each student
cout<<result(cont_cor,10)<<endl;
}
}

PART D:

Update the que() function and change the main() function accordingly. Don't forget to include "math.h":

#include<iostream>
#include<string>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define mp make_pair
#define pi pair<int,int>
using namespace std;

pi que(int d)
{
//d=1, digits=10 (one digt)
//d=2, digits=100 (upto two digit)
//d=3, digits=1000 (upto three digit) and so on......
int digits=pow(10,d);
int a=rand()%digits;
int b=rand()%digits;
pi p=mp(a,b);
return p;
}
string message(int ans,int exp)
{
string s;
if(ans==exp)
{
int r=rand()%4+1; //random no between 1 and 4
switch(r)
{
case 1: s="Very good!"; break;
case 2: s="Excellent!"; break;
case 3: s="Nice Work!"; break;
case 4: s="Keep up the good work!"; break;
}
}
else
{
int r=rand()%6+1; //random no between 1 and 6
switch(r)
{
case 1: s="No"; break;
case 2: s="Please try again"; break;
case 3: s="Wrong"; break;
case 4: s="Try once more"; break;
case 5: s="Don't give up!"; break;
case 6: s="No. Keep trying"; break;
}
}
return s;
}
string result(int cnt,int tot)
{
double per=(double)cnt/tot*100;
if(per>=75)
return "Congratulations, you are ready to go to the next level! ";
else
return "Please ask your teacher for extra help. ";
}
int main()
{
srand(time(NULL));
bool correct;

//continue to ask questions for every students
while(true)
{
cout<<"Welcome New student to the portal ";
cout<<"Enter the difficulty level of the questions (1 to 9) that you want to be asked ";
int d;
cin>>d;
if(d<1 || d>9)
{
cout<<"Enter difficulty level in range 1 to 9 ";
continue;
}
//pass the difficulty level to que()
pi p=que(d);
//ask 10 questions to each student
int cont_cor=0; //count for correct answers
for(int i=1;i<=10;i++)
{
int exp=p.first*p.second; //expected answer

cout<<"How much is "<<p.first<<" times "<<p.second<<"? ";

int ans;
cin>>ans;
cout<<message(ans,exp)<<endl;
if(ans==exp)
correct=true;
else
correct=false;

//if answer is correct generate a new question and increment count of correct answers
if(correct)
{
cont_cor++;
p=que(d);
}
}
//print result for each student
cout<<result(cont_cor,10)<<endl;
}
}

PART E:

change main() function:

#include<iostream>
#include<string>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define mp make_pair
#define pi pair<int,int>
using namespace std;

pi que(int d)
{
//d=1, digits=10 (one digt)
//d=2, digits=100 (upto two digit)
//d=3, digits=1000 (upto three digit) and so on......

int digits=pow(10,d);
int a=rand()%digits;
int b=rand()%digits;
pi p=mp(a,b);

return p;
}
string message(double ans,double exp)
{
string s;
if(ans==exp)
{
int r=rand()%4+1; //random no between 1 and 4
switch(r)
{
case 1: s="Very good!"; break;
case 2: s="Excellent!"; break;
case 3: s="Nice Work!"; break;
case 4: s="Keep up the good work!"; break;
}
}
else
{
int r=rand()%6+1; //random no between 1 and 6
switch(r)
{
case 1: s="No"; break;
case 2: s="Please try again"; break;
case 3: s="Wrong"; break;
case 4: s="Try once more"; break;
case 5: s="Don't give up!"; break;
case 6: s="No. Keep trying"; break;
}
}
return s;
}
string result(int cnt,int tot)
{
double per=(double)cnt/tot*100;
if(per>=75)
return "Congratulations, you are ready to go to the next level! ";
else
return "Please ask your teacher for extra help. ";
}
int main()
{
srand(time(NULL));
bool correct;

//continue to ask questions for every students
while(true)
{
cout<<"Welcome New student to the portal ";
cout<<"Enter type of Arithmetic operations that you want to practice ";
cout<<"1. Addition ";
cout<<"2. Subtraction ";
cout<<"3. Multiplication ";
cout<<"4. Division ";
cout<<"5. Random ";
int type; cin>>type;
if(type<1 || type>5)
{
cout<<"Enter type in range 1 to 5 ";
continue;
}

cout<<"Enter the difficulty level of the questions (1 to 9) that you want to be asked ";
int d;
cin>>d;
if(d<1 || d>9)
{
cout<<"Enter difficulty level in range 1 to 9 ";
continue;
}

pi p=que(d);
//ask 10 questions to each student
int cont_cor=0; //count for correct answers
for(int i=1;i<=10;i++)
{
int t=type;
double exp; //expected answer
if(t==5)
{
t=rand()%4+1; //convert to a random question
}

switch(t)
{
case 1: cout<<"How much is " <<p.first<< " plus "<<p.second <<"? ";
exp=p.first+p.second;
break;
case 2: cout<<"How much is "<<p.first<<" minus "<<p.second<<"? ";
exp=p.first-p.second;
break;
case 3: cout<<"How much is "<<p.first<<" multiply "<<p.second<<"? ";
exp=p.first*p.second;
break;
case 4: cout<<"How much is "<<p.first<<" divide "<<p.second<<"? ";
exp=(double)p.first/p.second;
break;
}
double ans;
cin>>ans;
cout<<message(ans,exp)<<endl;
if(ans==exp)
correct=true;
else
correct=false;

//if answer is correct generate a new question and increment count of correct answers
if(correct)
{
cont_cor++;
p=que(d);
}
}
//print result for each student
cout<<result(cont_cor,10)<<endl;
}
}

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