类的组合

设计一个用于人事管理的人员类。由于考虑到通用性,这里只抽象出所有类型人员有具有的属性:姓名,性别,出生日期等。其中出生日期声明为一个日期”类的内嵌子对象。用成员函数实现对人员信息的录入和显示。要求包括:构造函数和析构函数、复制构造函数、内联成员函数、带默认形参值的成员函数、类的组合。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<iostream>
using  namespace  std;
class  Time{
public :
Time( int  Year, int  Month, int  Day){
year=Year;month=Month;day=Day;
}     //构造函数
Time(Time &p){
year=p.year;month=p.month;day=p.day;
}     //复制构造函数
int  Gettime(){
cout<<year<< "年  " <<month<< "月  " <<day<< "日  " <<endl;
}     //返回出生日期
~Time(){
cout<< "~Time" <<endl;
}     //析构函数
private :
int  year,month,day;
};
class  Renyuan{
public :
Renyuan(Time a, char  xingming[], int  xingbie):riqi(a){
for ( int  i=0;i<10;i++)
name[i]=xingming[i];
sex=xingbie;
}
int  Getxinxi(){
cout<< "姓名:" ;
for ( int  i=0;i<10;i++)
cout<<name[i];
cout<<endl;
cout<< "性别:" ;
if (sex==1)     //sex为1,表示是男性
cout<< "男" <<endl;
else  if (sex==0)     //为0,表示是女性
cout<< "女" <<endl;
cout<< "出生日期:" ;
riqi.Gettime();
}
~Renyuan(){
cout<< "~Renyuan" <<endl;
}
private :
Time riqi;
char  name[10];
int  sex;
};
int  main(){
char  xingming[10]={ 'x' , 'i' , 'a' , 'o' , 'z' , 'h' , 'a' , 'n' , 'g' };
Time xiaozhang(1980,2,3);
Renyuan zhang(xiaozhang,xingming,1);
zhang.Getxinxi();
return  0;
}

 



本文转自 pangfc 51CTO博客,原文链接:http://blog.51cto.com/983836259/1338329,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值