Problem 1469. -- 继承派生(8)--人员和教师类

1469: 继承派生(8)--人员和教师类

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

Description

Person类包含私有成员数据姓名、性别和年龄。Person类包含若干成员函数(如下所示)。
class Person
{
    private:
        char name[20];
        char sex[3];
        int age;
    public:
        Person();
        Person(char *n,char *s,int a);
        char *GetName();
        char *GetSex();
        int GetAge();
        void Show();
};
Teacher类由Person类公有派生而来,包含私有成员数据职称(title)和工资(pay)。Teacher类包含若干成员函数(如下所示)。
class Teacher:public Person
{
    private:
        char title[20];
        int pay;
    public:
        Teacher();
        Teacher(char *n,char *s,int a,char *t,int p);
        Teacher(Person p1,char *t,int p);
        Teacher(char *t,int p);
        Teacher(Person p1);
        void Show();
};
完成上述各成员函数的设计。main函数已给定(如下所示),提交时只需要提交main函数外的代码部分。
int main()
{
    char name[20],sex[3],title[20];
    int age,pay,cas=0;
    Person p1;
    Teacher t1;
    cout<<"P1:";    p1.Show();
    cout<<"T1:";    t1.Show();
    while(cin>>name>>sex>>age>>title>>pay)
    {
        cas++;
        cout<<"Case #"<<cas<<":"<<endl;
        Person p2(name,sex,age);
        Teacher t2(name,sex,age,title,pay);
        Teacher t3(p2,title,pay);
        Teacher t4(title,pay);
        Teacher t5(p2);
        cout<<"P2:";    p2.Show();
        cout<<"T2:";    t2.Show();
        cout<<"T3:";    t3.Show();
        cout<<"T4:";    t4.Show();
        cout<<"T5:";    t5.Show();
    }
    return 0;
}

Input

包含多组数据(数据均正确合法)
每组测试数据1行,每行包括姓名(字符串)、性别(字符串)、年龄(整数)、职称(字符串)和工资(整数)。

Output

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

Sample Input

张三 男 35 副教授 3000

Sample Output

Function #1 is called!
Function #1 is called!
Function #4 is called!
P1:Unknown/No/0
Function #3 is called!
T1:Unknown/No/0/Unknown/0
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!
P2:张三/男/35
Function #3 is called!
T2:张三/男/35/副教授/3000
Function #9 is called!
T3:张三/男/35/副教授/3000
Function #9 is called!
T4:Unknown/No/0/副教授/3000
Function #9 is called!
T5:张三/男/35/Unknown/0
Function #9 is called!

[Submit][Status][Web Board]