Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #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;}
  2. Op(int id,string nm){type=SYM;ident=id;name=nm;}
  3. Op(int id,string nm,double val){type=VAR;ident=id;name=nm;value=val;}
  4. enum TYP tp(){return type;}
  5. int id(){return ident;}bool isnum(){return type==NUM;}bool issym(){return type==SYM;}
  6. 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