C++ Primary School Students Computer Aided Instruction System

We all know that computers are playing an increasing role in education.

Let's write a program to help elementary school students learn multiplication. Use the rand function to generate two one-bit positive integers. It should then display a question such as what is 6 times 7? The student then enters the answer.

The program checks the student's answers.

One problem that arises in computer-assisted instruction environments is that students are prone to fatigue. This can be eliminated by changing the conversation of the computer to keep the students' attention. It is required that for each correct answer and incorrect answer, different comments should be printed, as follows: Comments for the correct answer:
Very good!

Excellent!

Nice work!
Keep up the good work!
Comments for the wrong answer:
No. Please try again.

Wrong.

Try once more.

Don't give up!

No. Keep trying.
Use a random number generator to choose a number between 1 and 4, and use it to choose a corresponding comment for each answer. Use a switch statement to emit the response.

First review the usage of the rand() function:

rand() function usage: (reproduced) 

1. rand() does not require parameters, it will return an arbitrary integer from 0 to the maximum random number, and the size of the maximum random number is usually a fixed large integer.

2. If you want to generate a random integer among 100 integers from 0 to 99, it can be expressed as: int num = rand() % 100; 

In this way, the value of num is a random number from 0 to 99.

3. If you want to generate 1~100, it is like this: int num = rand() % 100 + 1;

4. In summary, it can be expressed as: int num = rand() % n +a;

Where a is the starting value, n-1+a is the ending value, and n is the range of integers.

5. Generality: rand() % (b-a+1)+ a ; means a random integer between a~b.

6. If you want to generate decimals between 0-1, you can first obtain integers from 0-10, and then divide them by 10 to get 10 random decimals that are "random to tenths".

If you want to get a random decimal number "random to percentile", you need to get 10 integers from 0 to 100 first, and then divide them by 100, and so on for other cases.

/*
rand()函数用法:(转载) 
1、rand()不需要参数,它会返回一个从0到最大随机数的任意整数,最大随机数的大小通常是固定的一个大整数。
2、如果你要产生0~99这100个整数中的一个随机整数,可以表达为:int num = rand() % 100; 
这样,num的值就是一个0~99中的一个随机数了。
3、如果要产生1~100,则是这样:int num = rand() % 100 + 1;
4、总结来说,可以表示为:int num = rand() % n +a;
其中的a是起始值,n-1+a是终止值,n是整数的范围。
5、一般性:rand() % (b-a+1)+ a ; 就表示 a~b 之间的一个随机整数。
6、若要产生0-1之间的小数,则可以先取得0-10的整数,然后均除以10即可得到“随机到十分位”的10个随机小数。
若要得到“随机到百分位”的随机小数,则需要先得到0~100的10个整数,然后均除以100,其它情况依 此类推。
*/
#include<iostream>
#include<cmath>
#include <stdlib.h>

using namespace std;

int main()
{
	int x,y,a;  //x和y是两个随机生成的数,a为学生输入的答案 
	int sum=0;  //sum是两个数相乘的结果
	int count=0;//count为计数器 
	int right=0;//记录对的题数
	float s;    //计算正确率 
	do
	{
		count++;
		x=rand()%10;//随机数 
		y=rand()%10;
		sum=x*y;
		
		cout << x << " * " << y << " = " << endl;
		cout << "Please enter the answer :" << endl;
		cin >> a;
		if(a==sum)
		{
			right++; 
			switch(rand()%4)
			{
				case 0:	cout << "Very good!" << endl << endl;break;
				case 1:	cout << "Excellent!" << endl << endl;break;
				case 2:	cout << "Nice work!" << endl << endl;break;
				case 3:	cout << "Keep up the good work!" << endl << endl;break;
				
			}
		}
		else
		{
			switch(rand()%4)
			{	
				case 0:	cout << "No. Please try again." << endl << endl;break;
				case 1:	cout << "Wrong. Try once more." << endl << endl;break;
				case 2:	cout << "Don't give up!" << endl << endl;break;
				case 3:	cout << "No. Keep trying." << endl << endl;break;
			}
		}
		
	
	}while(count<10);
	
	s=right*1.0/count;//计算正确率 
	if(s<0.75)
	{
		cout <<"Please ask your instructor foe extra help" << endl;
	}
	return 0;
}

The above program is still not perfect enough, the function of the previous program will be enhanced below.

a) Modify the program to allow the user to input a capability level. Level 1 means only one digit can be used in the question, level 2 means a maximum of 2 digits can be used, etc.
b) Modify the program to add types of arithmetic problems, allowing the user to select the type of arithmetic problems he or she wishes to learn. Option 1 means addition problems only, 2 means subtraction problems only, 3 means multiplication problems only, and 4 means division problems only.

#include<iostream>
#include<cmath>
#include <stdlib.h>
using namespace std;

int main()
{
	int x,y,a;  //x和y是两个随机生成的数,a为学生输入的答案 
	int sum=0;  //sum是两个数相乘的结果
	int count=0;//count为计数器 
	int right=0;//记录对的题数
	float s;    //计算正确率 
	int note=0;//记录能力等级 
	int f=0;//记录用户所希望学的问题 
	cout << "Please enter your ability level, 1 or 2" << endl;
	cin >> note; 
	cout << endl;
	cout << "************" << endl;
	cout << "*1:加法问题*" << endl; 
	cout << "*2:减法问题*" << endl; 
	cout << "*3:乘法问题*" << endl;
	cout << "*4:除法问题*" << endl;
	cout << "************" << endl;
	cout << "Please enter the type of arithmetic problem you want to learn" << endl;
	cin >> f;
	do
	{
	        count++;
		if(note==1)
		{			
			x=rand()%10;//随机数 
			y=rand()%10;
		}
		else
		{
			x=rand()%20;//随机数 
			y=rand()%20;
		}
			
		if(f==1)
		{
			sum=x+y;
			cout << x << " + " << y << " = " << endl;
		}
		else if(f==2)
		{
			sum=x-y;
			cout << x << " - " << y << " = " << endl;
		}
		else if(f==3)
		{
			sum=x*y;
			cout << x << " * " << y << " = " << endl;
		}
		else if(f==4)
		{
			sum=x/y;
			cout << x << " / " << y << " = " << endl;
		}
			cout << "Please enter the answer :" << endl;
			cin >> a;
			if(a==sum)
			{
				right++; 
				switch(rand()%4)
				{
					case 0:	cout << "Very good!            " << endl << endl;break;
					case 1:	cout << "Excellent!            " << endl << endl;break;
					case 2:	cout << "Nice work!            " << endl << endl;break;
					case 3:	cout << "Keep up the good work!" << endl << endl;break;
					
				}
			}
			else
			{
				switch(rand()%4)
				{	
					case 0:	cout << "No. Please try again." << endl << endl;break;
					case 1:	cout << "Wrong. Try once more." << endl << endl;break;
					case 2:	cout << "Don't give up!       " << endl << endl;break;
					case 3:	cout << "No. Keep trying.     " << endl << endl;break;
				}
			}
					
	}while(count<10);
	
	s=right*1.0/count;//计算正确率 
	if(s<0.75)
	{
		cout <<"Please ask your instructor foe extra help !!!" << endl;
	}
	return 0;
}

 If you have any questions, please leave a message in the comment area.

 

 

Guess you like

Origin blog.csdn.net/weixin_74287172/article/details/130547947