第七次项目3实验

来源:互联网 发布:淘宝卖什么吃的赚钱 编辑:程序博客网 时间:2024/05/16 15:03

一、问题及代码

#include<iostream>#include<string>using namespace std;class CPerson  {  protected:      string m_szName;      string m_szId;      int m_nSex;//0:女,1:男      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(){cout<<"姓名"<<"\t"<<"id"<<"\t"<<"性别"<<"\t"<<"年龄"<<"\t"<<"部门"<<"\t"<<"薪水"<<endl;cout<<m_szName<<"\t"<<m_szId<<"\t"<<m_nSex<<"\t"<<m_nAge<<"\t";};  };    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();  }; void CEmployee::Show2(){Show1();cout<<m_szDepartment<<"\t"<<m_Salary<<endl;}int main()  {      string name,id,department;      int sex,age;      double salary;      cout<<"请输入雇员的姓名,ID,性别(0:女,1:男),年龄,部门,薪水:\n";      cin>>name>>id>>sex>>age>>department>>salary;      CEmployee employee1(name,id,sex,age,department,salary);      employee1.Show2();      return 0;  } 


二、运行结果


三、心得体会

大小写一定要分开,名字太繁琐要注意仔细。到底该如何调用,还需要熟练掌握。

四、知识点归纳

继承的格式

调用的格式

初始化列表的格式

原创粉丝点击