博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
四则运算的在线答题(判断对错,记录错题)
阅读量:6152 次
发布时间:2019-06-21

本文共 1791 字,大约阅读时间需要 5 分钟。

个人项目3:可以在之前基础上实现在线答题;

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

可以将错题保存起来;

程序:

#include<iostream.h>

#include<stdlib.h>
#include<time.h>
void boom()
{
float x,y;
int a,b;
int first_num,second_num,third_num,fourth_num;
srand(time(NULL));
int n;
float k;
float d;
float daan[100];
int zq=0;
int cw=0;
cout<<"所需题数"<<endl;
cin>>n;
for(int i=0;i<n;i++)
{
a=rand()%4;
first_num=rand()%10;
second_num=rand()%10;
third_num=rand()%10;
fourth_num=rand()%10;
if (second_num==1)
{
x=(float)first_num;
}
else if(first_num>second_num)
{
b=first_num;
first_num=second_num;
second_num=b;
}
x=(float)first_num/second_num;
if (fourth_num==1)
{
y=(float)third_num;
}
else if(third_num>fourth_num)
{
b=third_num;
third_num=fourth_num;
fourth_num=b;
}
y=(float)third_num/fourth_num;
a=rand()%4;
switch(a)
{
case 0:
cout<<i+1<<"、 "<<first_num<<"/"<<second_num<<"+"<<third_num<<"/"<<fourth_num<<"="<<" ";
daan[i+1]=x+y;
break;
case 1:
cout<<i+1<<"、 "<<first_num<<"/"<<second_num<<"-"<<third_num<<"/"<<fourth_num<<"="<<" ";
daan[i+1]=x-y;
break;
case 2:
cout<<i+1<<"、 "<<first_num<<"/"<<second_num<<"*"<<third_num<<"/"<<fourth_num<<"="<<" ";
daan[i+1]=x*y;
break;
case 3:
if(y!=0)
{
cout<<i+1<<"、 "<<first_num<<"/"<<second_num<<"÷"<<third_num<<"/"<<fourth_num<<"="<<" ";
}
else
{
i=i-1;
}
daan[i+1]=(float)x/y;
break;
}
if((i+1)%3==0)
{
for(int c=0;c<=1;c++)
{
cout<<endl;
}
}
if((i+1)==n)
{
cout<<endl;
}
}
for(i=1;i<=n;i++)
{
cout<<"请答题:"<<endl;
cout<<i<<"、";
cin>>d;
if(d==daan[i])
{
cout<<"回答正确!"<<endl;
cout<<endl;
zq=zq+1;
}
else
{
cout<<"回答错误,正确答案为:"<<" "<<daan[i]<<endl;
cout<<endl;
cw=cw+1;
}
}
k=(float)zq/n;
cout<<"答对数为:"<<" "<<zq<<"个"<<endl;
cout<<"答错数为:"<<" "<<cw<<"个"<<endl;
cout<<"正确率为:"<<" "<<k<<endl;
}
int main()
{
boom();
main();
return 0;
}

运行结果:

出现的问题:

不知如何将错题保存,以及以什么形式保存。

转载于:https://www.cnblogs.com/amnavov/p/9885756.html

你可能感兴趣的文章
也问腾讯:你把用户放在什么位置?
查看>>
CSS Sprites 样式生成工具(bg2css)
查看>>
[转]如何重构代码--重构计划
查看>>
类中如何对list泛型做访问器??
查看>>
C++解析XML--使用CMarkup类解析XML
查看>>
P2P应用层组播
查看>>
Sharepoint学习笔记—修改SharePoint的Timeouts (Execution Timeout)
查看>>
CSS引入的方式有哪些? link和@import的区别?
查看>>
Redis 介绍2——常见基本类型
查看>>
asp.net开发mysql注意事项
查看>>
(转)Cortex-M3 (NXP LPC1788)之EEPROM存储器
查看>>
ubuntu set defult jdk
查看>>
[译]ECMAScript.next:TC39 2012年9月会议总结
查看>>
【Xcode】编辑与调试
查看>>
用tar和split将文件分包压缩
查看>>
[BTS] Could not find stored procedure 'mp_sap_check_tid'
查看>>
PLSQL DBMS_DDL.ALTER_COMPILE
查看>>
Activity生命周期
查看>>
高仿UC浏览器弹出菜单效果
查看>>
Ubuntu忘记密码,进不了系统的解决方法
查看>>