设计一个程序,包含公司类( company )和员工类( employee ),其中:
1)一个公司有5名员工:2)公司有名字、类型、地址等属性;3)公司具有对外宣传、外派员工等行为:4)员工有姓名、职位、性别、年龄、工号,是否打卡等属性:5)员工具有完成工作、打卡等行为:6完成主函数的编写,并在主函数中完成 company 对外宜传和外派员工等工作。
代码如下,如有帮助,请帮忙采纳一下,谢谢。
#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;
}
你按照每个类的属性和方法,定义出公司类和员工类就可以了啊。主要困难在哪里