Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>using namespace std;enum TYP{NUM,SYM,VAR};static const char*typestr[]={"num","sym","var"};class Op{private:TYP type;int ident;string name;double value;public:Op(int id,double val){type=NUM;ident=id;value=val;}
- Op(int id,string nm){type=SYM;ident=id;name=nm;}
- Op(int id,string nm,double val){type=VAR;ident=id;name=nm;value=val;}
- enum TYP tp(){return type;}
- int id(){return ident;}bool isnum(){return type==NUM;}bool issym(){return type==SYM;}
- void eval(){cout<<typestr[type]<<id()<<endl;}}};int main(){Op three(1,3),x(1,"x"),y(2,"y"),z(3,"z");three.eval();x.eval();y.eval();z.eval();Expr ex1(1,"*",three,y),ex2(2,"-",x,ex1),ex3(3,"=",z,ex2);ex1.eval();ex2.eval();ex3.eval();return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement