1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| #define _CRT_SECURE_NO_WARNINGS #include<iostream>
using namespace std;
class Programmer { public: virtual void PrintPaid() = 0; Programmer() {}; Programmer(double tPaid) :paid(tPaid) {}; virtual ~Programmer() { cout << "~Programmer()..." << endl; } double getPaid() { return paid; } private: double paid; };
class Junior_programmer : public Programmer { public: Junior_programmer(){} Junior_programmer(double paid):Programmer(paid){} virtual void PrintPaid() { cout << "Junior_programmer :" << getPaid() << endl; } ~Junior_programmer() { cout << "~Junior_programmer()..." << endl; } };
class Mid_programmer : public Programmer{ public: Mid_programmer(){} Mid_programmer(double paid) :Programmer(paid) {}
virtual void PrintPaid() { cout << "Mid_programmer :" << getPaid() << endl; } ~Mid_programmer() { cout << "~Mid_programmer()..." << endl; } };
class Adv_programmer : public Programmer { public: Adv_programmer(double paid) :Programmer(paid) {} Adv_programmer(){} virtual void PrintPaid() { cout << "Adv_programmer :" << getPaid() << endl; } ~Adv_programmer() { cout << "~Adv_programmer()..." << endl; } };
class Architect : public Programmer{ public: Architect(double paid) :Programmer(paid) {} Architect(){} virtual void PrintPaid() { cout << "Architect :" << getPaid() << endl; } ~Architect() { cout << "~Architect" << endl; } };
void ShowProgrammerPaid(Programmer * p) { if (p != NULL) { p->PrintPaid();
delete p; p = NULL; }
cout << "====================" << endl << endl; }
int main(char *argv[], int argc) { ShowProgrammerPaid(new Junior_programmer(10000)); ShowProgrammerPaid(new Mid_programmer(15000)); ShowProgrammerPaid(new Adv_programmer(20000)); ShowProgrammerPaid(new Architect(30000));
return 0; }
|