#include"a.h"
#include <iostream>
#include <cmath>
#include<cstdlib>
#include <cstring>
#include <assert.h>
#include "stack.h"
using namespace
enum Boolean[False,Ture];
template<class Type>class Stack{
public:
Stack (int=10);
~Stack(){delete[]elements;}
void Push(const Type&item);
Type Pop();
Type GetTop();
void MakeEmpty(){top=-1;}
int IsEmpty()const{return top==-1;}
int IsFull()const{return top==maxSize-1};
private:
int top;
Type *elements;
int maxSize;
};
template<class Type> Stack<Type>::Stack(int s):top(-1),maxSize(s){
elements=new Type[maxSize];
assert(elements!=0);
}
template<class Type>void Stack<Type>::Push(const Type&item){
assert(!IsFull());
elements[++top]=item;
}
template<class Type>Type Stack<Type>::Pop(){
assert(!IsEmpty());
return elements[top--];
}
template<class Type>Type Stack<Type>::GetTop(){
assert(!Is Empty());
return elements[top];
}
class Calculator{
public:
Calculator(int sz):s(sz){}
void Run();
void Clear();
private:
void AddOperand(double value);
enum Boolean ;GetTwoOperands(double&left,double&right)
void DoOperand(char op);
class stack;
};
void Calculator::AddOperand(double value){
void Push(const value);
}
Boolean Calculator::GetTwoOPerands{double&left,double&right};
{
if (s.IsEmpty())
{
cerr<<"Missing Operand!"<<endl; return False;
}
right=s.Pop();
if(s.IsEmpty()){
cerr<<"Missing Operand!"<<endl; return False;
}
left=s.Pop();
return Ture;
}
void Calculator::DoOperator(char op){
double left,right; Boolean result;
result=Get2Operands(left,right);
if(result==Ture)
switch(op){
case'+': s.Push(left+right);break;
case'-': s.Push(left-right);break;
case'*': s.Push(left*right);break;
case'/': if(right==0.0){
cerr<<"Divide by 0!"<<endl; Clear();
}
elses.Push(result=left/right);break;
case'^': s.Push(Power(left,right));break;
}
else Clear();
}
void Calculator::Run(){
char c[20];
while(cin>>d,*c!='q')
switch(*c)
{
case'c': S.ClearStack();
break;
case'-'
if(strlen(c)>1)
AddOperand(atoi));
else DoOperator (*c);
break;
case'+':
case'*':
case'/':
case'^':
Do Operator(*c);
break;
default:
AddOperand(atoi(c));
break;
}
}
void Calculator::Clear(void)
{S.ClearStack();}
//1.cpp
int main()
{
Calculator CALC;
CALC.Run();
}
ompiling...
1.cpp
L:\051170114\1\1.cpp(9) : error C2226: syntax error : unexpected type 'Boolean'
L:\051170114\1\1.cpp(49) : warning C4518: 'void ' : storage-class or type specifier(s) unexpected here; ignored
L:\051170114\1\1.cpp(49) : error C2146: syntax error : missing ';' before identifier 'DoOperand'
L:\051170114\1\1.cpp(56) : error C2039: 'GetTwoOPerands' : is not a member of 'Calculator'
L:\051170114\1\1.cpp(41) : see declaration of 'Calculator'
L:\051170114\1\1.cpp(56) : error C2146: syntax error : missing ';' before identifier 'GetTwoOPerands'
L:\051170114\1\1.cpp(56) : error C2501: 'Boolean' : missing storage-class or type specifiers
L:\051170114\1\1.cpp(56) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
1.obj - 6 error(s), 1 warning(s)