⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 output.cpp

📁 能计算数学函数的计算器,有一千多行代码的程序.这个计算器可用 set 命令自定义变量
💻 CPP
字号:
#include <ctype.h>
#include "common.h"
#include "calculate.h"
void PrintResult (
	NODE *Result
	)
{
	char format[10];
	char c = '%';
	if (error != NULL || vision == false) {
		return;
	}
	sprintf (format,"%c.%df\n",c,prec);
	
	printf ("= ");
	if (Result->Term.Operand.DataSignal == INTEGER) {
		printf ("%d\n",Result->Term.Operand.Data.Integer);
	} else {
		printf (format,Result->Term.Operand.Data.Real);
	}
	putchar ('\n');
}

void PrintError (
	void
	)
{
	printf ("error[%d]:",error);
	switch (error) {
		case the_name_is_too_long:
			printf ("变量的名字好长啊...\n");
			break;
		case can_not_identify_identifier:
			printf ("以前好像没有见过变量:%s\n",VarName);
			break;
		case the_data_bit_is_too_long:
			printf ("数据也太大了一点吧\n");
			break;
		case the_real_number_is_illegal:
			printf ("小数点只有一个,看你打了几个\n");
			break;
		case illegal_compages:
			printf ("好像不是这回事\n");
			break;
		case the_brackets_are_not_match:
			printf ("括号是成对出现的,不要棒打鸳鸯噢\n");
			break;
		case the_mode_operator_only_accept_integral_operands:
			printf ("好像只能对整数求余吧\n");
			break;
		case the_divisor_can_not_be_zero:
			printf ("你见过除数为 0 的表达式吗\n");
			break;
		case the_stack_is_null:
			printf ("不知道错哪了,检查了半天也没查出什么错了");
			break;
		case memmory_allocation_failed:
			printf ("电脑内存有点小噢\n");
			break;
		case the_argument_cannot_been_explained:
			printf ("还是说中文吧,不懂啊\n");
			break;
		case find_some_illegal_word:
			printf ("这里只用全英文的变量名\n");
			break;
		case the_precision_or_mode_only_accept_integral_argument:
			printf ("全局变量的值只能是 0 -100 的整数啊,我是认真的");
			break;
		case the_command_is_incorrect:
			printf ("看来我应该抓紧时间学习,才能弄懂你的语言\n");
			break;
		case the_var_is_not_seen_before:
			printf ("以前好像没见过变量:%s\n",Command[1]);
			break;
		case find_some_illegal_alpha:
			printf ("有些东西不认识\n");
			break;
		case the_prec_value_range_from_0_to_100:
			printf ("prec 的值只能是从 0 到 100\n");
			break;
		case connot_use_system_identify:
			printf ("那是我自己用的名字\n");
		default:
			break;
	}
	putchar ('\n');
}

void CmdExecute (
	void
	)
{
	if (error != NULL) {
		return;
	}
	switch (ArgCounter) {
		case 0:
			return;
		case 1:
			if (infocmd == 0) {
				Calculator ();
				return;
			} else if (infocmd == 1 || infocmd == 2) {
				error = the_command_is_incorrect;
				return;
			} else if (infocmd == 3) {
				usage ();
				return;
			} else {
				exit (0);
			}
		case 2:
			if (infocmd != 2 ) {
				error = the_command_is_incorrect;
				return;
			} else {
				if (infoarg == 1) {
					printf ("prec : %d\n\n",prec);
					return;
				} else if (infoarg == 2) {
					printf ("prec : %d\n",prec);
					PrintVariable ();
					putchar ('\n');
					return;
				} else {
					VARIABLE *tmp;
					for (int i = 0;Command[1][i] != NULL;i ++) {
						if (!isalpha (Command[1][i])) {
							error = find_some_illegal_word;
							return;
						}
					}
					if (tmp = VariableSearch (VariableList,Command[1])) {
						printf ("%s : ",Command[1]);
						if (tmp->Operand.DataSignal == FLOAT) {
							printf ("%f\n",tmp->Operand.Data.Real);
						} else {
							printf ("%d\n",tmp->Operand.Data.Integer);
						}
					} else {
						error = the_var_is_not_seen_before;
						return;
					}
					return;
				}
			}
		case 3:
			if (infocmd != 1) {
				error = the_command_is_incorrect;
				return;
			} else {
				Calculator ();
				if (error != NULL) {
					return;
				}			
				if (infoarg == 1) {
					if (ExpressionHead->Term.Operand.DataSignal == FLOAT) {
						error = the_precision_or_mode_only_accept_integral_argument;
						return;
					}
					if (ExpressionHead->Term.Operand.Data.Integer > 100 || ExpressionHead->Term.Operand.Data.Integer < 0) {
						error = the_prec_value_range_from_0_to_100;
						return;
					}
					prec = ExpressionHead->Term.Operand.Data.Integer;
					printf ("命令成功执行\n\n");
					return;
				} else if (infoarg == 2) {
					error = the_command_is_incorrect;
					return;
				} else {
					VARIABLE *tmp;
					for (int i = 0;Command[1][i] != NULL;i ++) {
						if (!isalpha (Command[1][i])) {
							error = find_some_illegal_word;
							return;
						}
					}
					if (tmp = VariableSearch (VariableList,Command[1])) {
						tmp->Operand = ExpressionHead->Term.Operand;
						printf ("命令成功执行\n\n");
						return;
					}
					tmp = NewVarNode (Command[1],ExpressionHead->Term.Operand);
					VariableListTail = InsertVarNode (VariableListTail,tmp);
					printf ("命令成功执行\n\n");
				}
			}
	}
}
void Output (
	 void
	 )
{
	CmdExecute ();
	if (error != NULL) {
		PrintError ();
		error = NULL;
		vision = false;
	}
	PrintResult (ExpressionHead);
	ArgCounter = 0;
	infoarg = 0;
	infocmd = 0;
	vision = false;
	DeleteList (ExpressionHead);
	ExpressionHead = NULL;
	FreeCMD ();
	free (Unknown);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -