123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #include <iostream>
- #include <cstring>
- class Date {
- public:
- int year, month, day;
- Date(int y = 0, int m = 0, int d = 0) : year(y), month(m), day(d) {}
- void input() {
- std::cin >> year >> month >> day;
- }
- void display() const {
- std::cout << year << "年" << month << "月" << day << "日";
- }
- };
- class People {
- private:
- char name[11];
- char number[7];
- char sex[3];
- Date birthday;
- char id[19];
- public:
- People() {
- std::strcpy(name, "");
- std::strcpy(number, "");
- std::strcpy(sex, "");
- std::strcpy(id, "");
- }
- People(const People& other) {
- std::strcpy(name, other.name);
- std::strcpy(number, other.number);
- std::strcpy(sex, other.sex);
- birthday = other.birthday;
- std::strcpy(id, other.id);
- }
- void input() {
- std::cout << "姓名:";
- std::cin >> name;
- std::cout << "编号:";
- std::cin >> number;
- std::cout << "性别(男/女):";
- std::cin >> sex;
- std::cout << "出生日期(年 月 日):";
- birthday.input();
- std::cout << "身份证号:";
- std::cin >> id;
- }
- void display() const {
- std::cout << "\n姓名:" << name << std::endl;
- std::cout << "编号:" << number << std::endl;
- std::cout << "性别:" << sex << std::endl;
- std::cout << "出生日期:";
- birthday.display();
- std::cout << std::endl;
- std::cout << "身份证号:" << id << std::endl;
- }
- ~People() {}
- };
- int main() {
- int num;
- std::cout << "员工人数:";
- std::cin >> num;
- People* peopleArray = new People[num];
- for (int i = 0; i < num; ++i) {
- peopleArray[i].input();
- }
- People firstCopy = peopleArray[0];
- firstCopy.display();
- for (int i = 0; i < num; ++i) {
- peopleArray[i].display();
- }
- delete[] peopleArray;
- return 0;
- }
|