- 题目描述 对people类重载“= =”运算符和“=”运算符,“==”运算符判断两个people类对象的id属性是否相等;“=”运算符实现people类对象的赋值操作。
- 代码如下
#include#include using namespace std;class Data{public: Data(){} Data(int yy,int mm,int dd){ year=yy; month=mm; day=dd; } Data(Data &ap){ year=ap.year; month=ap.month; day=ap.day; } ~Data(){ } int get_year(){ return year; } int get_month(){ return month; } int get_day(){ return day; } void set_year(int y){ year=y; } void set_month(int m){ month=m; } void set_day(int d){ day=d; }private: int year; int month; int day;};class People{public: People(int num,string se,Data birth,string iid):birthday(birth){ number=num; sex=se; id=iid; } People(People &tp){ number=tp.get_number(); sex=tp.get_sex(); id=tp.get_id(); birthday=tp.get_birthday(); } People(){} People get_People(){ int num,yy,mm,dd; string ID,se; cout<<"Please enter the number of the People:"< >num; cout<<"Please enter the sex:(male or female)"< >se; cout<<"Please enter the birthday:" <<"(Warning the format is 1998 8 3.)"< >yy>>mm>>dd; cout<<"Please enter the id:"< >ID; Data birth(yy,mm,dd); id=ID; number=num; sex=se; birthday=birth; return *this; } ~People(){} void set_number(int num){ number=num; } void set_sex(string se){ sex=se; } void set_birhtday(Data birth){ birthday=birth; } void set_id(string iidd){ id=iidd; } inline int get_number(){ return number; } inline string get_sex(){ return sex; } Data get_birthday() { return birthday; } inline string get_id(){ return id; } void details(){ cout<<"Number:"< <
- 测试截图