import java.util.Date;
public class Person {
private long IdPerson;
private String Name;
private String Sex;
private Date Birthday;
private String HomeAddress;
public Person(){}
//初始化对象
public Person(long idPerson, String name, String sex, Date birthday, String homeAddress) {
super();
IdPerson = idPerson;
Name = name;
Sex = sex;
Birthday = birthday;
HomeAddress = homeAddress;
}
//输出
@Override
public String toString() {
return "Person [IdPerson=" + IdPerson + ", Name=" + Name + ", Sex=" + Sex + ", Birthday=" + Birthday
+ ", HomeAddress=" + HomeAddress + "]";
}
//下面是分别获取和设置单个属性的方法
public long getIdPerson() {
return IdPerson;
}
public void setIdPerson(long idPerson) {
IdPerson = idPerson;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getSex() {
return Sex;
}
public void setSex(String sex) {
Sex = sex;
}
public Date getBirthday() {
return Birthday;
}
public void setBirthday(Date birthday) {
Birthday = birthday;
}
public String getHomeAddress() {
return HomeAddress;
}
public void setHomeAddress(String homeAddress) {
HomeAddress = homeAddress;
}
}
纯手打,望采纳!
以下程序经VS2010编译通过
华中科技大学 C++ 实验十 类与对象的基本概念 第三题
#include
#include
#include
using namespace std;
class Person{
private:
char IdPerson[19];
char Name[20];
char Sex[10];
int Birthday;
char HomeAddress[50];
public:
Person();
void CinIdPerson();
void CinName();
void CinSex();
void CinBirthday();
void CinHomeAddress();
void Show();
Person(Person&cop)//拷贝构造函数
{
strcpy(IdPerson,cop.IdPerson);
strcpy(Name,cop.Name);
strcpy(Sex,cop.Sex);
Birthday=cop.Birthday;
strcpy(HomeAddress,cop.HomeAddress);
}
};
Person::Person()//构造函数
{
IdPerson[0]='\0';Name[0]='\0';Sex[0]='\0';Birthday=0;HomeAddress[0]='\0';
}
void Person::CinIdPerson()
{
cout<<"请输入身份证号"< cin>>IdPerson; } void Person::CinName() { cout<<"请输入姓名"< cin>>Name; } void Person::CinSex() { cout<<"请输入性别"< cin>>Sex; } void Person::CinBirthday() { cout<<"请输入生日"< cin>>Birthday; } void Person::CinHomeAddress() { cout<<"请输入家庭地址"< cin>>HomeAddress; } void Person::Show()//显示数据 { cout<<"======================================="< cout<<"身份证号:"< cout<<"======================================="< } void main() { int i=0,j,k; Person Id[100]; cout<<"本程序最多支持记录100人"< do{ cout<<"请输入学生编号"< cin>>i; Id[i].Show(); cout<<"修改请按 1,不改请按 0"< cin>>j; for(;j;) { Id[i].CinIdPerson(); Id[i].CinName(); Id[i].CinSex(); Id[i].CinBirthday(); Id[i].CinHomeAddress(); Id[i].Show(); j=0; } cout<<"继续编辑请按 1,返回选择请按 0"< cin>>k; }while(k=1); }