您的位置:首页 > 其它

项目2-职员有薪水了(1)(第10,11周补充项目)

2016-05-19 08:54 441 查看
*Copyright (c) 2014,烟台大学计算机学院

*All right reserved.

*文件名称:test.cpp

*作 者:韩双志

*完成日期:2016年5月19日

*版本号:v1.0

*

*问题描述:定义一个名为CPerson的类,有以下私有成员:姓名、身份证号、性别和年龄,成员函数:构造函数、析构函数、输出信息的函数。并在此基础上派生出CEmployee类,派生类CEmployee增加了两个新的数据成员,分别用于表示部门和薪水。要求派生类CEmployee的构造函数显示调用基类CPerson的构造函数,并为派生类CEmployee定义析构函数,定义输出信息的函数

*输入描述:输入姓名,ID,性别,专业,薪水

*输出描述:输出姓名,ID,性别,专业,薪水

/*

#include <iostream>

#include<cstring>

using namespace std;

class CPerson//员工信息

{

protected:

string m_szName;

string m_szId;

string m_nSex;//0:women,1:man

int m_nAge;

public:

CPerson(string name,string id,string sex,int age);//复制构造函数

void Show1();

~CPerson();//析构函数

};

class CEmployee:public CPerson

{

private:

string m_szDepartment;//专业

double m_Salary;//薪水

public:

CEmployee(string name,string id,string sex,int age,string department,double salary);

void Show2();

~CEmployee();

};

//复制构造函数的实现

CPerson::CPerson(string name,string id,string sex,int age):m_szName(name),m_szId(id),m_nSex(sex),m_nAge(age){}

CEmployee::CEmployee(string name,string id,string sex,int age,string department,double salary):CPerson(name,id,sex,age),

m_szDepartment(department),m_Salary(salary){}

void CPerson::Show1()//输出的信息

{

cout<<"name "<<"id "<<"sex "<<"age "<<"deparment "<<"salary"<<endl;

cout<<m_szName<<" "<<m_szId<<" "<<m_nSex<<" "<<m_nAge<<" " ;

}

CPerson::~CPerson()//析构函数

{

cout<<endl;

}

void CEmployee::Show2()

{

CPerson::Show1();

cout<<m_szDepartment<<" "<<m_Salary<<" "<<endl;

}

CEmployee::~CEmployee()//析构函数的实现

{

cout<<"半:"<<endl;

}

int main()

{

string name,id,department;

string sex;

int age;

double 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;

}

*/

运行结果:



知识点结构:

类的继承,类的派生

学习心得

学会了类的继承,与类的派生
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: