C++代码,计算器的

来源:百度知道 编辑:UC知道 时间:2024/05/31 03:31:39
做个c++计算器,在图形界面上有+ - * /的按扭,还有十个数字,用这个界面上 的这些按扭可以完成所有的加减乘除运算,不用键盘,并且在EDIT框中显示出来?

MFC可以快速实现。我就不给出可视化部分了,因为太简单,建一个工程,然后可视化的编辑对话框,然后添加按钮,添加映射什么的。
核心算法在此,支持表达式
3+(32*23+53)/20
试试吧
/*
simple integer arithmetic calculator according to the EBNF
<exp> -> <term>{<addop><term>}
<addop>->+|-
<term>-><factor>{<mulop><factor>}
<mulop> -> *
<factor> -> ( <exp> )| Number
Input a line of text from stdin
Outputs "Error" or the result.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char token;/*global token variable*/
/*function prototypes for recursive calls*/
int exp(void);
int term(void);
int factor(void);

void error(void)
{
fprintf(stderr,"Error\n");
exit(1);
}

void match(char expectedToken)
{
if(token==expectedToken)token=getchar();
else error();
}