急求!!!C++程序设计!!!!
编程序,循环进行如下的处理过程:由计算机生成简单的四则运算题;用户给出答案;计算机判断对错。直到用户回答说不再继续做了时结束程序。提示:可让用户选择指定出加、减、乘、除哪...
编程序,循环进行如下的处理过程:由计算机生成简单的四则运算题;用户给出答案;计算机判断对错。直到用户回答说不再继续做了时结束程序。提示:可让用户选择指定出加、减、乘、除哪一种运算题,以及出一位数还是两位数的运算题;而后通过使用“rand()%10”或“rand()%100”来获得一个0到9的一位整数随机值或得到0到99的两位整数随机值来为用户出题。还可进一步对用户所做算术题的对错次数进行记录,结束程序时给出一个某种形式的成绩。
界面化的 邮箱skyliuch@vip.qq.com 谢了
如果可以给我加上注释 那就更好了 展开
界面化的 邮箱skyliuch@vip.qq.com 谢了
如果可以给我加上注释 那就更好了 展开
4个回答
展开全部
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
void main()
{
int type,add,sum,mul,div,total,count,rcount,num1,num2,answer;
double score;
time_t t;
srand((unsigned int)time(&t));
cout<<"-------进入答题程序!--------\n请选择算法:1--加法,2--减法,3--乘法,4--除法,0--退出!\n";
cin>>type;
while( type>0 && type<5)
{
switch(type)
{
case 1:
rcount=0;
cout<<"你选择了加法,请选择位数:输入1或2分别代表1位,2位数运算:\n";
cin>>add;
if (1 == add)
{
cout<<"你选择了1位数加法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%10;
num2 = rand()%10;
cout<<count<<". "<<num1<<" + "<<num2<<" = ";
cin>>answer;
if( answer == (num1 + num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n";;
}
if (2 == add)
{
cout<<"你选择了2位数加法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%100;
num2 = rand()%100;
cout<<count<<". "<<num1<<" + "<<num2<<" = ";
cin>>answer;
if( answer == (num1 + num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n";
}
break;
case 2:
rcount=0;
cout<<"你选择了减法,请选择位数:输入1或2分别代表1位,2位数运算:\n";
cin>>sum;
if (1 == sum)
{
cout<<"你选择了1位数减法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%10;
num2 = rand()%10;
cout<<count<<". "<<num1<<" - "<<num2<<" = ";
cin>>answer;
if( answer == (num1 - num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n"; }
if (2 == sum)
{
cout<<"你选择了2位数减法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%100;
num2 = rand()%100;
cout<<count<<". "<<num1<<" - "<<num2<<" = ";
cin>>answer;
if( answer == (num1 - num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n";
}
break;
case 3:
rcount=0;
cout<<"你选择了乘法,请选择位数:输入1或2分别代表1位,2位数运算:\n";
cin>>mul;
if (1 == mul)
{
cout<<"你选择了1位数乘法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%10;
num2 = rand()%10;
cout<<count<<". "<<num1<<" * "<<num2<<" = ";
cin>>answer;
if( answer == (num1 * num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n"; }
if (2 == mul)
{
cout<<"你选择了2位数乘法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%100;
num2 = rand()%100;
cout<<count<<". "<<num1<<" * "<<num2<<" = ";
cin>>answer;
if( answer == (num1 * num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n";
}
break;
case 4:
rcount=0;
cout<<"你选择了除法,请选择位数:输入1或2分别代表1位,2位数运算:\n";
cin>>div;
if (1 == div)
{
cout<<"你选择了1位数除法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%10;
num2 = rand()%10;
if (0 == num2)
{
count--;
continue;
}
cout<<count<<". "<<num1<<" / "<<num2<<" = ";
cin>>answer;
if( answer == (num1 / num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n";}
if (2 == div)
{
cout<<"你选择了2位数除法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%100;
num2 = rand()%100;
cout<<count<<". "<<num1<<" / "<<num2<<" = ";
cin>>answer;
if( answer == (num1 / num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n";
}
break;
default: break;
}
cout<<"--------继续答题吗?--------\n请选择算法:1--加法,2--减法,3--乘法,4--除法,0--退出!\n";
cin>>type;
}
}
#include <stdlib.h>
#include <time.h>
void main()
{
int type,add,sum,mul,div,total,count,rcount,num1,num2,answer;
double score;
time_t t;
srand((unsigned int)time(&t));
cout<<"-------进入答题程序!--------\n请选择算法:1--加法,2--减法,3--乘法,4--除法,0--退出!\n";
cin>>type;
while( type>0 && type<5)
{
switch(type)
{
case 1:
rcount=0;
cout<<"你选择了加法,请选择位数:输入1或2分别代表1位,2位数运算:\n";
cin>>add;
if (1 == add)
{
cout<<"你选择了1位数加法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%10;
num2 = rand()%10;
cout<<count<<". "<<num1<<" + "<<num2<<" = ";
cin>>answer;
if( answer == (num1 + num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n";;
}
if (2 == add)
{
cout<<"你选择了2位数加法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%100;
num2 = rand()%100;
cout<<count<<". "<<num1<<" + "<<num2<<" = ";
cin>>answer;
if( answer == (num1 + num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n";
}
break;
case 2:
rcount=0;
cout<<"你选择了减法,请选择位数:输入1或2分别代表1位,2位数运算:\n";
cin>>sum;
if (1 == sum)
{
cout<<"你选择了1位数减法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%10;
num2 = rand()%10;
cout<<count<<". "<<num1<<" - "<<num2<<" = ";
cin>>answer;
if( answer == (num1 - num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n"; }
if (2 == sum)
{
cout<<"你选择了2位数减法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%100;
num2 = rand()%100;
cout<<count<<". "<<num1<<" - "<<num2<<" = ";
cin>>answer;
if( answer == (num1 - num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n";
}
break;
case 3:
rcount=0;
cout<<"你选择了乘法,请选择位数:输入1或2分别代表1位,2位数运算:\n";
cin>>mul;
if (1 == mul)
{
cout<<"你选择了1位数乘法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%10;
num2 = rand()%10;
cout<<count<<". "<<num1<<" * "<<num2<<" = ";
cin>>answer;
if( answer == (num1 * num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n"; }
if (2 == mul)
{
cout<<"你选择了2位数乘法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%100;
num2 = rand()%100;
cout<<count<<". "<<num1<<" * "<<num2<<" = ";
cin>>answer;
if( answer == (num1 * num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n";
}
break;
case 4:
rcount=0;
cout<<"你选择了除法,请选择位数:输入1或2分别代表1位,2位数运算:\n";
cin>>div;
if (1 == div)
{
cout<<"你选择了1位数除法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%10;
num2 = rand()%10;
if (0 == num2)
{
count--;
continue;
}
cout<<count<<". "<<num1<<" / "<<num2<<" = ";
cin>>answer;
if( answer == (num1 / num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n";}
if (2 == div)
{
cout<<"你选择了2位数除法,请输入欲做的题数:\n";
cin>>total;
for(count=1; count<=total; count++)
{
num1 = rand()%100;
num2 = rand()%100;
cout<<count<<". "<<num1<<" / "<<num2<<" = ";
cin>>answer;
if( answer == (num1 / num2) )
{
rcount++;
}
}
score = (1.0*rcount/total)*100;
cout<<"\n答题结果如下:\n答对题数: "<<rcount<<"\n"<<"得分:"<<score<<"\n\n";
}
break;
default: break;
}
cout<<"--------继续答题吗?--------\n请选择算法:1--加法,2--减法,3--乘法,4--除法,0--退出!\n";
cin>>type;
}
}
展开全部
这个代码事比较简单的,你给我留个邮箱,晚上我帮你写一个吧!还有就是要界面化的还是DOS环境的啊?给我百度hi留言吧!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我有DOS的代码!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询