#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
class Arith{
private:
int right,wrong;
int num;
public:
Arith(){
right=0;wrong=0;num=0;}
void setNum();
int getNum()const{return num;}
void doing();
void statistics();
};
void Arith::setNum(){
cout<<"输入答题数目:";
int number;
cin>>number;
num=number;
printf("你已确定答题数目,请选择答题选项.\n");
system("pause");
}
void Arith::doing(){
int i;
int num1,num2,middle,result;
char symbol;
system("cls");
for(i=1;i<=num;i++){
cout<<"答题数:"<<i-1;
cout<<"
正确次数:"<<right<<"
错误次数:"<<wrong<<endl;
cout<<"第"<<i<<"题:"<<endl;
srand(time(NULL));
num1=rand()%9;
num2=rand()%9;
middle=rand()%3+1;
switch(middle){
case 1:symbol='+';
cout<<num1<<symbol<<num2<<"=";
cin>>result;
if(result==num1+num2)
right++;
while(result!=num1+num2){
cout<<"答案错误!重新输入:\n";
wrong++;
cout<<num1<<symbol<<num2<<"=";
cin>>result;
}
break;
case 2:symbol='-';
while(num1<num2){
num1=rand()%9;
num2=rand()%9;
}
cout<<num1<<symbol<<num2<<"=";
cin>>result;
if(result==num1-num2)
right++;
while(result!=num1-num2){
cout<<"答案错误!重新输入:\n";
wrong++;
cout<<num1<<symbol<<num2<<"=";
cin>>result;
}
break;
case 3:symbol='*';
cout<<num1<<symbol<<num2<<"=";
cin>>result;
if(result==num1*num2)
right++;
while(result!=num1*num2){
cout<<"答案错误!重新输入:\n";
wrong++;
cout<<num1<<symbol<<num2<<"=";
cin>>result;
}
}
}
cout<<"答题数:"<<i-1;
cout<<"
正确次数:"<<right<<"
错误次数:"<<wrong<<endl;
cout<<"你已做完所有题目,查看做题情况进入统计选项\n";
system("pause");
}
void Arith::statistics(){
float rate;
if(num==0){
cout<<"你还没有做题呢.\n";
goto end;
}
system("cls");
cout<<"\n\n\n";
cout<<"\t\t------------------------------------\n";
cout<<"\t\t-
你一共做了"<<num<<"道题目
-
\n";
cout<<"\t\t-
正确次数为:"<<right<<"
-
\n";
cout<<"\t\t-
错误次数为:"<<wrong<<"
-
\n";
cout<<"\t\t------------------------------------\n";
rate=float(right)/float(num);
//重做的累加正确数目
switch(int(rate*10)){
case 0:
case 1:
case 2:
case 3:case 4:cout<<"\t\t看样子你得努力了,哎!\n";break;
case 5:cout<<"\t\t加油,差一点点就及格了!\n";break;
case 6:
case 7:cout<<"\t\t还行,不过要想考高分就得继续加油.\n";break;
case 8:cout<<"\t\t儒子可教也!\n";break;
case 9:
case 10:cout<<"\t\t非常之好,继续努力吧!\n";
}
end:;
system("pause");
}
void menu(){
cout<<endl;
cout<<endl;
cout<<"\t\t--------------------------------------\n";
cout<<"\t\t-
1.选择答题数目
-\n";
cout<<"\t\t-
2.开始答题
-\n";
cout<<"\t\t-
3.统计答题结果
- \n";
cout<<"\t\t-
4.退出
- \n";
cout<<"\t\t--------------------------------------\n";
}
int main(){
Arith doWork;
int choice;
while(1){
system("cls");
menu();
cout<<"你选择(1-4):";
cin>>choice;
switch(choice){
case 1:doWork.setNum();
break;
case 2:if(0==doWork.getNum()){
doWork.setNum();
}
doWork.doing();
break;
case 3:doWork.statistics();
break;
case 4:goto end;
default:
cout<<"选择错误,重新输入.\n";
system("pause");
}
}
end:;
cout<<"谢谢使用,再见!\n";
return 0;
}