多个类之间的应用 C++

一个项目团队Team由一名业务经理BusinessManager、一名技术经理TechnicalManager和5个普通员工Employee组成。基于组合关系由成员类实现的思想,编码实现一个项目团队。为了简化实现,业务经理类BusinessManage、技术经理类TechnicalManager和普通员工类Employee的成员数据只包括编号id、姓名name和年龄age。

【要求】
业务经理类BusinessManage、技术经理类TechnicalManager和普通员工类Employee均给出带所有成员数据的构造函数和析构函数。

#include  <iostream>      
#include  <cstring>
using  namespace  std;    
class  BusinessManager
{
public:
            BusinessManager()
            {
                        cout<<"BusinessManager  Constructed  without  any  parameter."<<endl;
            }
            BusinessManager(int  pId,char*  pName,int  age);
            void  setBusinessManager(int  pId,char*  pName,int  pAge);
          ~BusinessManager();
            void  printBusinessManager();
private:
            int  id;
            char*  name;
            int  age;
};
BusinessManager::BusinessManager(int  pId,char*  pName,int  pAge)
{

id = pId;
    age = pAge;
    name = new char[strlen(pName) + 1];
    if (name != 0)
        strcpy(name, pName);

            cout<<"BusinessManager  Constructed  with  all  parameters."<<endl;
}
void  BusinessManager::setBusinessManager(int  pId,char*  pName,int  pAge)
{

id = pId;
    age = pAge;
    name = new char[strlen(pName) + 1];
    if (name != 0)
        strcpy(name, pName);

}
BusinessManager::~BusinessManager()
{

            cout<<"BusinessManager  Deconstructed."<<endl;
}
void  BusinessManager::printBusinessManager()
{
cout<<"id:  "<<id<<",  "<<"name:  "<<name<<",  "<<"age:  "<<age<<endl;
}
class  TechnicalManager{
public:
            TechnicalManager()
            {
                cout<<"TechnicalManager  Constructed  without  any  parameter."<<endl;
            }
            TechnicalManager(int  pId,char*  pName,int  pAge);
            void  setTechnicalManager(int  pId,char*  pName,int  pAge)
            {

id = pId;
    age = pAge;
    name = new char[strlen(pName) + 1];
    if (name != 0)
        strcpy(name, pName);

            }
          ~TechnicalManager();
            void  printTechnicalManager();
private:
            int  id;
            char*  name;
            int  age;
};
TechnicalManager::TechnicalManager(int  pId,char*  pName,int  pAge)
{

id = pId;
    age = pAge;
    name = new char[strlen(pName) + 1];
    if (name != 0)
        strcpy(name, pName);

            cout<<"TechnicalManager  Constructed  with  all  parameters."<<endl;
}
TechnicalManager::~TechnicalManager()
{

            cout<<"TechnicalManager  Deconstructed."<<endl;
}
void  TechnicalManager::printTechnicalManager()
{
            cout<<"id:  "<<id<<",  "
                      <<"name:  "<<name<<",  "
                      <<"age:  "<<age<<endl;
}
class  Employee
{
public:
            Employee()
            {
                        cout<<"Employee  Constructed  without  any  parameter."<<endl;
            }
            Employee(int  pId,char*  pName,int  age);
            ~Employee();
            void  setEmployee(int  pId,char*  pName,int  age);
            void  printEmployee();
private:
            int  id;
            char*  name;
            int  age;
};
Employee::Employee(int  pId,char*  pName,int  pAge)
{

id = pId;
    age = pAge;
    name = new char[strlen(pName) + 1];
    if (name != 0)
        strcpy(name, pName);

            cout<<"Employee  Constructed  with  all  parameters."<<endl;
}
void  Employee::setEmployee(int  pId,char*  pName,int  pAge)
{

id = pId;
    age = pAge;
    name = new char[strlen(pName) + 1];
    if (name != 0)
        strcpy(name, pName);

}
Employee::~Employee()
{

            cout<<"Employee  Deconstructed."<<endl;
}
void  Employee::printEmployee()
{
            cout<<"id:  "<<id<<",  "
                      <<"name:  "<<name<<",  "
                      <<"age:  "<<age<<endl;
}
class  Team
{
public:
            Team()
            {
                        cout<<"Team  Constructed."<<endl;
            }
            void  printTeam()
            {
 bm.printBusinessManager();
        tm.printTechnicalManager();
        e[0].printEmployee();
        e[1].printEmployee();
        e[2].printEmployee();
        e[3].printEmployee();
        e[4].printEmployee();
        e[5].printEmployee();

            }
public:
            BusinessManager  bm;
            TechnicalManager  tm;
            Employee  e[6];
};
int  main()
{
            Team  t;
            t.bm.setBusinessManager(1001,"zhangsan_BM",32);
            t.tm.setTechnicalManager(1002,"lisi_TM",31);
            t.e[0].setEmployee(2000,"wang0_EMP",24);
            t.e[1].setEmployee(2001,"wang1_EMP",22);
            t.e[2].setEmployee(2002,"wang2_EMP",23);
            t.e[3].setEmployee(2003,"wang3_EMP",22);
            t.e[4].setEmployee(2004,"wang4_EMP",25);
            t.e[5].setEmployee(2005,"wang5_EMP",20);
            t.printTeam();
            return  0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值