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
| #define _CRT_SECURE_NO_WARNINGS #include<iostream>
using namespace std;
class CPU { public: virtual void caculate() = 0; };
class Card { public: virtual void display() = 0; };
class Memory { public: virtual void storage() = 0; };
class Computer { public: Computer(CPU *tcpu1, Card * tcard, Memory * tmemory) :cpu1(tcpu1), card(tcard), memory(tmemory) {}; void print() { cpu1->caculate(); card->display(); memory->storage(); cout << "=========================" << endl; } private: CPU *cpu1; Card * card; Memory * memory;
};
class IntelCpu :public CPU { public: virtual void caculate() { cout << "IntelCPU" << endl; } };
class IntelCard : public Card { public: virtual void display() { cout << "IntelCard" << endl; }; };
class IntelMemory :public Memory { public: virtual void storage() { cout << "IntelMemory" << endl; }; };
class NVIDIACard : public Card { public: virtual void display() { cout << "NVIDIACard" << endl; }; };
class KingstonMemory :public Memory { public: virtual void storage() { cout << "KingstonMemory" << endl; }; };
int main(char *argv[], int argc) { Computer p1(new IntelCpu,new IntelCard,new IntelMemory); p1.print();
Computer p2(new IntelCpu, new NVIDIACard, new KingstonMemory); p2.print();
return 0; }
|