第7天,改变世界的更新!(不好意思,抄minecraft1.7了)新手的崛起!

好的今天真是翻天覆地的更新,真的。不信,你先看下源代码:

/*我在此再次致谢我的第一任C++老师,the book!
          没有它,这个程序无从完成。
           悲!系统原装计算器!*/
#include "myinclude.h"//我的自建头文件
int main(){
	double a, b, c;unsigned Start, End;string i;
	Start = time(NULL);
	printf("计算器欢迎您的光临!");
start:
	printf("\n请选择您要计算的运算方式(如加减乘除)或命令(命令帮助请输入/help),请输入加减乘除的符号(如 + - * /),否则将运算失败。\n");
	printf("目前支持加减乘除和乘方;开平方\t对应符号+ - * / ^ ^/\n");
	cin >> i;    //困扰我多年的scanf string问题!
	if((i != "+") and (i != "-") and (i != "*") and (i != "/") and (i != "^") and (i != "^/") and (i != "/help") and (i != "/sr") and (i != "/cls") and (i != "/exit") and (i != "/shut")){
		srand(unsigned(time(NULL)));
		unsigned errq = rand() % 4;
		printf("\n");
		if(errq == 0) printf("Error(一定有bug)");
		else if(errq == 1) printf("你说啥?");
		else if(errq == 2) printf("傻");
		else if(errq == 3) printf("what?");
		printf("\n\n");
		system("pause");
		goto start;
	}
	if(i == "^/"){
		if(a == 1){
			printf("\n开平方运算中数字不能为1!\n\n");
			system("pause");
			goto start;
		}
		printf("请输入要开平方的数字:");
		scanf("%lf", &a);
		c = sqrt(a);
		goto stop;
	}
	if(i == "/help"){
		printf("\n1、/cls:清空屏幕,重新从头运行;\n2、/sr:显示程序源代码;\n3、/shut:关机;\n4、/exit:退出程序;\n\n#以上是所有命令帮助#\n\n");
		system("pause");
		goto start;
	}
	if(i == "/exit"){
		End = time(NULL);
		unsigned Time = End - Start;
		printf("\nTotal running time : %u seconds\n\n", Time);
		system("pause");
		return 0;
	}
	if(i == "/cls"){
		system("cls");
		printf("计算器欢迎您的光临!");
		goto start;
	}
	if(i == "/sr"){
		fstream fin;
		fin.open("计算器.cpp", ios::in);
		if(!fin.is_open()){
			printf("\nError\n\n");
			system("pause");
			goto start;
		}
		system("cls");
		printf("源代码:\n");
		char buf[100000];
		while(fin.getline(buf, sizeof(buf))) printf("%s\n", buf);
		printf("\n");
		system("pause");
		fin.close();
		system("cls");
		printf("计算器欢迎您的光临!");
		goto start;
	}
	if(i == "/shut") system("shutdown /s /t 0");
	printf("请输入您要计算的两个数字,两个数字间请加空格(此计算器不支持两个以上数字的运算,但支持重复运算):");
	scanf("%lf %lf", &a, &b);
	if(i == "+") c = a + b;
	else if(i == "-") c = a - b;
	else if(i == "*") c = a * b;
	else if(i == "/"){
		int d = fmod(a, b);
		c = a / b;
		d = my_constrain::constrain(d, -2147483648, 2147483647); I want say:"what the fuck?"
		c = my_constrain::constraind(c, -999999999999999, 999999999999999);
		cout << "\n结果:" << setprecision(20) << fixed << setprecision(0) << c << "余" << setprecision(10) << fixed << setprecision(0) << d << " " << setprecision(20) << fixed << setprecision(3) << c << "\n谢谢惠顾,欢迎下次光临!\n\n";
		system("pause");
		goto start;
	}
	else if(i == "^"){
		if((a == 1) || (b == 1)){
			printf("\n乘方运算中第一或第二个数字不能为1!\n\n");
			system("pause");
			goto start;
		}
		c = pow(a, b);
	}
	c = my_constrain::constraind(c, -999999999999999, 999999999999999);
stop:       /*在这里我只能用传统cout了..*/
	cout << "\n结果:" << setprecision(20) << fixed << setprecision(3) << c << "\n谢谢惠顾,欢迎下次光临!\n\n";
	system("pause");
	goto start;
}

看没看到,我插了个自建头文件,头文件里这样写:

/*我会永远永远记着它,我的第一个自建头文件*/
#ifndef MYINCLUDE_H_
#define MYINCLUDE_H_

#include<bits/stdc++.h>
#include<windows.h>

using namespace std;

namespace my_constrain       //约束
{
	int constrain(int zh, int a, int b){
		if(zh < a){
			zh = a;
		}
		else if(zh >= a and zh <= b){
			zh = zh;
		}
		else{
			zh = b;
		}
		return zh;
	}
	double constraind(double zh, double a, double b){
		if(zh < a){
			zh = a;
		}
		else if(zh >= a and zh <= b){
			zh = zh;
		}
		else{
			zh = b;
		}
		return zh;
	}
	float constrainf(float zh, float a, float b){
		if(zh < a){
			zh = a;
		}
		else if(zh >= a and zh <= b){
			zh = zh;
		}
		else{
			zh = b;
		}
		return zh;
	}
}

#endif

是不是有点新手味儿了?好的,包包!(今天换成zip了)

提取码:htrs (还是老样子)icon-default.png?t=N5K3https://pan.baidu.com/s/1ZVG3tNv-2MdPn6lhzNNDcQ#就这么长#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值