//日期类 class Date { public: Date(int year = 1970, int month = 1, int day = 1) : m_year(year), m_month(month), m_day(day) {} void setDate(int year, int month, int day) { m_year = year; m_month = month; m_day = day; } void printDate() const { std::cout << m_year << '-' << m_month << '-' << m_day << std::endl; } private: int m_year; int m_month; int m_day; };

//人员类 class People { public: People(int number = 0, char sex = 'M', const Date& birthday = Date(), const std::string& id = "") : m_number(number), m_sex(sex), m_birthday(birthday), m_id(id) {} People(const People& other) : m_number(other.m_number), m_sex(other.m_sex), m_birthday(other.m_birthday), m_id(other.m_id) {} ~People() {} inline int getNumber() const { return m_number; } inline char getSex() const { return m_sex; } inline Date getBirthday() const { return m_birthday; } inline std::string getId() const { return m_id; } void setNumber(int number) { m_number = number; } void setSex(char sex) { m_sex = sex; } void setBirthday(const Date& birthday) { m_birthday = birthday; } void setId(const std::string& id) { m_id = id; } void printInfo() const { std::cout << "Number: " << m_number << std::endl; std::cout << "Sex: " << m_sex << std::endl; std::cout << "Birthday: "; m_birthday.printDate(); std::cout << "ID: " << m_id << std::endl; } private: int m_number; char m_sex; Date m_birthday; std::string m_id; };

//测试代码 int main() { Date date(1990, 1, 1); People p(1, 'M', date, "123456789012345678"); p.printInfo(); return 0; }

C++ 人员管理系统:设计 People 类实现人员信息录入和显示

原文地址: https://www.cveoy.top/t/topic/nizR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录