Problem 1464. -- 继承派生(3)--CPU类和计算机类

1464: 继承派生(3)--CPU类和计算机类

Time Limit: 10 Sec  Memory Limit: 65535 MB   64bit IO Format: %lld
Submitted: 1259  Accepted: 482
[Submit][Status][Web Board]

Description

CPU类包含私有成员数据CPU品牌和型号(char factory[40],type[40])。CPU类包含若干成员函数(如下所示)。
class CPU
{
    private:
        char factory[40];
        char type[40];
    public:
        CPU();
        CPU(char *f,char *t);
        void Show();
};
计算机类Computer由CPU类公有派生而来,包含私有成员数据计算机品牌(char factory[40])、型号(char type[40])、内存大小(int ram)和价格(int price)。Computer类包含若干成员函数(如下所示)。
class Computer:public CPU
{
    private:
        char factory[40];
        char type[40];
        int ram;
        int price;
    public:
        Computer();
        Computer(char *s1,char *s2,int r,int p,char *s3,char *s4);
        Computer(char *s1,char *s2,int r,int p,CPU c);
        Computer(char *s1,char *s2,int r,int p);
        Computer(CPU c);
        void Show();
};
完成上述各成员函数的设计。main函数已给定(如下所示),提交时只需要提交main函数外的代码部分。
int main()
{
    char s1[40],s2[40],s3[40],s4[40];
    int r,p;
    int cas=0;
    CPU cpu0;
    Computer computer0;
    cout<<"CPU 0:"; cpu0.Show();
    cout<<"Computer0: ";  computer0.Show();
    while(cin>>s1>>s2>>r>>p>>s3>>s4)
    {
        cas++;
        cout<<"Case #"<<cas<<":"<<endl;
        CPU cpu1(s3,s4);
        Computer computer1(s1,s2,r,p,s3,s4);
        Computer computer2(s1,s2,r,p,cpu1);
        Computer computer3(s1,s2,r,p);
        Computer computer4(cpu1);
        cout<<"CPU 1: "; cpu1.Show();
        cout<<"Computer1: "; computer1.Show();
        cout<<"Computer2: "; computer2.Show();
        cout<<"Computer3: "; computer3.Show();
        cout<<"Computer4: "; computer4.Show();
    }
    return 0;
}

Input

包含多组数据(数据均正确合法)
每组测试数据1行,每行包括字符串(计算机品牌factory)、字符串(计算机型号)、整数(内存大小)、整数(计算机价格)、字符串(CPU品牌)和字符串(CPU型号)。

Output

每组测试数据输出具体格式详见Sample Output。

Sample Input

联想(Lenovo) IdeaCentre(C560) 4 4199 英特尔 酷睿(i3-4160T)

Sample Output

Function #1 is called!
Function #1 is called!
Function #4 is called!
CPU 0:Unknown Unknown
Function #3 is called!
Computer0: 品牌:Unknown 型号:Unknown 内存:0G  价格:0元 CPU:Unknown Unknown
Function #3 is called!
Function #9 is called!
Case #1:
Function #2 is called!
Function #2 is called!
Function #5 is called!
Function #6 is called!
Function #1 is called!
Function #7 is called!
Function #8 is called!
CPU 1: 英特尔 酷睿(i3-4160T)
Function #3 is called!
Computer1: 品牌:联想(Lenovo) 型号:IdeaCentre(C560) 内存:4G  价格:4199元 CPU:英特尔 酷睿(i3-4160T)
Function #3 is called!
Function #9 is called!
Computer2: 品牌:联想(Lenovo) 型号:IdeaCentre(C560) 内存:4G  价格:4199元 CPU:英特尔 酷睿(i3-4160T)
Function #3 is called!
Function #9 is called!
Computer3: 品牌:联想(Lenovo) 型号:IdeaCentre(C560) 内存:4G  价格:4199元 CPU:Unknown Unknown
Function #3 is called!
Function #9 is called!
Computer4: 品牌:Unknown 型号:Unknown 内存:0G  价格:0元 CPU:英特尔 酷睿(i3-4160T)
Function #3 is called!
Function #9 is called!

[Submit][Status][Web Board]