2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > C++ 小学生计算机辅助教学系统

C++ 小学生计算机辅助教学系统

时间:2021-11-08 13:48:03

相关推荐

C++ 小学生计算机辅助教学系统

我们都知道计算机在教育中起的作用越来越大。

下面编写一个程序,帮助小学生学习乘法。利用rand函数产生两个一位的正整数。接着应该显示诸如6乘7等于多少的问题?学生然后输入答案。

程序会检查学生的答案。

计算机助教学环境中出现的一个问题是学生容易疲劳。这是可以消除的,通过变换计算机的对话来保持学生的注意力。要求对于每个正确的答案和不正确的答案,应该打印出不同的评语,如下所示:正确答案的评语:

Very good!

Excellent!

Nice work!

Keep up the good work!

错误答案的评语:

No. Please try again.

Wrong.

Try once more.

Don't give up!

No. Keep trying.

利用随机数生成器在1~4之间选择一个数,用它为每个答案选择相应的评语。使用switch语句发出响应。

先复习一下rand()函数的用法:

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,其它情况依 此类推。

/*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;}

上面的程序还是不够完善,下面增强前面的程序功能。

a)修改程序,允许用户输入能力等级。等级1表示在问题中只能使用一位数,等级2表示最大只能使用2位数,等等。

b)修改程序,增加算术问题的类型,允许用户选择他或者她希望学习的算术问题的类型。选项1表示只是加法问题,2表示只是减法问题,3表示只是乘法问题,4表示只是除法问题。

#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;}

如有疑问,欢迎在评论区留言。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。