小学生算数系统

来源:互联网 发布:2017手机号码采集软件 编辑:程序博客网 时间:2024/04/29 12:30
/*copyright (c) 2013,烟台大学计算机学院 *All rights reserved. *作者:赵焱 *完成日期:2013年11月18日 *版本号:v1.0*/#include <iostream>#include<ctime>#include<cstdlib>int qa(); //函数声明,完成一道题的测试并返回评判结果,正确为1,错误为0using 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;}

运行结果 :