码迷,mamicode.com
首页 > 其他好文 > 详细

个人项目:二柱子加强版

时间:2018-10-31 22:13:01      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:ase   要求   记录   time   if语句   code   inf   题目   col   

要求:

1.实现在线答题;

2.答题结束后,可以判断对错;

3.将错的题保存起来;

#include<iostream>
#include<stdarg.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
using namespace std;
int main()
{
cout<<endl;
cout<<"欢迎来到小学生四则运算在线答题系统"<<endl;
cout<<endl;
cout<<endl;
Again:
double Q1=1;
int Q01;
int Q2=1;
int Q3=100;
char Q4=y;
int Q5=1;
char Q6=n;
char Q7=n;
double ans=0;
int right=0;
cout<<" 输入题目数量:";
cin>>Q1;
Q01=floor(Q1);
while(1)
{
cout<<" 减法中需要有负数吗?需要: 1;不需要:2";
cin>>Q7;
cout<<"-------------------------------------------------------------------------"<<endl;
cout<<"开始进行答题:"<<endl;
srand(time(NULL));
if(Q4==y)
{
while(1)
{
if(Q1<1)
{
cout<<"输入有误,请重新输入题目数量:";
cin>>Q1;
Q01=floor(Q1);
}
else
{
for(int j=0;j<Q01;j++)
{
if(j!=0&&j%Q2==0)
{
for(int i=0;i<Q5;i++)
{
cout<<endl;
} 
}
int num1=rand()%Q3;
int num2=rand()%Q3;
int sign=rand()%4;
switch(sign)
{
case 0:
cout<<j+1<<":"<<" "<<num1<<"+"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1+num2)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"答错了!"<<endl;
cout<<"正确答案是:"<<num1+num2<<endl;
}
break;
case 1:
if(Q7==y)
{
cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1-num2)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"答错了!"<<endl;
cout<<"正确答案是:"<<num1-num2<<endl;
}
}
else
{
if(num1>num2)
{
cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1-num2)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"答错了!"<<endl;
cout<<"正确答案是:"<<num1-num2<<endl;
}
}
else
{
cout<<j+1<<":"<<" "<<num2<<"-"<<num1<<"="<<"\t";
cin>>ans;
if(ans==num2-num1)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"答错了!"<<endl;
cout<<"正确答案是:"<<num2-num1<<endl;
}
}
}
break;
case 2:
cout<<j+1<<":"<<" "<<num1<<"*"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1*num2)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"答错了!"<<endl;
cout<<"正确答案是:"<<num1*num2<<endl;
}
break;
case 3:
if(num2!=0)
{
cout<<j+1<<":"<<" "<<num1<<"/"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1/num2)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"答错了!"<<endl;
cout<<"正确答案是:"<<num1/num2<<endl;
}
}
else
{
j--;
}
break;
}
}
break;
}
}
cout<<"共答对"<<right<<"道题;"<<"答错"<<Q01-right<<"道题。";
break;
}
if(Q4==n)
{
while(1)
{
if(Q01<1)
{
cout<<"输入有误,请重新输入题目数量:";
cin>>Q1;
Q01=floor(Q1);
}
else
{
for(int j=0;j<Q01;j++)
{
if(j!=0&&j%Q2==0)
{
for(int i=0;i<=Q5;i++)
{
cout<<endl;
}
}
int num1=rand()%Q3;
int num2=rand()%Q3;
int sign=rand()%2;
switch(sign)
{
case 0:
cout<<j+1<<":"<<" "<<num1<<"+"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1+num2)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"答错了!"<<endl;
cout<<"正确答案是:"<<num1+num2<<endl;
}
break;
case 1:
if(Q7==y)
{
cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1-num2)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"答错了!"<<endl;
cout<<"正确答案是:"<<num1-num2<<endl;
}
break;
}
else
{
if(num1>num2)
{
cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1-num2)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"答错了!"<<endl;
cout<<"正确答案是:"<<num1-num2<<endl;
}
break;
}
else
{
cout<<j+1<<":"<<" "<<num2<<"-"<<num1<<"="<<"\t";
cin>>ans;
if(ans==num2-num1)
{
cout<<"正确";
}
else
{
cout<<"答错了!"<<endl;
cout<<"正确答案是:"<<num2-num1<<endl;
}
break;
}
}
break;
}
}
}
break;
}
cout<<"共答对"<<right<<"道题;"<<"答错"<<Q01-right<<"道题。"<<endl;
break;
}
else
{
cout<<"输入有误,请按要求输入!"<<endl;
}
}
cout<<endl;
while(1)
{
cout<<"是否继续?(y:继续;n:退出)";
cin>>Q6;
if(Q6==y)
{
goto Again;
}
if(Q6==n)
{
goto Exit;
}
else
{
cout<<"输入有误,请重新输入:";
}
}
Exit:
return 0;
}

技术分享图片

个人总结:这次编程难度较大,主要学习到了if语句的多重利用,如何记录错题,确实想不到有效的解决方法。

个人项目:二柱子加强版

标签:ase   要求   记录   time   if语句   code   inf   题目   col   

原文地址:https://www.cnblogs.com/xuzhengdong/p/9886177.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!