• 题目描述
/*设计一个用于人事管理的People(人员)类。*/
/*
考虑到通用性,这里只抽象所有类型人员都具有的属性:
number(编号)、sex(性别)、birthday(出生日期)、id(身份证号)等等。
其中“出生日期”定义为一个“日期”类内嵌子对象。
用成员函数实现对人员信息的录入和显示。
要求包括:构造函数和析构函数、拷贝构造函数、内联成员函数、聚集。
*/
  • 代码如下
#include<iostream>
#include<string>
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:"<<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;
}
  • 测试截图

C++创建People类--练习的更多相关文章

  1. vs里根据json快速创建对应类的方法

    有时候,我们在调用别人接口的时候,服务端返回了一个json格式的字符串,我们要获取json里面的数据的话一般有两种方式: 1.通过正则 2.反序列化成一个对象 第一种方式这里不再多说,主要说一下第二种 ...

  2. [转]自己写PHP扩展之创建一个类

    原文:http://www.imsiren.com/archives/572 比如我们要创建一个类..PHP代码如下 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  3. C#-数据库访问技术 ado.net——创建 数据库连接类 与 数据库操作方法 以及简单的数据的添加、删除、修改、查看

    数据库访问技术 ado.net 将数据库中的数据,提取到内存中,展示给用户看还可以将内存中的数据写入数据库中去 并不是唯一的数据库访问技术,但是它是最底层的数据库访问技术 1.创建数据库,并设置主外键 ...

  4. classmethod一个用处是创建可选类构造器

    Definition and Introduction通常来说, descriptor 是一种绑定着特殊行为属性的对象, 在访问它时行为被descriptor协议定义的方法所重载.这些方法是__get ...

  5. MFC编程入门之八(对话框:创建对话框类和添加控件变量)

    创建好对话框资源后要做的就是生成对话框类了.生成对话框类主要包括新建对话框类.添加控件变量和控件的消息处理函数. 例程Addition是基于对话框的程序,所以程序自动创建了对话框模板IDD_ADDIT ...

  6. (spring-第17回【AOP基础篇】) 创建增强类

    一.   增强类包含的信息: a)   横切逻辑(插入的具体代码) b)   部分连接点信息(在方法的哪个位置插入代码,比如方法前.方法后等). 二.   增强的类型 每一种增强有一个需要实现的增强类 ...

  7. Swift游戏实战-跑酷熊猫 06 创建平台类以及平台工厂类

    这节内容我们一起学习下随机长度的踩踏平台的原理是怎么样的. 要点: 平台类 我们的平台类继承于SKNode,这样就能被添加进其它节点进而显示在场景中. 它有一个方法来创建平台,这个方法接收一个包含SK ...

  8. 利用MyEclipse自动创建PO类、hbm文件(映射文件)、DAO

    原文地址:http://blog.csdn.net/fangzhibin4712/article/details/7179414 前提条件:表sjzdfl  表sjzdxx (使用数据库MySQL) ...

  9. Android(java)学习笔记62:继承Thread类创建线程类

    package cn.itcast_02; /* * 该类要重写run()方法,为什么呢? * 不是类中的所有代码都需要被线程执行的. * 而这个时候,为了区分哪些代码能够被线程执行,java提供了T ...

  10. 一种从JSON数据创建Java类的高效办法

    <一种从JSON数据创建Java类的高效办法> 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs JSON格式的数据经常会遇到,比如调用Web服 ...

随机推荐

  1. Java使用TCP聊天程序

    前面使用了UDP进行通信的聊天程序 现在做一个用TCP进行通信的聊天程序 原理: ServerSocket Socket 1.开一个线程监听端口,准备接收消息 2.不断接受消息发送到目的端口 P.S. ...

  2. Android中的Service与进程间通信(IPC)详解

    Service 什么是Service 在后台长期运行的没有界面的组件.其他组件可以启动Service让他在后台运行,或者绑定Service与它进行交互,甚至实现进程间通信(IPC).例如,可以让服务在 ...

  3. Android UI 切图命名规范、标注规范及单位描述(转载)

    本文转自:https://blog.csdn.net/klxh2009/article/details/74938009 很多UI设计师做APP切图都会有两套,一套是Android的,一套是IOS的. ...

  4. matlab 中“newff” 函数的参数设置

    matlab 中"newff" 函数的使用方法技巧|和各参数的意义 先来一个简单的源程序让大家练习一下: % Here input P and targets T define a ...

  5. 服务器ipmi远程管理

    DELL iDRAC (Integrated Dell™ Remote Access Controller )是 Dell PowerEdge 系列服务器上的远程管理方案, 11代 12代服务器已经集 ...

  6. JavaScript递归深度问题

    递归是有限的东西: function fact(num) { if (num <= 1) { return 1; } else { return fact(num - 1); } } 测试结果是 ...

  7. 在Eclipse中安装JSHint插件

    离线安装 1.下载插件包 http://download.eclipsesource.com/~rsternberg/jshint-eclipse-0.9.8.20130728-0004-b94b44 ...

  8. mac nvm install

    open the url https://github.com/creationix/nvm 1. curl -o- https://raw.githubusercontent.com/creatio ...

  9. Linux --Mysql基础命令

    mysql>create database a; --创建一个名为a的新库 mysql>create table a: --创建一个名为a新表 mysql>use a: --进入一个 ...

  10. 在同一网关下ping不通其他电脑

    最近在做数据库相关的程序,所以想先用ping试下和主机连没连着,但发现虽然两台电脑在同一网关下,但却互相ping不通,后来才发现,原来是防火墙在作怪. Omg!感慨一下!默认的情况下,保守的windo ...