作业帮 > 综合 > 作业

编写计算器程序,用c++程序语言.

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/05/16 16:06:32
编写计算器程序,用c++程序语言.
请编写程序实现任意数学表达式求值计算器功能
说明:
(^)是乘方运算符,(#)是开方运算符,键入(S)清屏,键入(Q)退出.
负数运算以及错误警告.
如输入数学表达式:例 6+(6+8/2*(8-5)^3)*2 =234
6*10-4%3+10.6^3 =1151.727
00011001&&10010001 =00010001
(6*3)&&0||4=1
即:从键盘输入一段 表达式,通过程序计算,可得表达式的结果
要求得完成:加+、减-、乘*、除/、余%、n次方(^乘方)、开n次方(#开方)、与&&、或||、非!、括号() 等几种运算的混合运算.
编写计算器程序,用c++程序语言.
所有你列的运算都实现了,代码如下
#ifndef _CALCULARTOR_H
#define _CALCULARTOR_H
#include
#include
#include
#include
#include
using namespace std;
struct OPRT{
int size;
int top;
char *elements;
OPRT(int sizeOprt){
size=sizeOprt;
elements=new char[sizeOprt];
top=-1;
}
~OPRT(){
delete [] elements;
}
bool empty(){
if(top==-1)
return true;
else
return false;
}
bool full(){
if(top >= size-1)
return true;
else
return false;
}
bool push(char x){
if(full())
return false;
top++;
elements[top]=x;
return true;
}
bool pop(char &x){
if(empty())
return false;
x=elements[top];
top--;
return true;
}
char gettop(){
char x;
x=elements[top];
return x;
}
};
struct OPRD{
int size;
int top;
double *elements;
OPRD(int size1){
size=size1;
elements=new double[size1];
top=-1;
}
~OPRD(){
delete [] elements;
}
bool empty(){
if(top==-1)
return true;
else
return false;
}
bool full(){
if(top >= size-1)
return true;
else
return false;
}
bool push(double x){
if(full())
return false;
top++;
elements[top]=x;
return true;
}
bool pop(double &x){
if(empty())
return false;
x=elements[top];
top--;
return true;
}
double gettop(){
double x;
x=elements[top];
return x;
}
};
int precede(char cStackTop,char cNew);
double operate(double a,char theta,double b);
#endif
//:This is the main function of calculator
#include "calculator.h"
bool bError = false;
int main(void)
{
const intiSizeOfStk = 20;
OPRDoprd(iSizeOfStk);
OPRToprt(iSizeOfStk);
stringsInExp;
stringsOprd;//to get num from sInExp
doubledOprd;
cout
再问: 编译的时候有一个错误Cannot open include file: 'calculator.h': No such file or directory,怎么办呢?
再答: 这个程序并不只一个文件,一共有三个,你得先建一个项目,然后把三个文件导进去,再编译
再问: 可以给我讲详细点嘛?
再答: 如果一个程序既有头文件(这个你应该知道吧?)又有源文件,你就得建一个项目,然后在项目中添加你需要的头文件和源文件,这个很基本,当然可能我这个程序复杂了点,你试着改一下吧
再问: 可以给我说说操作过程吗?