设计一个Employee类,包含:雇员的编号、姓名、性别、出生日期等。其中“出生日期”声明为一个日期类的对象。用成员函数实现对人员信息的录入和显示。

#include <iostream>
using namespace std;
class CDate {//创建一个名为CDate的类,用于设置日期
public:
    void setDate(int year, int month, int day) {
        Year = year;
        Month = month;
        Day = day;
    }
    void showDate();
    //以下三个成员函数用于Employee中调用年、月、日
    int show1();
    int show2();
    int show3();
private:
    int Year;
    int Month;
    int Day;
};
int CDate::show1()
{
    return Year;
}
int CDate::show2()
{
    return Month;
}
int CDate::show3()
{
    return Day;
}
inline void CDate::showDate()
{
    cout << Year << "/" << Month << "/" << Day << endl;
}
class Employee {
private:
    string bh;//变量编号
    string xm;//变量姓名
    string xb;//变量性别
    CDate riqi;//将CDate看作一个变量的类型,定义该变量
public:
    //构造函数初始化内部参数
    Employee(string BH, string XM, string XB ) :bh(BH), xm(XM), xb(XB), riqi() {
        cout << "Calling the constructor." << endl;//调用构造函数后输出 Calling the constructor.
    };
    //成员函数,用于输入信息
    void inputinfo(string bh1, string xm1, string xb1, int Year1, int Month1, int Day1);
    void showinfo();//成员函数用于输出
    ~Employee() {//析构函数,释放内存同时输出 Calling the destructor.
        cout << "Calling the destructor." << endl;
    }
};
inline void Employee::showinfo()
{
    cout << bh << " " << xm << " " << xb << " " << riqi.show1() << "/" << riqi.show2() << "/" << riqi.show3() << endl;
}
void Employee::inputinfo(string bh1, string xm1, string xb1, int Year1, int Month1, int Day1)
{
    bh = bh1;
    xm = xm1;
    xb = xb1;
    riqi.setDate(Year1, Month1, Day1);//调用CDate类里的setDate函数,将年、月、日的信息输入
}
int main()
{
    string a, b, c;
    int x, y, z;
    while (cin >> a >> b >> c >> x >> y >> z)
    {
        Employee inf("0", "0", "0");//初始化
        inf.inputinfo(a, b, c, x, y, z);
        inf.showinfo();
    }
    return 0;
}

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值