个简单的手持计算器。程序支持算术运算+以及C(清除)、.DOCVIP

  • 12
  • 0
  • 约9.83千字
  • 约 3页
  • 2020-04-03 发布于天津
  • 举报

个简单的手持计算器。程序支持算术运算+以及C(清除)、.DOC

设计一个程序来模拟一个简单的手持计算器。程序支持算术运算+、-、*、/、=、以及C(清除)、A(全清除)操作。 基本要求: 程序运行时,显示一个窗口,等待用户输入,用户可以从键盘输入要计算的表达式,输入的表达式显示在窗口中,用户键入’=’ 符号后,窗口显示出结果。(不用考虑运算符的优先级) 测试数据: 程序输入不少于5种不同的表达式进行测试。 输入: 12.3+2-12+5= 输出: 12.3+2-12+5=7.3 #includestdlib.h #includestdio.h #includestring.h #includestacklist.h #includemath.h struct Type { char ch; double num; char str[10]; }; struct Stack { type *data; struct Stack *next; }; stacklist *initiationstack() { stacklist *top=(stacklist*)malloc(sizeof(stacklist)); top-data=(type*)malloc(sizeof(type)); top-data=0; top-next=0; return top; }; int isempty(stacklist *top) { if(top-next) return 1; else return 0; } void push(stacklist **top, char c) { stacklist *p; p=(stacklist*)malloc(sizeof(stacklist)); p-data=(type*)malloc(sizeof(type)); p-data-ch=c; p-next=(*top)-next; (*top)-next=p; } void push(stacklist **top, double c) { stacklist *p; p=(stacklist*)malloc(sizeof(stacklist)); p-data=(type*)malloc(sizeof(type)); p-data-num=c; p-next=(*top)-next; (*top)-next=p; } void push(stacklist **top, char *c) { stacklist *p; p=(stacklist*)malloc(sizeof(stacklist)); p-data=(type*)malloc(sizeof(type)); strcpy(p-data-str,c); p-next=(*top)-next; (*top)-next=p; } void pop(stacklist **top) { stacklist *p=(*top)-next; (*top)-next=(*top)-next-next; free(p-data); free(p); } double fun(char c,double a, double b) { switch(c) { case + : return a+b; case - : return a-b; case * : return a*b; case / : return a/b; } return 0; } double yusuan(stacklist *number,stacklist *character) { stacklist *number1, *character1,*number2, *character2; number1=initiationstack(); character1=initiationstack(); number2=initiationstack(); character2=initiationstack(); double a,b,result; char c; push(number2,number-next-data-num); result=number-next-da

文档评论(0)

1亿VIP精品文档

相关文档