64,666
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<string>
using namespace std;
class Date
{
public:
Date(int y = 0, int m = 0, int d = 0);
Date(const Date& b);
~Date()
{
cout << "Destructor called." << endl;
}
int year;
int month;
int day;
};
Date::Date(int y, int m, int d)
{
year = y;
month = m;
day = d;
}
Date::Date(const Date& b)
{
year = b.year;
month = b.month;
day = b.day;
}
class People
{
public:
People(string, string, int, int, int, int);
People(const People& b);
~People()
{
cout << "Destructor called." << endl;
}
void show();
void set();
private:
string name;
string sex;
Date birthday;
int id;
};
People::People(string n, string s, int y, int m, int d, int i) :birthday(y, m, d)
{
name = n;
sex = s;
id = i;
}
People::People(const People& b)
{
name = b.name;
sex = b.sex;
Date birthday(b.birthday);
id = b.id;
}
void People::show()
{
cout << "name " << name << endl << "sex " << sex << endl << "birthday" << birthday.year << birthday.month << birthday.day << endl << "id" << id << endl;
}
void People::set()
{
cin >> name >> sex >> birthday.year >> birthday.month >> birthday.day >> id;
}
int main()
{
People p1("bb", "man", 1992, 12, 01, 5684554654);
People p2("cc", "man", 1996, 11, 02, 6456456454);
People p3(p1);
return 0;
}