C++第11周(春)项目2 - 职员有薪水了

/*
* 程序的版权和版本声明部分
* Copyright (c)2014, 在校学生
* All rightsreserved.
* 文件名称: 1.cpp
* 作    者:  刘旺
* 完成日期:2014年5月9日
* 版本号: v1.0
* 输入描述:无
* 问题描述:   定义一个名为CPerson的类,有以下私有成员:姓名、身份证号、性别和年龄,成员函数
             :构造函数、析构函数、输出信息的函数。并在此基础上派生出CEmployee类,
               派生类CEmployee增加了两个新的数据成员,分别用于表示部门和薪水。
              要求派生类CEmployee的构造函数显示调用基类CPerson的构造函数,
               并为派生类CEmployee定义析构函数,定义输出信息的函数
*/

#include <iostream>
using namespace std ;

class Cperson{
   protected :
             string m_szName ;//姓名
             string m_size ;//  身份证号
             int n_Sex ; //性别
             int m_nAge ;   //年龄
   public :
          Cperson(string m_sz , string m_si , int n , int m) ; //构造函数
          void show() ;  //输出成员
          ~Cperson() ; //析构函数
};

Cperson::Cperson(string m_sz , string m_si , int n , int m):m_szName(m_sz),m_size(m_si),n_Sex(n),m_nAge(m)
{
}

void Cperson::show()
{

      cout  << m_szName << "      " << m_size << "      " ;
      if(n_Sex==0){cout << "women" ;}
      else{cout << "man" ;}
      cout << "     " << m_nAge << "       "  ;
}

Cperson::~Cperson()
{
}

class Cemployee:public Cperson{
    private :
      string m_szDeparment ; //部门
      double m_Salary ;   //薪水
    public:
        Cemployee(string m_sz , string m_si , int n , int m, string m_d , double m_Sa) ;
        void Show2() ;
        ~Cemployee() ;
};

Cemployee::Cemployee(string m_sz , string m_si , int n , int m, string m_d , double m_Sa):Cperson(m_sz , m_si ,n,m)
{
              m_szDeparment = m_d ;
              m_Salary = m_Sa ;
}

void Cemployee::Show2()
{
    show() ;
    cout << "  " << m_szDeparment << "      " << m_Salary << endl ;
}

Cemployee::~Cemployee()
{
}

int main()
{
   string name ,id, department ;
   int sex , age ;
   double salary ;
   cout << "input employee's name , id , sex(0:women, 1:man),age,deparment ,salary:\n" ;
   cin >> name >> id >> sex >> age >> department >> salary ;
   Cemployee employee(name , id  , sex , age , department , salary ) ;
   cout << "姓名      身份证                性别    年龄     部门       薪水"  << endl ;
   employee.Show2() ;
   return 0 ;
}

实力是不断训练出来的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章