当前位置: 首页 > news >正文

四则运算1

运行代码为

#include<iostream.h>
#include<stdlib.h>
#include<time.h>
void boom()
{
float x,y;
int z,t; 
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;
cout<<"********************************"<<endl;
for(int i=0;i<n;i++)
{
z=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)
{
t=first_num;
first_num=second_num;
second_num=t;
}
x=(float)first_num/second_num;
if (fourth_num==1)
{
y=(float)third_num;
}
else if(third_num>fourth_num)
{
t=third_num;
third_num=fourth_num;
fourth_num=t;
}
y=(float)third_num/fourth_num;
z=rand()%4;
switch(z)
{
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();
int c;
cout<<"要继续答题吗?(0:继续 1:退出)"<<endl;
cin>>c;
if(c==0)
{
cout<<endl;
main();
}
else
{
cout<<endl;
return 0;
}

return 0;
}

题目要求:能随机生成30道四则运算题目

转载于:https://www.cnblogs.com/wmq123/p/10251755.html

相关文章:

  • Windows API 第15篇 GetVolumeInformation 获取磁盘卷(驱动器)信息
  • 看完这篇文章,你还觉得Python难吗?
  • 使用AIR进行移动APP开发常见功能和问题(上)
  • 应用el-tabs模拟nav menu组件
  • “ an error occurred during ssl communication”--VisualSVN
  • mybatis 动态SQL .1
  • 从零开始编写自己的C#框架(2)——开发前准备工作
  • 下列关于异常处理的描述中,错误的是()。
  • centos搭建svn 服务器 并同步到web 目录(总结)
  • windows phone 7 中怎样定义和使用资源(Resource)
  • Scrum丰田之道
  • 一步步学习微软InfoPath2010和SP2010--第十四章节--高级选项(9)--高级函数
  • vue+webpack 在引入图片以及在img引用变量名的本地图片报错
  • android选择图片或拍照图片上传到服务器(包括上传参数) (转)
  • 你应该了解的大数据10个新趋势
  • ES2017异步函数现已正式可用
  • iOS编译提示和导航提示
  • javascript面向对象之创建对象
  • Java-详解HashMap
  • Linux gpio口使用方法
  • zookeeper系列(七)实战分布式命名服务
  • 多线程事务回滚
  • 今年的LC3大会没了?
  • 日剧·日综资源集合(建议收藏)
  • 手机app有了短信验证码还有没必要有图片验证码?
  • 用jQuery怎么做到前后端分离
  • 函数计算新功能-----支持C#函数
  • ​决定德拉瓦州地区版图的关键历史事件
  • ​一帧图像的Android之旅 :应用的首个绘制请求
  • #define、const、typedef的差别
  • #LLM入门|Prompt#2.3_对查询任务进行分类|意图分析_Classification
  • (6)添加vue-cookie
  • (day6) 319. 灯泡开关
  • (DenseNet)Densely Connected Convolutional Networks--Gao Huang
  • (PyTorch)TCN和RNN/LSTM/GRU结合实现时间序列预测
  • (备忘)Java Map 遍历
  • (二)学习JVM —— 垃圾回收机制
  • (附源码)springboot 房产中介系统 毕业设计 312341
  • (附源码)ssm考生评分系统 毕业设计 071114
  • (黑客游戏)HackTheGame1.21 过关攻略
  • (接口封装)
  • (十八)devops持续集成开发——使用docker安装部署jenkins流水线服务
  • (原創) 系統分析和系統設計有什麼差別? (OO)
  • (转)linux下的时间函数使用
  • (转)原始图像数据和PDF中的图像数据
  • .NET Remoting学习笔记(三)信道
  • .net Stream篇(六)
  • .NET:自动将请求参数绑定到ASPX、ASHX和MVC(菜鸟必看)
  • .net下的富文本编辑器FCKeditor的配置方法
  • .ui文件相关
  • @configuration注解_2w字长文给你讲透了配置类为什么要添加 @Configuration注解
  • @Tag和@Operation标签失效问题。SpringDoc 2.2.0(OpenApi 3)和Spring Boot 3.1.1集成
  • [AHOI2009]中国象棋 DP,递推,组合数
  • [C/C++]数据结构----顺序表的实现(增删查改)
  • [ccc3.0][数字钥匙] UWB配置和使用(二)