ConsoleApplication控制台程序--0.6.7

我最近两个月一直在写作业【表情包】,没时间顾得上更新,

所以!我决定撕掉作业把我的程序晒出来~

叫做ConsoleApplication!

我会专门创建一个专栏记录它的更新

放程序:

#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cfloat>
#include <Windows.h>
#include <cmath>

using namespace std;

string getmes;

void getmes_console();
int calc_console();
int fcalc_console();
int precalc_console();
int prefcalc_console();
int powcalc_console();
int sqrcalc_console();
int admin_console();

int main()
{
	cout << "Starting Console Application......" << endl << endl;
	Sleep(1500);
	cout << "Installized." << endl;
	cout << "版本1.0.2.0.12125009。输入\"help\"启动帮助文件。" << endl;

	for (;;) {
		getmes_console();
		if (getmes == "exit") {
			cout << "成功退出." << endl;
			system("pause");
			exit(0);
		}
		else if (getmes == "help") {
			cout << "这是一个控制台应用程序,整合了一些功能。" << endl;
			cout << "具体操作如下:" << endl;
			cout << "看到了:" << endl;
			cout << "Console>" << endl;
			cout << "就说明我们可以开始使用了,现有以下命令:" << endl;
			cout << "1:exit" << endl;
			cout << "退出程序。" << endl;
			cout << "2:help" << endl;
			cout << "帮助。" << endl;
			cout << "3:calc" << endl;
			cout << "计算器程序。现有加(+),减(-),乘(*),除(/)和取余运算(%),输入格式为:1 + 2。" << endl;
			cout << "4:fcalc" << endl;
			cout << "calc的小数点版本。" << endl;
			cout << "5:precalc" << endl;
			cout << "高级函数计算器。现有取绝对值(abs)和平方根(sqrt),输入格式为:abs -3。" << endl;
			cout << "6:sqrcalc" << endl;
			cout << "关于三角形的计算器。现有正弦函数(sin),余弦函数(cos),正切函数(tan),反正弦函数(asin)和反正切函数(atan),输入格式为:sin 20.8。" << endl;
			cout << "7:prefcalc" << endl;
			cout << "precalc的小数版本。增加向上取整(ceil)和向下取整(floor)。" << endl;
			cout << "8:powclac" << endl;
			cout << "计算第一个值的第二个值次方,输入格式为:1 2。" << endl;
			cout << "9:filewrite" << endl;
			cout << "文件写入器。在程序目录下会生成一个您提供的名字的文件,内容也为您提供的。" << endl;
			cout << "10:limits" << endl;
			cout << "显示变量类型在运行操作系统中的上下限和位数。" << endl;
		}
		else if (getmes == "calc") {
			calc_console();
		}
		else if (getmes == "fcalc") {
			fcalc_console();
		}
		else if (getmes == "precalc") {
			precalc_console();
		}
		else if (getmes == "prefcalc") {
			prefcalc_console();
		}
		else if (getmes == "powcalc") {
			powcalc_console();
		}
		else if (getmes == "sqrcalc") {
			sqrcalc_console();
		}
		else if (getmes == "limits") {
			cout.setf(std::ios_base::fixed);
			cout.setf(std::ios_base::dec);
			cout << "请注意每个系统的变量上下限不同,当前显示的为运行系统的变量上下限。" << endl;
			cout << "上限:" << endl;
			cout << "short:" << SHRT_MAX << endl;
			cout << "int:" << INT_MAX << endl;
			cout << "long:" << LONG_MAX << endl;
			cout << "long long(C++11):" << LLONG_MAX << endl;
			cout << "unsigned short:" << USHRT_MAX << endl;
			cout << "unsigned int:" << UINT_MAX << endl;
			cout << "unsigned long:" << ULONG_MAX << endl;
			cout << "unsigned long long(C++11):" << ULLONG_MAX << endl;
			cout.setf(std::ios_base::scientific);
			cout << "float:" << FLT_MAX << endl;
			cout << "double:" << DBL_MAX << endl;
			cout << "long double:" << LDBL_MAX << endl;
			cout << "下限:" << endl;
			cout.setf(std::ios_base::fixed);
			cout << "short:" << SHRT_MIN << endl;
			cout << "int:" << INT_MIN << endl;
			cout << "long:" << LONG_MIN << endl;
			cout << "long long(C++11):" << LLONG_MIN << endl;
			cout.setf(std::ios_base::scientific);
			cout << "float:" << FLT_MIN << endl;
			cout << "double:" << DBL_MIN << endl;
			cout << "long double:" << LDBL_MIN << endl;
			cout.setf(std::ios_base::fixed);
			cout << "unsigned short:" << 0 << endl;
			cout << "unsigned int:" << 0 << endl;
			cout << "unsigned long:" << 0 << endl;
			cout << "unsigned long long(C++11):" << 0 << endl;
			cout << "位数:" << endl;
			cout << "short:" << sizeof(short) << endl;
			cout << "int:" << sizeof(int) << endl;
			cout << "long:" << sizeof(int) << endl;
			cout << "long long(C++11):" << sizeof(long long) << endl;
			cout << "unsigned short:" << sizeof(unsigned short) << endl;
			cout << "unsigned int:" << sizeof(unsigned int) << endl;
			cout << "unsigned long:" << sizeof(unsigned long) << endl;
			cout << "unsigned long long(C++11):" << sizeof(unsigned long long) << endl;
			cout << "float:" << sizeof(float) << endl;
			cout << "double:" << sizeof(double) << endl;
			cout << "long double:" << sizeof(long double) << endl;
			cout << "bool(C++11):" << sizeof(bool) << endl;
			cout << "char:" << sizeof(char) << endl;
 		}
		else if (getmes == "admin") {
			admin_console();
		}
		else if (getmes == "appver") {
			cout << "ConsoleApplication 控制台应用程序 版本1.0.2.0.12125009" << endl;
			cout << "C++版本,本产品适用于Windows Vista SP1 x64及以上版本,并支持C++11标准的环境" << endl;
		}
		else {
			cout << "Error000:未输入有效的命令。\a" << endl;
		}
		getmes = "";
	}
	
	return 0;
}
void getmes_console() {
	cout << "Console>";
	cin >> getmes;
}
int calc_console() {
	long long a = 0;
	char b = 'N';
	long long c = 0;
	long long ans = 0;
	cout << "Message001:切换视图Calc。" << endl;
	cout << "Calc>";
	cin >> a >> b >> c;
	switch (b) {
	case '+':ans = a + c; break;
	case '-':ans = a - c; break;
	case '*':ans = a * c; break;
	case '/':
		if (b <= 0) {
			cout << "来自视图Calc:Error002:除数不是有效的正整数。\a";
			cout << "Error002:程序“clac”异常退出,返回代码1。\a";
			exit(1);
		}
		ans = a / b;
		break;
	case '%':ans = a % b; break;
	default:
		cout << "来自视图Calc:Error001:未输入有效的运算符,计算无法继续。\a" << endl;
		cout << "Error002:程序“clac”异常退出,返回代码1。\a";
		exit(1);
	}
	cout << ans << endl;
	return 1;
}
int fcalc_console() {
	long double a = 0;
	char b = 'N';
	long double c = 0;
	long double ans = 0;
	int k = 0;
	long double r = 0.0;
	cout << "Message001:切换视图fCalc。" << endl;
	cout << "fCalc>";
	cin >> a >> b >> c;
	switch (b) {
	case '+':ans = a + c; break;
	case '-':ans = a - c; break;
	case '*':ans = a * c; break;
	case '/':
		if (c <= 0) {
			cout << "来自视图fCalc:Error002:除数不是有效的正实数。\a";
			cout << "Error002:程序“fcalc”异常退出,返回代码1。\a";
			exit(1);
		}
		ans = a / c;
		break;
	case '%':
		k = (long long)a / c;
		r = a - k * c;
		ans = r;
		break;
	default:
		cout << "来自视图Calc:Error001:未输入有效的运算符,计算无法继续。\a" << endl;
		cout << "Error002:程序“fcalc”异常退出,返回代码1。\a";
		exit(1);
	}
	cout << ans << endl;
	return 1;
}
int precalc_console() {
	string math;
	long long x = 0;
	long long ans = 0;
	cout << "Message001:切换视图preCalc。" << endl;
	cout << "preCalc>";
	cin >> math >> x;
	if (math == "abs") {
		ans = abs(x);
	}
	else if (math == "sqrt") {
		ans = (int)sqrt(x);
	}
	else {
		cout << "来自视图preCalc:Error001:未输入有效的运算函数,计算无法继续。\a" << endl;
		return 1;
	}
	cout << ans << endl;
	return 0;
}
int prefcalc_console() {
	string math;
	long double x = 0.0;
	long double ans = 0.0;
	cout << "Message001:切换视图prefCalc。" << endl;
	cout << "prefCalc>";
	cin >> math >> x;
	if (math == "abs") {
		ans = fabs(x);
	}
	else if (math == "ceil") {
		ans = ceil(x);
	}
	else if (math == "floor") {
		ans = floor(x);
	}
	else if (math == "sqrt") {
		ans = sqrt(x);
	}
	else {
		cout << "来自视图prefCalc:Error001:未输入有效的运算函数,计算无法继续。\a" << endl;
		return 1;
	}
	cout << ans << endl;
	return 0;
}
int powcalc_console() {
	long double x = 0.0;
	long double y = 0.0;
	long double ans = 0.0;
	cout << "Message001:切换视图powCalc。" << endl;
	cout << "powCalc>";
	cin >> x >> y;
	ans = pow(x, y);
	cout << ans << endl;
	return 0;
}
int sqrcalc_console() {
	string math;
	long double x = 0.0;
	long double ans = 0.0;
	cout << "Message001:切换视图sqrCalc。" << endl;
	cout << "sqrCalc>";
	cin >> math >> x;
	if (math == "sin") {
		ans = sin(x);
	}
	else if (math == "cos") {
		ans = cos(x);
	}
	else if (math == "tan") {
		ans = tan(x);
	}
	else if (math == "asin") {
		ans = asin(x);
	}
	else if (math == "acos") {
		ans = acos(x);
	}
	else if (math == "atan") {
		ans = atan(x);
	}
	else {
		cout << "来自视图sqrCalc:Error001:未输入有效的运算函数,计算无法继续。\a" << endl;
		return 1;
	}
	cout << ans << endl;
	return 0;
}
int admin_console() {
	unsigned long long password = 0;
	cin >> password;
	if (password == 1212) {
		cout << "Console-admin>";
	}
	else {
		cout << "验证错误。" << endl;
		return 1;
	}
	cin >> getmes;
	if (getmes == "memcheck") {
		cout << "全局定义变量" << endl;
		cout << "getmes:string:" << hex << &getmes << endl;
		cout.setf(std::ios_base::dec);
		return 0;
	}
	else if (getmes == "exit") {
		return 0;
	}
	else {
		cout << "Error000:未输入有效的命令。\a" << endl;
	}
	return 0;
}

搭建环境:

操作系统 Windows 11 家庭中文版 22H2 22621.1702 64位

IDE Microsoft Visual Studio Community 2022 64位 17.5.3

拜~

不允许转载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值