博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++重载运算符练习--对people类重载“= =”运算符和“=”运算符
阅读量:4542 次
发布时间:2019-06-08

本文共 1911 字,大约阅读时间需要 6 分钟。

  1. 题目描述
    对people类重载“= =”运算符和“=”运算符,“==”运算符判断两个people类对象的id属性是否相等;“=”运算符实现people类对象的赋值操作。
  2. 代码如下
#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:"<
<
  1. 测试截图
    这里写图片描述

 

转载于:https://www.cnblogs.com/FlyerBird/p/8995957.html

你可能感兴趣的文章
Python执行Linux系统命令的4种方法
查看>>
09 mongoDB基础(进阶)
查看>>
Xenomai PC开发环境
查看>>
spring-c3p0-01
查看>>
浏览器
查看>>
E20170624-ts
查看>>
linux shell实现随机数多种方法(date,random,uuid)
查看>>
页面上有tab,如何点击加载更多?
查看>>
bash&nbsp;shell笔记1&nbsp;脚本基础知识
查看>>
html dl dt dd标签元素语法结构与使用
查看>>
OC单元测试框架-----Google开源单元测试框架Google Test(gtest)
查看>>
QLineEdit IP地址校验
查看>>
Using Bing Search Service over SOAP Protocol in an ASP.NET Web Application
查看>>
2016年秋季-《UML大战需求分析》-个人阅读计划
查看>>
cocos2d-x多线程解析域名
查看>>
LeetCode:Verify Preorder Serialization of a Binary Tree
查看>>
4_something
查看>>
ACM数论之旅12---康托展开((*゚▽゚*)装甲展开,主推进器启动,倒计时3,2,1......)...
查看>>
使用WebHelper调用Asp.net WebAPI
查看>>
磁盘创建
查看>>