Shelyin 2021-10-29 17:02 采纳率: 100%
浏览 113
已结题

一道C++编程设计,搞不明白

设计一个程序,包含公司类( company )和员工类( employee ),其中:
1)一个公司有5名员工:2)公司有名字、类型、地址等属性;3)公司具有对外宣传、外派员工等行为:4)员工有姓名、职位、性别、年龄、工号,是否打卡等属性:5)员工具有完成工作、打卡等行为:6完成主函数的编写,并在主函数中完成 company 对外宜传和外派员工等工作。

  • 写回答

2条回答 默认 最新

  • 关注

    代码如下,如有帮助,请帮忙采纳一下,谢谢。

    #include <iostream>
    #include <string>
    using namespace std;
    
    class employee
    {
    private:
        string mName;
        string mZw;  //职位
        string mSex;
        int mAge;
        string mNmb; //工号
    public:
        employee(){}
        employee(string name,string zw,string sex,int age,string id){
            mName = name; 
            mZw = zw;
            mSex = sex;
            mAge = age;
            mNmb = id;
        }
        void work(){
            cout << mName << "正在工作"<<endl;
        }
        void card(){
            cout << mName << "打卡" <<endl;
        }
        
        //get an set
        void setName(string s){mName = s;}
        void setZw(string s){mZw = s;}
        void setSex(string s){mSex = s;}
        void setAge(int a){mAge = a;}
        void setNmb(string nmb){mNmb = nmb;}
    
        string getName(){return mName;}
        string getZw(){return mZw;}
        string getSex(){return mSex;}
        int getAge(){return mAge;}
        string getNmb(){return mNmb;}
    };
    
    class company 
    {
    private:
        employee mEmp[5];
        string mName;
        string mType;
        string mAddr;
        int nNmb;
    public:
        company(){nNmb = 0;}
        void xuchuan(){
            cout << mName << "是个好公司"<<endl;
        }
        void waipai()
        {
            int n,i;
            cout << "请输入外派员工的数量:";
            cin >> n;
            if (n>5)
            {
                cout << "公司没有那么多人"<<endl;
                return ;
            }
            cout << "外派人员:"<<endl;
            for(i=0;i<n;i++)
            {
                cout << "  姓名:" << mEmp[i].getName() <<  "  年龄:" << mEmp[i].getAge()<<endl;
            }
        }
        //
        void setName(string s){mName = s;}
        void setType(string t){mType = t;}
        void setAddr(string addr){mAddr = addr;}
        void setEmp(employee a[],int n)
        {
            nNmb = n;
            for(int i = 0;i<n;i++)
                mEmp[i] = a[i];
        }
    
        string getName(){return mName;}
        string getType(){return mType;}
        string getAddr(){return mAddr;}
        void getEmp(employee a[],int &nmb)
        {
            for(int i = 0;i< nNmb;i++)
                a[i] = mEmp[i];
        }
        void addEmp(employee e)
        {
            if(nNmb < 5)
            {
                mEmp[nNmb] = e;
                nNmb++;
            }
        }
    };
    
    
    
    
    int main()
    {
        employee a1("张一","经理","男",33,"00001");
        employee a2("张二","经理","男",34,"00002");
        employee a3("张三","经理","男",35,"00003");
        employee a4("张四","经理","男",36,"00004");
        employee a5("张五","经理","男",37,"00005");
        company cp;
        cp.setName("搞笑有效公司");
        cp.setType("娱乐");
        cp.setAddr("远在天边");
        cp.addEmp(a1);
        cp.addEmp(a2);
        cp.addEmp(a3);
        cp.addEmp(a4);
        cp.addEmp(a5);
        cp.xuchuan();
        cp.waipai();
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 11月6日
  • 已采纳回答 10月29日
  • 创建了问题 10月29日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度