欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 焦点 > [开源]C++代码分享

[开源]C++代码分享

2025/1/4 12:32:26 来源:https://blog.csdn.net/dream321_/article/details/144857168  浏览:    关键词:[开源]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修复失败,睡觉! 
------------------------------------------------------------------- 日志 --------------------------------------------------------------*/ 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com