博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++创建People类--练习
阅读量:4947 次
发布时间:2019-06-11

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

  • 题目描述
/*设计一个用于人事管理的People(人员)类。*//*考虑到通用性,这里只抽象所有类型人员都具有的属性:number(编号)、sex(性别)、birthday(出生日期)、id(身份证号)等等。其中“出生日期”定义为一个“日期”类内嵌子对象。用成员函数实现对人员信息的录入和显示。要求包括:构造函数和析构函数、拷贝构造函数、内联成员函数、聚集。*/
  • 代码如下
#include
#include
using namespace std;class Data {public: Data() {} Data(int yy, int mm, int dd); Data(Data &ap); ~Data(); int get_year(); int get_month(); int get_day(); void set_year(int y); void set_month(int m); void set_day(int d);private: int year; int month; int day;};Data::Data(int yy, int mm, int dd) { year = yy; month = mm; day = dd;}Data::Data(Data &ap) { year = ap.year; month = ap.month; day = ap.day;}Data::~Data() {}int Data::get_day() { return day;}int Data::get_month() { return month;}int Data::get_year() { return year;}void Data::set_day(int d) { day = d;}void Data::set_month(int m) { month = m;}void Data::set_year(int y) { year = y;}class People {public: People(int num, string se, Data birthd, string iid); People(People &tp); People(){} People get_People(); ~People() { } void set_number(int num) { number = num; } void set_sex(string se) { sex = se; } void set_birthday(Data birth) { birthday = birth; } void set_id(string iidd) { id = iidd; } int get_number(); string get_sex(); Data get_birthday(); string get_id(); void details();private: int number; string sex; Data birthday; string id;};inline int People::get_number() { return number;}inline string People::get_sex() { return sex;}inline string People::get_id() { return id;}Data People::get_birthday() { return birthday;}void People::details() { cout << "Number:"<
<< endl; cout << "Sex:" << sex << endl; cout << "Birhtday:" << birthday.get_year() << "/" << birthday.get_month() << "/" << birthday.get_day() << endl; cout << "ID:" << id << endl;}People::People(int num, string se, Data birth, string iid):birthday(birth){ number = num; sex = se; id = iid;}People People::get_People() { int num, yy, mm, dd; string ID, se; cout << "Please enter the number of the people:"; cin >> num; cout << "Please enter the sex of the people:(male or female)"; cin >> se; cout << "Please enter the birthday of the people:" << endl << "(Warnning:The format is similar to 1998 8 3)" << endl; cin >> yy >> mm >> dd; cout << "Please enter the id of the people:"; cin >> ID; Data birth(yy, mm, dd); id = ID; number = num; sex = se; birthday = birth; return *this;}People::People(People &tp) { number = tp.get_number(); sex = tp.get_sex(); id = tp.get_id(); birthday = tp.get_birthday();}int main(){ People asp; asp.get_People(); asp.details(); return 0;}
  • 测试截图

     

 

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

你可能感兴趣的文章
python日期模块
查看>>
笔记54 Mybatis快速入门(五)
查看>>
网站搭建 (第04天) 导航栏与页脚
查看>>
Redis通过Lua一次获取多个key值
查看>>
android EditText不弹出软键盘
查看>>
php将数组写入配置文件
查看>>
ALV 报表
查看>>
Spring+Quartz实现定时任务的配置方法
查看>>
同时启动多个tomcat服务器
查看>>
怎么将iphone上的照片导出到本地文件
查看>>
Repeater+DataPagerSource分页
查看>>
模块化导出
查看>>
pagebean pagetag java 后台代码实现分页 demo 前台标签分页 后台java分页
查看>>
H5小知识
查看>>
面包屑之javascript声明期与执行期的故事
查看>>
作为程序员的你,必须掌握的21个Java核心技术!
查看>>
Sphinx 2.0.8 发布,全文搜索引擎 Installing Sphinx on Windows
查看>>
自定义orgmode中加粗字体的颜色
查看>>
基于keepalived搭建MySQL热机集群
查看>>
AX lookup方法重载实例
查看>>