当前位置:编程学习 > C/C++ >>

c++编程题

设计一个用于人事管理的 People(人员)类。考虑到通用性,这里只抽象出所有类型

人员都具有的属性:number(编号) 、易做图(性别)、birthday(出生日期) 、id(身份证号)等

等。其中"出生日期"定义为一个"日期"类内嵌子对象。用成员函数实现对人员信息的录入和

显示。要求包括:构造函数和析构函数、拷贝构造函数、内联成员函数、带缺省形参值的成

员函数、聚集。
追问:来自手机问问这里有的不能访问,谢谢,比如m_idate.year
答案:#include <iostream>
#include <string>
using namespace std;

class Date
{
public:
 Date():m_iYear(2011),m_iMonth(1),m_iDay(1){}
 Date(int year,int month,int day):m_iYear(year),m_iMonth(month),m_iDay(day){}
 Date(const Date& date){m_iYear=date.m_iYear;m_iMonth=date.m_iMonth;m_iDay=date.m_iDay;}
 virtual ~Date(){}
 inline int GetYear(){return m_iYear;}
 inline int GetMonth(){return m_iMonth;}
 inline int GetDay(){return m_iDay;}
 inline void SetYear(int year){m_iYear=year;}
 inline void SetMonth(int month){m_iMonth=month;}
 inline void SetDay(int day){m_iDay=day;}
 friend istream& operator >>(istream& in,Date& date);
 friend ostream& operator <<(ostream& out,Date& date);
private:
 int m_iYear;
 int m_iMonth;
 int m_iDay;
};

istream& operator >>(istream& in,Date& date)
{
 cin>>date.m_iYear>>date.m_iMonth>>date.m_iDay;
 return in;
}

ostream& operator <<(ostream& out,Date& date)
{
 cout<<date.m_iYear<<"-"<<date.m_iMonth<<"-"<<date.m_iDay;
 return out;
}

class People
{
public:
 People():m_sNum("000001"),m_sSex("男"),m_birth(),m_sId(""){}
 People(const People& p);
 virtual ~People(){}
 void Get();
 void Show();
 inline void SetNum(string num){m_sNum=num;}
 inline void SetSex(string 易做图){m_sSex=易做图;}
 inline void SetBirth(Date birth){m_birth=birth;}
 inline void SetID(string id){m_sId=id;}
 inline string GetNum(){return m_sNum;}
 inline string GetSex(){return m_sSex;}
 inline Date GetBirth(){return m_birth;}
 inline string GetID(){return m_sId;}
private:
 string m_sNum;
 string m_sSex;
 Date m_birth;
 string m_sId;
};

People::People(const People& p)
{
 m_sNum=p.m_sNum;
 m_sSex=p.m_sSex;
 m_birth=p.m_birth;
 m_sId=p.m_sId;
}

void People::Get()
{
 cout<<"请输入编号:"<<endl;
 cin>>m_sNum;
 cout<<"请输入性别:"<<endl;
 cin>>m_sSex;
 cout<<"请输入生日日期(以空格隔开):"<<endl;
 cin>>m_birth;
 cout<<"请输入身份证号:"<<endl;
 cin>>m_sId;
}

void People::Show()
{
 cout<<"该职员信息:"<<endl;
 cout<<"编号:"<<m_sNum<<endl;
 cout<<"性别:"<<m_sSex<<endl;
 cout<<"生日:"<<m_birth<<endl;
 cout<<"身份证号:"<<m_sId<<endl;
}

int main()
{
 People p;
 p.Get();
 p.Show();
 return 0;
}

留个邮箱,发给你。差不多写好了。。码字真累啊
留名,有空拿来复习C++

上一个:C++大数问题
下一个:c++程序设计

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,