用c++设计一个用于人事管理的People类,包含number(编号)、sex(性别)、birthday(出生日期)、id(身份证号)等属性,“出生日期”声明为一个“日期”类内嵌子对象,用成员函数实现对人员信息的录入和显示,要求包括:构造函数、析构函数、复制构造函数、内联成员函数、带默认形参值的成员函数、类的组合
时间: 2023-05-28 13:02:26 浏览: 128
#include<iostream>
#include<string>
using namespace std;
class Date {
private:
int year, month, day;
public:
Date(int y = 1900, int m = 1, int d = 1):year(y), month(m), day(d){};
friend ostream& operator<<(ostream& os, const Date& d);
};
ostream& operator<<(ostream& os, const Date& d) {
os << d.year << "-" << d.month << "-" << d.day;
return os;
}
class People {
private:
string number;
string sex;
Date birthday;
string id;
public:
People(string n, string s, int y, int m, int d, string i):number(n), sex(s), birthday(y,m,d), id(i){};
People(const People& p) :number(p.number), sex(p.sex), birthday(p.birthday), id(p.id) {};
~People() {};
inline string getNumber() const{ return number; };
inline string getSex() const { return sex; };
inline Date getBirthday() const { return birthday; };
inline string getId() const { return id; };
void show() {
cout << "编号:" << number << endl;
cout << "性别:" << sex << endl;
cout << "出生日期:" << birthday << endl;
cout << "身份证号:" << id << endl;
};
};
int main() {
People p("20190101", "男", 1990, 10, 1, "430************");
People p1(p);
p.show();
p1.show();
return 0;
}
阅读全文