——————————头文件————————
#define _CRT_SECURE_NO_WARNINGS 1 #ifndef __CALCULATOR_H__ #define __CALCULATOR_H__ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<windows.h> #include<math.h> typedef float DataType; #define MaxSize 100 typedef struct { float data[MaxSize]; int top; } ComStack; typedef struct { float data[MaxSize]; int top; }Stack; void InitStack(Stack *s); int GetTop(Stack s, DataType *z); int Push(Stack *s, DataType z); int Pop(Stack *s, DataType *z); void TransmitExpression(char a[], char b[]); float EvaluateExpression(char b[]); int quit(); int mune(); int SimpleCalculator(); int ExpressionCalculator(); #endif
————————函数部分——————
#include"calculator.h" void InitStack(Stack *s) { s->top = 0; } int GetTop(Stack s, DataType *z) { if (s.top > 0) { *z = s.data[s.top - 1]; return 1; } else return 0; } int Push(Stack *s, DataType z) { if (s->top >= MaxSize) { printf("栈已满,不能进栈!\n"); return 0; } else { s->data[s->top] = z; s->top++; return 1; } } int Pop(Stack *s, DataType *z) { if (s->top == 0) { printf("栈已空,不能出栈!\n"); return 0; } else { s->top--; *z = (char)s->data[s->top]; return 1; } } void TransmitExpression(char a[], char b[]) { Stack s; char ch; DataType x; int i = 0, j = 0; InitStack(&s); ch = a[i]; i++; while (ch != '\0') { switch (ch) { case '(': Push(&s, ch); break; case
具有表达式求值功能的计算器软件设计
最新推荐文章于 2022-04-18 07:00:00 发布