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

[开源]C++代码分享

一,声明

        被人水平有限,开源只是为了分享。勿喷!!!还请大佬指点。

二,代码

// --------------------------------------------------------- 头文件 ----------------------------------------------- #include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
// -------------------------------------命名空间 --------------------------------------using namespace std;// -------------------------------------------------------------- 变量 ------------------------------------------------------------int Options_1; // 第一个用户选项(选择四则运算) 
int Options_2; //第二个用户选项 (选择难度) 
long long answer;//用户的答案 
long long answer_2;
long long a , b;//两个数// -------------------------------------------随机数生成 --------------------------------------------void plan_1()
{srand(static_cast<unsigned int>(time(NULL))); // 随机生成种子a = rand() % 10;b = rand() % 10;
} void plan_2()
{srand(static_cast<unsigned int>(time(NULL))); // 随机生成种子a = rand() % 100;b = rand() % 100;
}void plan_3()
{srand(static_cast<unsigned int>(time(NULL))); // 随机生成种子a = rand() % 1000;b = rand() % 1000;
}void division_1()
{srand(static_cast<unsigned int>(time(NULL))); // 随机生成种子a = rand() % 10;b = rand() % 9 + 1;//生成1到9的随机数 
} void division_2()
{srand(static_cast<unsigned int>(time(NULL))); // 随机生成种子a = rand() % 100;b = rand() % 99 + 1;//生成1到99的随机数 
}void division_3()
{srand(static_cast<unsigned int>(time(NULL))); // 随机生成种子a = rand() % 1000;b = rand() % 999 + 1;//生成1到999的随机数 
}// -------------------------------------------------------------自定义函数 ----------------------------------------------------------------void BUG()
{cout << "搁着卡BUG呢???"<< endl;cout << "搁着卡BUG呢???"<< endl;cout << "搁着卡BUG呢???"<< endl;cout << "????????????????????????" << endl;cout << "????????????????????????" << endl;cout << "????????????????????????" << endl;cout << "????????????????????????" << endl;}void screen_main()
{cout << "========== 超级无敌分级别计算训练器 ==========" << endl;cout << "1.两位数加法运算" << endl;cout << "2.两位数减法运算" << endl;cout << "3.两位数乘法运算" << endl;cout << "4.两位数除法运算" << endl;
} void screen_1()
{cout << "-------------------------------- 分级别加法计算练习器 -----------------------------------------" << endl;cout << "1.十以内的加法计算(so easy)" << endl;cout << "2.一百以内的加法计算(easy)" << endl;cout << "3.一千以内的加法计算(a little difficult)" << endl;cin >> Options_2;if(Options_2 == 1){plan_1();cout << a << "+" << b << "=?" << endl;cin >> answer;if (answer == a + b){cout << "True" << endl;}else{cout << "False" << endl;	}}if(Options_2 == 2){plan_2();cout << a << "+" << b << "=?" << endl;cin >> answer;if (answer == a + b){cout << "True" << endl;}else{cout << "False" << endl;	}}if(Options_2 == 3){plan_3();cout << a << "+" << b << "=?" << endl;cin >> answer;if (answer == a + b){cout << "True" << endl;}else{cout << "False" << endl;	}}if (Options_2 < 1 || Options_2 > 3)//错误判断 {BUG();}
}void screen_2()
{cout << "-------------------------------- 分级别减法计算练习器 -----------------------------------------" << endl;cout << "1.十以内的减法计算(so easy)" << endl;cout << "2.一百以内的减法计算(easy)" << endl;cout << "3.一千以内的减法计算(a little difficult)" << endl;cin >> Options_2;if(Options_2 == 1){plan_1();cout << a << "-" << b << "=?" << endl;cin >> answer;if (answer == a - b){cout << "True" << endl;}else{cout << "False" << endl;	}}if(Options_2 == 2){plan_2();cout << a << "-" << b << "=?" << endl;cin >> answer;if (answer == a - b){cout << "True" << endl;}else{cout << "False" << endl;	}}if(Options_2 == 3){plan_3();cout << a << "-" << b << "=?" << endl;cin >> answer;if (answer == a - b){cout << "True" << endl;}else{cout << "False" << endl;	}}if (Options_2 < 1 || Options_2 > 3)//错误判断 {BUG();}
}void screen_3()
{cout << "-------------------------------- 分级别乘法计算练习器 -----------------------------------------" << endl;cout << "1.十以内的乘法计算(so easy)" << endl;cout << "2.一百以内的乘法计算(easy)" << endl;cout << "3.一千以内的乘法计算(a little difficult)" << endl;cin >> Options_2;if(Options_2 == 1){plan_1();cout << a << "x" << b << "=?" << endl;cin >> answer;if (answer == a * b){cout << "True" << endl;}else{cout << "False" << endl;	}}if(Options_2 == 2){plan_2();cout << a << "x" << b << "=?" << endl;cin >> answer;if (answer == a * b){cout << "True" << endl;}else{cout << "False" << endl;	}}if(Options_2 == 3){plan_3();cout << a << "x" << b << "=?" << endl;cin >> answer;if (answer == a * b){cout << "True" << endl;}else{cout << "False" << endl;	}}if (Options_2 < 1 || Options_2 > 3)//错误判断 {BUG();}
}void screen_4()
{cout << "-------------------------------- 分级别除法计算练习器 -----------------------------------------" << endl;cout << "1.十以内的除法计算(so easy)" << endl;cout << "2.一百以内的除法计算(easy)" << endl;cout << "3.一千以内的除法计算(a little difficult)" << endl;cout << "请依次输入商和余数" << endl;cin >> Options_2;if(Options_2 == 1){division_1();cout << a << "/" << b << "=?" << endl;cin >> answer >> answer_2;if (answer == a / b && answer_2 == a % b){cout << "True" << endl;}else{cout << "False" << endl;	}}if(Options_2 == 2){division_2();cout << a << "/" << b << "=?" << endl;cin >> answer >> answer_2;if (answer == a / b && answer_2 == a % b){cout << "True" << endl;}else{cout << "False" << endl;	}}if(Options_2 == 3){division_3();cout << a << "/" << b << "=?" << endl;cin >> answer >> answer_2;if (answer == a / b && answer_2 == a % b){cout << "True" << endl;}else{cout << "False" << endl;	}}if (Options_2 < 1 || Options_2 > 3)//错误判断 {BUG();}
}// -----------------------------------------------主函数 -------------------------------------------int main()
{screen_main();//调用screen_main函数cin >> Options_1; //选项1if(Options_1 == 1){screen_1();} if(Options_1 == 2){screen_2();}if(Options_1 == 3){screen_3();}if(Options_1 == 4){screen_4();}if (Options_1 < 1 || Options_1 > 4){BUG();return 0;} }/* -----------------------------------------------------------------日志 ------------------------------------------------------------
[2024/8/29]:完成了加法全部部分 
[2024/8/29]:完成了减法全部部分
[2024/8/29]:完成了乘法全部部分
[2024/8/29]:完成了除法全部部分
待解决BUG:除法出现除零  除法出现无限循环/不循环小数导致计算错误 
[2024/8/30]:除零BUG已修复 
[2024/8/30]:BUG修复失败,睡觉! 
------------------------------------------------------------------- 日志 --------------------------------------------------------------*/ 

http://www.lryc.cn/news/515325.html

相关文章:

  • CSS3——3. 书写格式二
  • PHP语言的计算机基础
  • 第 23 章 JSON
  • Java 正则表达式入门与应用(详细版)
  • 洛谷:P1540 [NOIP2010 提高组] 机器翻译
  • 基于AT89C51单片机的可暂停八路抢答器设计
  • 面试题解,Java中的“对象”剖析
  • 行为模式3.迭代器模式
  • 第8章 DMA控制器
  • 后端java开发路由接口并部署服务器(四)
  • 检索增强生成 和思维链 结合: 如何创建检索增强思维链 (RAT)?
  • 在 SQL 中,区分 聚合列 和 非聚合列(nonaggregated column)
  • 单元测试3.0+ @RunWith(JMockit.class)+mock+injectable+Expectations
  • STM32第十一课:STM32-基于标准库的42步进电机的简单IO控制(附电机教程,看到即赚到)
  • MotionCtrl: A Unified and Flexible Motion Controller for Video Generation 论文解读
  • LINUX线程操作
  • 在Lua中,Metatable元表如何操作?
  • 4D LUT: Learnable Context-Aware 4D LookupTable for Image Enhancement
  • 瑞芯微rk3568平台 openwrt系统适配ffmpeg硬件解码(rkmpp)
  • 使用SuperMap制作地形图的详细教程
  • PHP Array:精通数组操作
  • 【使用命令配置java环境变量永久生效与脚本切换jdk版本】
  • STM32-笔记32-ESP8266作为服务端
  • RAG(Retrieval-Augmented Generation,检索增强生成)流程
  • 【Python学习(六)——While、for、循环控制、指数爆炸】
  • 解释一下:运放的输入失调电流
  • 力扣hot100——二分查找
  • PHP 使用集合 处理复杂数据 提升开发效率
  • Unity 对Sprite或者UI使用模板测试扣洞
  • unity学习3:如何从github下载开源的unity项目