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

[开源]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; //选项1
	
	
	if(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.kler.cn/a/468009.html

相关文章:

  • 级联配准learning
  • Timer、Ticker使用及其注意事项
  • 01、Docker学习,第一天:简单入门与安装
  • SQL中聚类后字段数据串联字符串方法研究
  • 重庆大学软件工程复试怎么准备?
  • 深入解析 Linux 设备树中的引脚控制(pinctrl)二
  • 基于Spring Boot微信小程序的房产交易租赁服务平台
  • 慧集通iPaaS集成平台低代码训练-实践篇
  • 术业有专攻,遨游工业三防手机筑牢“危急特”通信防线
  • Ubuntu离线登入mysql报错缺少libncurses.so.5问题
  • CSS 之 响应式设计 前世今生
  • Java 集合框架之 List、Set 和 Map 的比较与使用
  • ABAP弹出对对话框错误信息设计
  • 在 SQL 中,区分 聚合列 和 非聚合列(nonaggregated column)
  • C#中鼠标点击获取Chart图形上的坐标值
  • Nginx整理
  • TP8 前后端跨域访问请求API接口解决办法
  • 数据结构考前总结
  • 【光纤通信】光纤结构
  • protobuf: 通讯录2.2
  • Git关联多个仓库
  • HALCON中用于分类的高斯混合模型create_class_gmm
  • uniapp--HBuilder开发
  • 一些计算机零碎知识随写(25年1月)
  • YOLO系列的学习
  • Python中的OS库