本文主要是介绍1479: 多重继承派生(3)--person、account、admin和master类,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1479: 多重继承派生(3)--person、account、admin和master类
Description
Input
Output
每组测试数据输出具体格式详见Sample Output。
Sample Input
张三 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;
}
这篇关于1479: 多重继承派生(3)--person、account、admin和master类的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!