1479: 多重继承派生(3)--person、account、admin和master类
Description
Input
Output
每组测试数据输出具体格式详见Sample Output。
Sample Input ![](http://acm.wust.edu.cn/image/copy.gif)
张三 201506 2541 绘画
王大夫 2012510 3654 跳舞
殷文琦 1005210 5412 写代码编程
Sample Output
CASE #1:
Person::Constructor Function is called.
Person::Constructor Function is called.
Account::Constructor Function is called.
Person::Constructor Function is called.
Admin::Constructor Function is called.
Person::Constructor Function is called.
Account::Constructor Function is called.
Admin::Constructor Function is called.
Master::Constructor Function is called.
Show Function is called.
Person::Show Function is called.
NAME:张三 CODE:201506
Show Function is called.
Account::Show Function is called.
NAME:张三 CODE:201506 PAY:2541
Show Function is called.
Admin::Show Function is called.
NAME:张三 CODE:201506 EXPERIENCE:绘画
Show Function is called.
Master::Show Function is called.
NAME:张三 CODE:201506 PAY:2541 EXPERIENCE:绘画
CASE #2:
Person::Constructor Function is called.
Person::Constructor Function is called.
Account::Constructor Function is called.
Person::Constructor Function is called.
Admin::Constructor Function is called.
Person::Constructor Function is called.
Account::Constructor Function is called.
Admin::Constructor Function is called.
Master::Constructor Function is called.
Show Function is called.
Person::Show Function is called.
NAME:王大夫 CODE:2012510
Show Function is called.
Account::Show Function is called.
NAME:王大夫 CODE:2012510 PAY:3654
Show Function is called.
Admin::Show Function is called.
NAME:王大夫 CODE:2012510 EXPERIENCE:跳舞
Show Function is called.
Master::Show Function is called.
NAME:王大夫 CODE:2012510 PAY:3654 EXPERIENCE:跳舞
CASE #3:
Person::Constructor Function is called.
Person::Constructor Function is called.
Account::Constructor Function is called.
Person::Constructor Function is called.
Admin::Constructor Function is called.
Person::Constructor Function is called.
Account::Constructor Function is called.
Admin::Constructor Function is called.
Master::Constructor Function is called.
Show Function is called.
Person::Show Function is called.
NAME:殷文琦 CODE:1005210
Show Function is called.
Account::Show Function is called.
NAME:殷文琦 CODE:1005210 PAY:5412
Show Function is called.
Admin::Show Function is called.
NAME:殷文琦 CODE:1005210 EXPERIENCE:写代码编程
Show Function is called.
Master::Show Function is called.
NAME:殷文琦 CODE:1005210 PAY:5412 EXPERIENCE:写代码编程
代码:
#include <iostream>
#include <string>
using namespace std;
class Person
{
public:
Person(string name,int code):name(name),code(code)
{
cout<<"Person::Constructor Function is called."<<endl;
}
virtual void Show()
{
cout<<"Person::Show Function is called."<<endl;
cout<<"NAME:"<<name<<" CODE:"<<code<<endl;
}
string GetName()
{
return name;
}
int GetCode()
{
return code;
}
private:
string name;
int code;
};
class Account:virtual public Person
{
public:
Account(string name,int code,int pay):Person(name,code),pay(pay)
{
cout<<"Account::Constructor Function is called."<<endl;
}
void Show()
{
cout<<"Account::Show Function is called."<<endl;
cout<<"NAME:"<<GetName()<<" CODE:"<<GetCode()<<" PAY:"<<pay<<endl;
}
int GetPay()
{
return pay;
}
private:
int pay;
};
class Admin:virtual public Person
{
public:
Admin(string name,int code,string experience):Person(name,code),experience(experience)
{
cout<<"Admin::Constructor Function is called."<<endl;
}
void Show()
{
cout<<"Admin::Show Function is called."<<endl;
cout<<"NAME:"<<GetName()<<" CODE:"<<GetCode()<<" EXPERIENCE:"<<experience<<endl;
}
string GetExperience()
{
return experience;
}
private:
string experience;
};
class Master:public Account,public Admin
{
public:
Master(string name,int code,int pay,string experience):Person(name,code),Account(name,code,pay),Admin(name,code,experience)
{
cout<<"Master::Constructor Function is called."<<endl;
}
void Show()
{
cout<<"Master::Show Function is called."<<endl;
cout<<"NAME:"<<GetName()<<" CODE:"<<GetCode()<<" PAY:"<<GetPay()<<" EXPERIENCE:"<<GetExperience()<<endl;
}
};
void Show(Person* p)
{
cout<<"Show Function is called."<<endl;
p->Show();
}
int main()
{
string name,experience;
int code,pay,Cas=0;
while(cin>>name>>code>>pay>>experience)
{
Cas++;
cout<<"CASE #"<<Cas<<":"<<endl;
Person person(name,code);
Account account(name,code,pay);
Admin admin(name,code,experience);
Master master(name,code,pay,experience);
Show(&person);
Show(&account);
Show(&admin);
Show(&master);
}
return 0;
}