#include 赞 踩 定义person类,包括数据成员身份证号码,姓名,性别,出生日期(用date类或者结构体完成),成员函数包括构造函数,拷贝构造函数和析构函数,输入输出person对象基本信息的函数。在main函数里定义person类的对象,对其进行输入和输出。 Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。
类的定义_定义人员类person,数据成员包括编号(num)、姓名(name)、性别(sex)、家庭住址(ad
#include "stdafx.h"
#include<iostream>
#include<cstring>
using namespace std;
class Data
{
public:
Data() {};
Data(int y, int m, int d);
Data(Data &refcar);
void set()
{
cout << "请输入生日:" << endl;
cin >> year >> month >> day;
}
void show()
{
cout << "出身日期为:" << year << "年" << month << "月" << day << "日" << endl;
}
~Data();
private:
int year;
int month;
int day;
};
Data::Data(int y, int m, int d)
{
year = y;
month = m;
day = d;
}
Data::Data(Data &p)
{
year = p.year;
month = p.month;
day = p.day;
}
Data::~Data() {}
class Person
{
public:
Person() {}
Person(char name, int id,char sex, Data &con_birthday);
Person(Person &refcar);
void set()
{
cout << "请输入姓名:" << endl;
cin >> name;
cout << "请输入身份证号:" << endl;
cin >> id;
cout << "请输入性别:" << endl;
cin >> sex;
}
void show()
{
cout << "姓名:" << name << "身份证号" << id << "性别" << sex << endl;
}
~Person();
private:
char name;
int id;
char sex;
Data m_iBirthday;
};
Person::Person(char a, int b, char c, Data &con_birthday) :m_iBirthday(con_birthday)
{
name = a;
id = b;
sex = c;
m_iBirthday = con_birthday;
}
Person::Person(Person &q)
{
name =q.name;
id = q.id;
sex = q.sex;
m_iBirthday = q.m_iBirthday;
}
Person::~Person() {
cout << "该函数被析构" << endl;
}
int main()
{
Person pn;
Data dt;
dt.set();
dt.show();
pn.set();
pn.show();
system("pause");
return 0;
}