c++编写一个程序,设计一个人员类(Person)。数据成员包括身份证号(IdPerson)、姓名(Name)、性别(Sex)、生日 (Birthday)和家庭住址(HomeAddress)。成员函数包括人员信息的录入和显示,还包括构造函数与拷贝 构造函数。
时间: 2024-05-21 12:12:25 浏览: 74
你好,以下是符合你要求的C++代码:
#include <iostream>
using namespace std;
class Person{
private:
string IdPerson;
string Name;
string Sex;
string Birthday;
string HomeAddress;
public:
Person(){}
Person(string id, string name, string sex, string birthday, string address){
IdPerson = id;
Name = name;
Sex = sex;
Birthday = birthday;
HomeAddress = address;
}
Person(const Person& p){
IdPerson = p.IdPerson;
Name = p.Name;
Sex = p.Sex;
Birthday = p.Birthday;
HomeAddress = p.HomeAddress;
}
void inputInfo(){
cout << "请输入身份证号:";
cin >> IdPerson;
cout << "请输入姓名:";
cin >> Name;
cout << "请输入性别:";
cin >> Sex;
cout << "请输入生日:";
cin >> Birthday;
cout << "请输入家庭住址:";
cin >> HomeAddress;
}
void showInfo(){
cout << "身份证号:" << IdPerson << endl;
cout << "姓名:" << Name << endl;
cout << "性别:" << Sex << endl;
cout << "生日:" << Birthday << endl;
cout << "家庭住址:" << HomeAddress << endl;
}
};
int main(){
Person p;
p.inputInfo();
p.showInfo();
Person q(p);
q.showInfo();
return 0;
}
当你输入完问题后,我将自动返回你答案,感谢使用 ChitGPT!
阅读全文