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
| #include<iostream> #include<cstring> using namespace std;
class CPU { private: string fy, ty; public: CPU() : fy("Unknown"), ty("Unknown") { cout << "Function #1 is called!" << endl; } CPU(string a, string b) : fy(a), ty(b) { cout << "Function #2 is called!" << endl; } CPU(const CPU& tmp) : fy(tmp.fy), ty(tmp.ty) { } void Show() const { cout << fy << " " << ty << endl; cout << "Function #3 is called!" << endl; } }; class Computer : public CPU { private: string brand, type; int ram, price; public: Computer() : brand("None"), type("None"), ram(0), price(0) { cout << "Function #4 is called!" << endl; } Computer(string a, string b, int r, int p, string c, string d) : CPU(c, d), brand(a), type(b), ram(r), price(p) { cout << "Function #5 is called!" << endl; } Computer(string a, string b, int r, int p, const CPU& tmp) : CPU(tmp), brand(a), type(b), ram(r), price(p) { cout << "Function #6 is called!" << endl; } Computer(string a, string b, int r, int p) : brand(a), type(b), ram(r), price(p) { cout << "Function #7 is called!" << endl; } Computer(const CPU& tmp) : CPU(tmp), brand("None"), type("None"), ram(0), price(0) { cout << "Function #8 is called!" << endl; } void Show() const { cout << "Brand:" << brand << " Type:" << type << " Memory:" << ram << " Price:" << price; cout << " CPU:"; CPU :: Show(); cout << "Function #9 is called!" << endl; } };
int main() { char s1[40],s2[40],s3[40],s4[40]; int ram,price; cin>>s1>>s2>>ram>>price>>s3>>s4;
CPU cpu0; cout<<"CPU 0:"; cpu0.Show(); CPU cpu1(s3,s4); cout<<"CPU 1:"; cpu1.Show(); Computer computer0; cout<<"Computer0: "; computer0.Show(); Computer computer1(s1,s2,ram,price,s3,s4); cout<<"Computer1: "; computer1.Show(); Computer computer2(s1,s2,ram,price,cpu1); cout<<"Computer2: "; computer2.Show(); Computer computer3(s1,s2,ram,price); cout<<"Computer3: "; computer3.Show(); Computer computer4(cpu1); cout<<"Computer4: "; computer4.Show(); return 0; }
|