第二学期第11周项目2--职员有薪水了(1)

来源:互联网 发布:淘宝店工商注册 编辑:程序博客网 时间:2024/05/16 10:16
/* * Copyright (c) 2013, 烟台大学计算机学院 * All rights reserved. * 作    者:  沈远宏 * 完成日期:2014年05月06日 * 版 本 号:v1.0 * 问题描述:定义一个名为CPerson的类,有以下私有成员:姓名、身份证号、性别和年龄,成员函数:构造函数、析构函数、输出信息的函数。             并在此基础上派生出CEmployee类,派生类CEmployee增加了两个新的数据成员,分别用于表示部门和薪水。要求派生类CEmployee             的构造函数显示调用基类CPerson的构造函数,并为派生类CEmployee定义析构函数,定义输出信息的函数。 * 输出:职员的信息*/#include <iostream>using namespace std;class CPerson{protected:    string m_szName;  //姓名    string m_szId; //身份证号    int m_nSex;//0:women,1:man //性别    int m_nAge;  //年龄public:    CPerson(string name,string id,int sex,int age):m_szName(name),m_szId(id),m_nSex(sex),m_nAge(age){}    void Show1();    ~CPerson()    {        cout<<"已释放1"<<endl;    }};class CEmployee:public CPerson{private:    string m_szDepartment;  //部门    double m_Salary;  //薪水public:    CEmployee(string name,string id,int sex,int age,string department,double salary):CPerson(name,id,sex,age),m_szDepartment(department),m_Salary(salary){}    void Show2();    ~CEmployee()    {        cout<<"已释放2"<<endl;    }};void CPerson::Show1(){    cout<<"姓名  "<<m_szName<<"\t身份证号  "<<m_szId;    if(m_nSex==0)    {     cout<<"\t性别  女";    }    else    {       cout<<"\t性别  男";    }    cout<<"\t年龄  "<<m_nAge<<endl;}void CEmployee::Show2(){    Show1();    cout<<"该职员的部门为  "<<m_szDepartment<<"\t薪水为  "<<m_Salary<<endl;}int main(){    string name,id,department;    int sex,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;}


运行结果:

心得体会:

希望以后工作的地方统计我的工资能有好多0

0 0