Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- enum Codes
- {
- Oct = 8,
- Dec = 0xa,
- Hex = 0x10,
- };
- class Base
- {
- protected:
- int value;
- public:
- void SetValue(int n)
- {
- this->value = n;
- Print();
- }
- virtual void Print(void) = 0;
- };
- class Hex : public Base
- {
- public:
- void Print(void)
- {
- cout << hex << this->Base::value << endl;
- }
- };
- class Oct : public Base
- {
- public:
- void Print(void)
- {
- cout << oct << this->Base::value << endl;
- }
- };
- class Dec : public Base
- {
- public:
- void Print(void)
- {
- cout << dec << this->Base::value << endl;
- }
- };
- class Numeral : Dec, Oct, Hex
- {
- public:
- void Call(int num_sys, int value)
- {
- switch(num_sys)
- {
- case Codes::Oct:
- this->Oct::SetValue(value);
- break;
- case Codes::Dec:
- this->Dec::SetValue(value);
- break;
- case Codes::Hex:
- this->Hex::SetValue(value);
- break;
- };
- }
- };
- void main(void)
- {
- Numeral *object = new Numeral();
- object->Call(Codes::Oct, 9);
- object->Call(Codes::Dec, 0xa);
- object->Call(Codes::Hex, 0xf);
- delete object;
- system("pause");
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement