第十一週(專案二)——職員有薪水了。
阿新 • • 發佈:2019-02-11
/* 02.*煙臺大學計算機學院學生 03.*All right reserved. 04.*檔名稱*煙臺大學計算機學院學生 05.*All right reserved. 06.*檔名稱:職員有薪水了 07.*作者:王洪海 08.*完成日期:2013年5月13日 09.*版本號:v1.0 10.*對任務及求解方法的描述部分:職員有薪水了 11.*我的程式: 12.*/ #include<iostream> #include<string> 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 showsex() { if(m_nSex==0) cout<<"女"<<endl; else if(m_nSex==1) cout<<"男"<<endl; } void Show1() { cout<<"姓名:"<<m_szName<<endl; cout<<"身份證:"<<m_szId<<endl; cout<<"性別:"; showsex(); cout<<"年齡:"<<m_nAge<<endl; } ~CPerson(){} }; 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() { Show1(); cout<<"部門:"<<m_szDepartment<<endl; cout<<"薪水:"<<m_Salary<<endl; } ~CEmployee(){} }; int main() { string name,id,department; int sex,age; double salary; cout<<"請輸入這個職員的姓名,身份證,性別,年齡,部門,薪水:\n"; cin>>name>>id>>sex>>age>>department>>salary; CEmployee employee1(name,id,sex,age,department,salary); employee1.Show2(); return 0; }
執行結果,如下圖: