您的位置:首页 > 其它

小学生算数能力系统

2016-06-13 20:11 190 查看
//
//  main.cpp
//  activity
//
//  Created by 徐伟 on 6/13/16.
//  Copyright © 2016 fizz. All rights reserved.
//

#include <iostream>
#include<ctime>
#include<cstdlib>
int qa(); //函数声明,完成一道题的测试并返回评判结果,正确1为,错误为0
using namespace std;
int main()
{
int sum=0;//学生得分
for(int i=0; i<10; i++)
{
cout<<"第"<<i+1<<"题:"<<endl;
sum+=qa();
cout<<endl;
}
cout<<"共答对了"<<sum<<"道题,得分"<<sum*10<<endl;
return 0;
}

int qa()
{
srand(time(0)); //初始化随机种子
int a,b,c,d,t;
a=rand()%100+1;
b=rand()%100+1;
c=rand()%4;
if(a<b&&(c==1||c==3)) //给小学生的题,减和除运算保证大减小和大除以小(额外增加的需求,并非原题中提及)
{
d=a;
a=b;
b=d;
}
if(c==3)//对于除法,调整被除数,以保证能整除(额外增加的需求,并非原题中提及)
a=(a/b)*b;
switch(c)
{
case 0:
d=a+b;
cout<<a<<"+"<<b<<"=";
break;
case 1:

d=a-b;
cout<<a<<"—"<<b<<"=";
break;
case 2:
d=a*b;
cout<<a<<"×"<<b<<"=";
break;
case 3:
d=a/b;
cout<<a<<"÷"<<b<<"=";
break;
}
cin>>t;
if(t==d)
cout<<"    right! ";
else
cout<<"    wrong! ";
return t==d;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: