划红线处怎么回事?
#include <iostream>
using namespace std;
#include <cstring>
class Date {
private:
int year, month, day;
public:
Date(int year = 0, int month = 0, int day = 0) {
this->year = year;
this->month = month;
this->day = day;
}
void setDate() {
cin >> year >> month >> day;
}
void showDate() {
cout << year << "年" << month << "月" << day << "日";
}
~Date() {}
};
class People {
private:
char name[11];
char number[7];
char sex[3];
char id[19];
Date birthday;
public:
People() {
}
People(char na[], char num[], char se[], int y, int m, int d, char i[]): birthday(y, m, d) {
strcpy(name, na);
strcpy(number, num);
strcpy(sex, se);
strcpy(id, i);
}
People(People &p) {
strcpy(name, p.name);
strcpy(number, p.number);
strcpy(sex, p.sex);
strcpy(id, p.id);
birthday = p.birthday;
}
//录入人员信息
void input() {
cout << "姓名:";
cin >> name;
//cout << endl;
cout << "编号:";
cin >> number;
//cout << endl;
cout << "性别(男/女): ";
cin >> sex;
//cout << endl;
cout << "出生日期(年 月 日):";
birthday.setDate();
//cout << endl;
cout << "身份证号:";
cin >> id;
//cout << endl;
}
void showPeople() {
cout << endl;
cout << "姓名:" << name << endl;
cout << "编号:" << number << endl;
cout << "性别:" << sex << endl;
cout << "出生日期: ";
birthday.showDate();
cout << endl;
cout << "身份证号:" << id;
}
~People() {}
};
int main() {
int n;//员工数
cout << "员工人数: ";
cin >> n;
//cout << endl;
People *p;
p = new People[n];
for (int i = 0; i < n; i++) {
p[i].input();
}
People p1(p[0]);
p1.showPeople();
for (int i = 0; i < n; i++) {
p[i].showPeople();
}
return 0;
}
我的解答思路和尝试过的方法
我想要达到的结果