/*
* 程序的版權和版本聲明部分
* 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 ;
}
實力是不斷訓練出來的。