#include <iostream>
using namespace std;
class CPerson
{
protected:
char *m_szName;
char *m_szId;
int m_nSex;//0:women,1:man
int m_nAge;
public:
CPerson(char *name,char *id,int sex,int age);
void Show1();
~CPerson();
};
void CPerson::Show1()
{
cout<<"name id sex age department salary"<<endl;
}
CPerson::CPerson(char *name,char *id,int sex,int age)
{
m_szName=new char[10];
m_szId=new char[19];
m_szName=name;
m_szId=id;
m_nSex=sex;
m_nAge=age;
}
CPerson::~CPerson()
{
delete[]m_szId;
delete[]m_szName;
}
class CEmployee:public CPerson
{
private:
char *m_szDepartment;
float m_Salary;
public:
CEmployee(char *name,char *id,int sex,int age,char *department,float salary);
void Show2();
~CEmployee();
};
CEmployee::~CEmployee()
{
delete[]m_szDepartment;
}
CEmployee::CEmployee(char* name,char* id,int sex,int age,char* department,float salary):CPerson(name,id,sex,age){m_szDepartment=new char[10];m_szDepartment=department;m_Salary=salary;}
void CEmployee::Show2()
{
char* a;
a=new char[5];
Show1();
if(m_nSex==0)
a="woman";
if(m_nSex==1)
a="man";
cout<<m_szName<<" "<<m_szId<<" "<<a<<" "<<m_nAge<<" "<<m_szDepartment<<" "<<m_Salary;
}
int main()
{
char name[10],id[19],department[10];
int sex,age;
float salary;
cout<<"input employee's name,id,sex(0:women,1:man),age,department,salary:\n";
cin>>name>>id>>sex>>age>>department>>salary;
CEmployee employee1(name,id,sex,age,department,salary);
employee1.Show2();
return 0;
}
第11周项目2(2)职员有薪水了
最新推荐文章于 2021-12-02 23:17:44 发布