Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- ostream operator<<(ostream& o, const Operand& obj)
- {
- o << obj.numar;
- }
- class Operand
- {
- public:
- Operand() { numar = 0; }
- Operand(int n) :numar(n){}
- friend Calculator;
- Operand operator+(Operand& obj)
- {
- return Operand(numar + obj.numar);
- }
- Operand operator/(Operand& obj)
- {
- return Operand(numar / obj.numar);
- }
- friend ostream operator<<(ostream& o, const Operand& obj);
- private:
- int numar;
- };
- class UC
- {
- public:
- UC() { nr1 = 0; nr2 = 0; operatie = ""; }
- UC(int n1, int n2, string op): nr1(n1), nr2(n2), operatie(op){}
- protected:
- int nr1;
- int nr2;
- string operatie;
- };
- class ALU:public UC
- {
- public:
- ALU()
- {
- operatie = UC::operatie;
- }
- Operand calcul()
- {
- if (operatie == "+")
- return (nr1 + nr2);
- else
- if (operatie == "/")
- return (nr1 / nr2);
- else
- cout << "Operatie incorecta";
- }
- private:
- string operatie;
- };
- class UM:public UC, public ALU
- {
- public:
- friend ALU;
- UM()
- {
- op1 = UC::nr1;
- op2 = UC::nr2;
- rezultat = 0;
- }
- void stocareDate()
- {
- rezultat = calcul();
- }
- protected:
- Operand op1;
- Operand op2;
- Operand rezultat;
- };
- class UA: public UM
- {
- public:
- void Afisare()
- {
- cout << op1 << "+" << op2 << "=" << rezultat;
- }
- };
- class Calculator
- {
- public:
- Calculator(UC _uc, ALU _alu, UM _um, UA _ua): uc(_uc), alu(_alu), um(_um), ua(_ua){}
- void executare()
- {
- ua.Afisare();
- }
- private:
- UC uc;
- ALU alu;
- UM um;
- UA ua;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement