7.27多重继承派生类的构造函数

多重继承派生类的构造函数
#include<iostream>
using namespace std;
class Employee: public Person  
{public:
Employee(char *Name, char Sex, int Age, char *Num, char *Clerk, char *Depart, char *Timer): Person(Name, Sex, Age) 
{  strcpy(num, Num);  strcpy(clerk, Clerk);
strcpy(department, Depart);  strcpy(timer, Timer);
cout << " The constructor of derived class Employee is called."<< endl;
}
~ Employee( )       
{  cout << " The destructor of derived class Employee is called." << endl; } 
  void EShow( )
{   cout << "    employee's num: " << num << endl;
cout << "        clerk: " << clerk << endl;
cout << "        department:: " << department << endl;
cout << "        timer: " << timer << endl;
  }
void EmpShow( )
{   Show( );
cout << "    employee's num: " << num << endl;
cout << "             clerk: " << clerk << endl;
cout << "        department:: " << department << endl;
cout << "             timer: " << timer << endl;
  }
protected:                
   char num[8];          
   char clerk[20];        
   char department[30];  
   char timer[11];       
};
    
class GradOnWork: public Graduate, public Employee 
{public:
GradOnWork(char *Name, char Sex, int Age, char *Id, char *Date, float Score, 
  char *Direct, char *Teacher, char *Num, char *Clerk, char *Depart, 
  char *Timer): Graduate(Name, Sex, Age, Id, Date, Score, Direct, 
  Teacher), Employee(Name, Sex, Age, Num, Clerk, Depart, Timer)
{ cout << " The constructor of derived class GradOnWork is called."<< endl;  }
~GradOnWork( )       
{  cout << " The destructor of derived class GradOnWork is called." << endl; } 
void GWShow( )
{
cout << " Be the graduate:" << endl;
GradShow( );
cout << " Be the employee:" << endl;
EShow( );
}
};
int main( )
{   GradOnWork gw("Mary", 'F', 19, "20120101001", "2012.09.01", 680, "Computer", "Johnson", "JG01029", "Senior Engineer", "Research Department", "20 years");
gw.GWShow( );                  
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值