/*
一个简单的计算器程序
大家一起交流 QQ:947980562
author : 灯下野狐
date : 09.3.14
*/
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
const int MaxSize = 100;
const double pi = 3.1415926;
const double EXP = 2.7128;//e的值
struct Stack//定义一个栈用来放操作符
{
char data[MaxSize];
int top;
};
struct Stack_double//定义一个栈用来放操作数
{
double data[MaxSize];
int top;
};
void Trans( char* &str, char* &postexp );//将str所指字符串转换成后缀表达式的函数声明
void Compvalue( char* &postexp );//对后缀表达式进行求值
void main()
{
char str[100], postexp[100];
char *p = str, *q = postexp;
cout<<"****************************\n";
cout<<"*****欢迎使用本计算程序*****\n";
cout<<"****************************\n\n";
cout<<"运算符包括:\n";
cout<<"+、-、*、/、^(次方)、%\n\n";
cout<<"sin、cos、tan、arcsin、arccos、arctan\n\n";
cout<<"e(底为e的次方)、log(底为e)、log10()(底为10的对数)、以及括号.\n\n\n";
while ( 1 )
{
cout<<"输入计算式(直接回车结束):\n";
cin.getline( str, 99 ); //输入表达式
Trans( p, q );//转换成后缀表达式
Compvalue( q );//进行求值
}
}
void Trans( char* &str, char* &postexp )//转换函数实现部分