跳到正文

个人记录

C++98计算器

BL_Turtle约 10 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 10 分钟

版本

  1. v1当前

蒟蒻开发了2小时,弄了个计算器

C++
//请看功能介绍
#include<windows.h>
#include<iostream>
#include<unistd.h>
#include<iomanip>
#include<cmath>
#include<ctime>
using namespace std;
void time() {
	time_t now = time(0);
	tm *localTime = localtime(&now);
	cout << "当前时间: ";
	cout << (localTime->tm_year + 1900) << "-"
		 << (localTime->tm_mon + 1) << "-"
		 << localTime->tm_mday << " "
		 << localTime->tm_hour << ":"
		 << localTime->tm_min << ":"
		 << localTime->tm_sec << endl;
	cout << endl;
}
long double jia(long double a,long double b) {
	cout << "输入第一个加数" << endl;
	cin >> a;
	cout << "输入第二个加数" << endl;
	cin >> b;
	cout << fixed << a + b << endl << endl;
	time();
}
long double jian(long double a,long double b) {
	cout << "输入被减数" << endl;
	cin >> a;
	cout << "输入减数(比被减数小)" << endl;
	cin >> b;
	cout << fixed << a - b << endl;
	time();
}
long double cheng(long double a,long double b) {
	cout << "输入第一个乘数" << endl;
	cin >> a;
	cout << "输入第二个乘数" << endl;
	cin >> b;
	cout << fixed << a * b << endl;
	time();
}
int chu(int a,int b) {
	cout << "输入被除数" << endl;
	cin >> a;
	cout << "输入除数(比除数小,不得为0)" << endl;
	cin >> b;
	if (a % b != 0) cout << a / b << "······" << a % b << endl;
	else cout << cout << a / b << endl;
	time();
}
int chf(int a,int b) {
	cout << "[ ]的[ ]次方?(按顺序输入两个数)" << endl;
	cin >> a >> b;
	cout << pow(a,b) << endl;
	time();
}
int main() {
	long long s;
	mainc:
	cout << "   CCCCCCCCCCC" << endl;
	cout << " CCCCCCCCCCCCC" << endl;
	cout << "CCC" << endl;
	cout << "CCC				+++		 +++ " << endl;
	cout << "CCC				+++		 +++" << endl;
	cout << "CCC			+++++++++++ +++++++++++" << endl;
	cout << "CCC			+++++++++++ +++++++++++" << endl;
	cout << "CCC				+++		 +++" << endl;
	cout << "CCC				+++		 +++" << endl;
	cout << "CCC" << endl;
	cout << " CCCCCCCCCCCCC" << endl;
	cout << "   CCCCCCCCCCC" << endl;
	cout << "-------------------------------------------------------------------------------" << endl;
	cout << "欢迎使用 C++98 计算器!" << endl;
	cout << "版本: Calc V2" << endl;
	cout << "开发: BL_TURTLE'S CansLC(2025,正式版)" << endl;
	cout << "想做什么? 使用[1] 疯[2] 退出[3] 显示当前时间(新功能!!!)[4] 功能介绍[5] 设置[6]" << endl;//新增设置
	cin >> s;
	if (s == 1) {
		usec:
		cout << "加法[1]" << endl;
		cout << "减法[2]" << endl;
		cout << "乘法[3]" << endl;
		cout << "除法[4]" << endl;
		cout << "乘方[5]" << endl;
		int sss,a,b;cin >> sss;
		if (sss == 1) {
			jia(a,b);
			cout << "回到哪里? 主界面[1] “使用”界面[2]";
			int gotowhere;cin >> gotowhere;
			if (gotowhere == 1) {
				cout << endl;
				goto mainc;
			}
			else if (gotowhere == 2) {
				cout << endl;
				goto usec;
			}
			else {
				cout << "输入错误" << endl;
				goto mainc;
			}
		}
		if (sss == 2) {
			jian(a,b);
			cout << "回到哪里? 主界面[1] “使用”界面[2]";
			int gotowhere;cin >> gotowhere;
			if (gotowhere == 1) {
				cout << endl;
				goto mainc;
			}
			else if (gotowhere == 2) {
				cout << endl;
				goto usec;
			}
			else {
				cout << "输入错误" << endl;
				goto mainc;
			}
		}
		if (sss == 3) {
			cheng(a,b);
			cout << "回到哪里? 主界面[1] “使用”界面[2]";
			int gotowhere;cin >> gotowhere;
			if (gotowhere == 1) {
				cout << endl;
				goto mainc;
			}
			else if (gotowhere == 2) {
				cout << endl;
				goto usec;
			}
			else {
				cout << "输入错误" << endl;
				goto mainc;
			}
		}
		if (sss == 4) {
			chu(a,b);
			cout << "回到哪里? 主界面[1] “使用”界面[2]";
			int gotowhere;cin >> gotowhere;
			if (gotowhere == 1) {
				cout << endl;
				goto mainc;
			}
			else if (gotowhere == 2) {
				cout << endl;
				goto usec;
			}
			else {
				cout << "输入错误" << endl;
				goto mainc;
			}
		}
		if (sss == 5) {
			chf(a,b);
			cout << "回到哪里? 主界面[1] “使用”界面[2]";
			int gotowhere;cin >> gotowhere;
			if (gotowhere == 1) {
				cout << endl;
				goto mainc;
			}
			else if (gotowhere == 2) {
				cout << endl;
				goto usec;
			}
			else {
				cout << "输入错误" << endl;
				goto mainc;
			}
		}
	}
	else if (s == 2) {
		system("calc");
		cout << "还要继续? 要[1] 不要[2]" << endl;
		int ss;cin >> ss;
		if (ss == 1) {
			while (1) {
				system("calc");
			}
		}
		else if (ss == 2) {
			system("Color 0A");
			cout << "滚!" << endl;
			goto end;
		}
		else {
			cout << "输入错误" << endl;
			goto mainc;
		}
	}
	else if (s == 3) {
		goto end;
	}
	else if (s == 4) {
		cout << "提示:由于开发人员技术To Low,一进入此功能将无法退出至别的页面!(anslt+F4结束程序)" << endl << endl;
		Sleep(1000);
		while (1) {
			time_t rawtime;
			struct tm *timeinfo;
			char buffer[80];
			time(&rawtime);
			timeinfo = localtime(&rawtime);
			strftime(buffer,sizeof(buffer),"%H:%M:%S",timeinfo);
			cout << "\r" << buffer << flush;
			sleep(1);
		}
	}
	else if (s == 5) {
		cout << "功能介绍:" << endl;
		cout << "·相比第一代,增加时间显示器" << endl;
		cout << "·运算数字范围更大(运用 “long double”)" << endl;
		cout << "·选择想做什么用数字输入,取消符号输入" << endl;
		cout << "·如果不想使用这个计算器,用“疯”选项打开Windows计算器" << endl;
		cout << "·如果输入数字错误,将回到主界面而不是退出程序" << endl;
		cout << ""
		jieshao:
		cout << endl << "想做什么? 退出[1] 回到主界面[2]" << endl;
		int ss;cin >> ss;
		if (ss == 1) {
			goto end;
		}
		else if (ss == 2) {
			goto mainc;
		}
		else {
			cout << "输入错误" << endl;
			goto jieshao;
		}
	}
	else {
		cout << "输入错误" << endl;
		goto mainc;
	}
	end:return 0;
}
原文