设计一个用于人事管理的People(人员)类。考虑到通用性,这里只抽象出所有类类型人员都具有的属性:number(编号)、sex(性别)、birthday(出生日期)、id(身份证号)等。其中"出生日期"定义为一个"日期"类内嵌子对象。用成员函数实现对人员信息的录入和显示。
要求包括:构造函数和析构函数、带缺省形参值的成员函数等实现。
#include<iostream> using namespace std; class Date{ private: int m_year; int m_month; int m_day; public: Date(int year ,int month, int day){ m_year=year; m_month=month; m_day=day; cout<<"年:"<<m_year<<" 月:"<<m_month<<" 日:"<<m_day<<endl; } }; class P1{ protected: int m_number; char *m_sex; long long m_id; public: P1(int number, char *sex, long long id){ m_number=number; m_sex=sex; m_id=id; cout<<"编号:"<<m_number<<endl<<"性别:"<<m_sex<<endl<<"身份证:"<<m_id<<endl; } }; class People:public Date,public P1{ public: People(); ~People(); }; int main(){ Date DD(1999,10,10); P1 PP(1,"F",411303199910102222); return 0; }