多个类之间的应用 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;
}
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在C DLL设计中实现多个功能一般有两种方式,一种是将所有功能都放在一个DLL中,另一种是将不同功能拆分到多个DLL中。 第一种方式即是将多个不同的功能写在同一个DLL中。这种方式的好处是简单易用,使用者只需要添加一个DLL文件即可调用各种不同的功能。这种方式也能够避免文件过多的问题,对于小型的项目来说比较适用。 但是这种方式也有其不足之处。由于多个功能都写在同一个DLL中,若其中一个功能出现问题,整个DLL文件都会受到影响,这会导致其他功能也无法正常使用。此外,风险也会增加,因为如果黑客攻击到某一个功能的代码,那么整个文件都会受到攻击。 另外一种方式是将不同的功能拆分到不同的DLL中,这种方式是针对大型项目或者需要支持多个平台的情况下不可避免的选择。将不同的功能拆分到不同的DLL中,不同功能之间可以独立开发和测试,与其它功能之间没有影响,能够避免单个文件出现问题就会影响到系统的问题。 但是,这种方式也需要注意一些问题。如何保证不同功能之间能够正常的调用和协作,如何将不同的DLL与系统成功集成是需要掌握的技能。需要注意的是,尽量不要让DLL文件太多,这样会增加操作复杂性和占用系统资源的问题。 总之,选择哪种方式实现多个功能一般需要根据实际需要来进行选择和权衡,灵活应用

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值