急急急!一道c++的编程题,望各位高手找错并帮忙修该,谢谢

woshishuinizi 2008-11-13 11:31:44
//employee.h
class Date

{

public:
Date(int NewY=0,int NewM=0,int NewD=0);//构造函数
void Setbirthday(int NewY,int NewM,int NewD);
void Showbirthday();
int GetYear() {return Year;}//隐式的构造函数
int GetMonth() {return Month ;}
int GetDay() {return Day;}
private:
int Year ,Month, Day;
};

//函数成员的实现

Date::Date(int NewY,int NewM,int NewD)

{
Year=NewY;
Month=NewM;
Day=NewD;
}

void Date::Setbirthday(int NewY,int NewM,int NewD)

{
Year=NewY;
Month=NewM;
Day=NewD;
}

void Date::Showbirthday()
{

cout<<Year<<" "<<Month<<" "<<Day<<" "<<endl;
}

class employee

{
public:
employee();
employee(employee &);
~employee() {}
void IncreaseEmpNO(int);
void Insex(char male=0,char female=1);
void InIDcardNO(char);
int GetindividualEmpNO();
char Getsex();
char GetIDcardNO();
protected:
int individualEmpNO;
char sex;
char IDcardNO[20];
Date birthday;


}



//如何实现将‘出生日期’声明为一个‘日期’类的内嵌子对象进而实现类的组合
employee::employee()
{
individualEmpNO=0000;
sex=0;
//员工的身份证号如何实现初始化

}

//拷贝构造函数又如何实现

void employee::Insex(char male=0,char female=1)

{
cout<<"输入员工性别(男用0,女用1)"<<endl;

}

void employee::InIDcardNO(char)

{
cout<<"输入员工的身份证号"<<endl;

}

int employee::GetindividualEmpNO()

{
return individualEmpNO;
}

char employee::Getsex()

{ return sex; }

char employee::GetIDcardNO()

{ return IdcardNO; }

#include <iostream>
using namespace std;
#include "employee.h"
int main ()

{
employee A;
employee B;
employee C;
employee D;

cout<<"输入第一个员工的信息"<<endl;
A.GetindividualEmpNO();
A.Getsex();
A.InIDcardNO();


cout<<"输入下一个员工的信息"<<endl;
B.GetindividualEmpNO();
B.Getsex();
B.InIDcardNO();


cout<<"输入下一个员工的信息"<<endl;
C.GetindividualEmpNO();
C.Getsex();
C.InIDcardNO();



cout<<"输入下一个员工的信息"<<endl;
D.GetindividualEmpNO();
D.Getsex();
D.InIDcardNO();


//

cout<<"编号"<<A.GetindividualEmpNO()<<"性别为"<<A.Getsex()<<"身份证号为"<<A.GetIDcardNO()
<<"出生日期为:"<<A.birthday<<endl;

cout<<"编号"<<A.GetindividualEmpNO()<<"性别为"<<A.Getsex()<<"身份证号为"<<A.GetIDcardNO()
<<"出生日期为:"<<A.birthday<<endl;

cout<<"编号"<<A.GetindividualEmpNO()<<"性别为"<<A.Getsex()<<"身份证号为"<<A.GetIDcardNO()
<<"出生日期为:"<<A.birthday<<endl;


cout<<"编号"<<A.GetindividualEmpNO()<<"性别为"<<A.Getsex()<<"身份证号为"<<A.GetIDcardNO()
<<"出生日期为:"<<A.birthday<<endl;

return 0;
}
...全文
212 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
太乙 2008-11-15
  • 打赏
  • 举报
回复
up
~~~~~~~
lgccaa 2008-11-15
  • 打赏
  • 举报
回复
修改别人的程序还真是一件痛苦的事啊,楼主的基础比较差啊,基础很重要


//employee.h

#include <iostream>

class Date
{
public:
Date(int NewY=0,int NewM=0,int NewD=0);//构造函数
~Date(); //析构函数
void Setbirthday(int NewY,int NewM,int NewD);
void Showbirthday();
int GetYear() {return Year;}//隐式的构造函数 //这里只是普通的成员函数,不是什么隐式的构造函数
int GetMonth() {return Month ;}
int GetDay() {return Day;}
Date & operator = (const Date &date); //这里要加一个赋值函数

private:
int Year ,Month, Day;
};

class employee
{
public:
employee();
employee(const employee &obj); //拷贝构造函数
~employee();
void SetindividualEmpNO(int EmpNO); //函数命名要规范
void SetSex(char sex);
void SetIDcardNO(char *IDcardNO);
void SetBirthday(Date birthday);
int GetindividualEmpNO();
char Getsex();
char *GetIDcardNO();
Date GetBirthday();

protected:
int individualEmpNO;
char sex;
char IDcardNO[20];
Date birthday;
};




//employee.cpp

#include "employee.h"

using namespace std;

//函数成员的实现

Date::Date(int NewY,int NewM,int NewD)
{
Year = NewY;
Month = NewM;
Day = NewD;
}

Date::~Date()
{
}

void Date::Setbirthday(int NewY,int NewM,int NewD)
{
Year = NewY;
Month = NewM;
Day = NewD;
}

void Date::Showbirthday()
{
cout<<Year<<" "<<Month<<" "<<Day;
}

//赋值函数
Date & Date::operator = (const Date &date)
{
this->Year = date.Year;
this->Month = date.Month;
this->Day = date.Day;

return *this;
}


//如何实现将‘出生日期’声明为一个‘日期’类的内嵌子对象进而实现类的组合
employee::employee()
{
individualEmpNO = 0000;
sex = 0;
//birthday(0,0,0);
strncpy(IDcardNO, "000000", sizeof(IDcardNO)/sizeof(IDcardNO[0])); //员工的身份证号如何实现初始化
}

employee::~employee()
{
}


//拷贝构造函数又如何实现
employee::employee(const employee &obj)
{
this->individualEmpNO = obj.individualEmpNO;
this->sex = obj.sex;
this->birthday = obj.birthday;
strncpy(this->IDcardNO, obj.IDcardNO, sizeof(obj.IDcardNO)/sizeof(obj.IDcardNO[0]));
}

void employee::SetindividualEmpNO(int EmpNO)
{
this->individualEmpNO = EmpNO;
}

void employee::SetSex(char sex)
{
this->sex = sex;
}

void employee::SetIDcardNO(char *IDcardNO)
{
if(IDcardNO == NULL)
return;

int length = strlen(IDcardNO);
if((length + 1) > 20)
return;
strcpy(this->IDcardNO, IDcardNO);

}

void employee::SetBirthday(Date birthday)
{
this->birthday = birthday;
}

int employee::GetindividualEmpNO()
{
return this->individualEmpNO;
}

char employee::Getsex()
{
return this->sex;
}

char *employee::GetIDcardNO()
{
return this->IDcardNO;
}

Date employee::GetBirthday()
{
return this->birthday;
}




//主程序
#include <iostream>
#include "employee.h"

using namespace std;

void InputMessage(employee &e);
void OutputMessage(employee &e);

int main ()
{
employee A;
employee B;
employee C;
employee D;

InputMessage(A);

OutputMessage(A);

system("pause");
return 0;
}

//这里输入员工信息
void InputMessage(employee &e)
{
cout<<"输入员工的信息"<<endl;
cout<<"请输入编号:";
int EmpNO;
cin>>EmpNO;
cout<<endl;
cout<<"请输入性别(0 男,1 女):";
char sex;
cin>>sex;
cout<<endl;
int year,month,day;
cout<<"请输入生日:"<<endl;
cout<<"年份:";
cin>>year;
cout<<"月份:";
cin>>month;
cout<<"天:";
cin>>day;
Date date(year, month, day);
cout<<"请输入身份证号:";
char *IDNO = new char[20];
cin>>IDNO;

e.SetindividualEmpNO(EmpNO);
e.SetSex(sex);
e.SetBirthday(date);
e.SetIDcardNO(IDNO);

delete [] IDNO;
}

//这里输出员工信息
void OutputMessage(employee &e)
{
cout<<endl;
cout<<"编号"<<"\t"<<"性别"<<"\t"<<"出生日期"<<"\t"<<"身份证号"<<endl;
cout<<e.GetindividualEmpNO()<<"\t"<<e.Getsex()<<"\t";
e.GetBirthday().Showbirthday();
cout<<"\t"<<e.GetIDcardNO()<<endl;
}

Longinc 2008-11-15
  • 打赏
  • 举报
回复
UP
帅得不敢出门 2008-11-15
  • 打赏
  • 举报
回复
up
woshishuinizi 2008-11-15
  • 打赏
  • 举报
回复
刚刚学,基础很差。望各位多多指教。不过3楼写的程序比较麻烦。源程序是这么要求的:
设计一个用于人事管理的“人员”类。考虑到通用性,这里只抽象出所有类型人员都具有的属性:编号、性别、出生日期、身份证号等。其中“出生日期”声明为一个“日期”类内嵌子对象。用成员函数实现队人员信息的录入何如显示。要求包括:构造函数和析构函数’拷贝构造函数、内联成员函数、带默认形参值的成员函数、类的组合。
希望各位能帮忙,谢谢。
wudeshou82666 2008-11-15
  • 打赏
  • 举报
回复
改好了???
BuleRiver 2008-11-14
  • 打赏
  • 举报
回复
#include <iostream>

using namespace std;

//employee.h
class Date
{
public:
Date(int NewY=0,int NewM=0,int NewD=0);//构造函数
void Setbirthday(int NewY,int NewM,int NewD);
void Showbirthday();
int GetYear() {return Year;}//隐式的构造函数
int GetMonth() {return Month ;}
int GetDay() {return Day;}
private:
int Year ,Month, Day;
};

//函数成员的实现

Date::Date(int NewY,int NewM,int NewD)
{
Year=NewY;
Month=NewM;
Day=NewD;
}

void Date::Setbirthday(int NewY,int NewM,int NewD)
{
Year=NewY;
Month=NewM;
Day=NewD;
}

void Date::Showbirthday()
{
cout <<Year <<" " <<Month <<" " <<Day <<" " <<endl;
}

class employee
{
public:
employee();
employee(employee &);
~employee() {}
void IncreaseEmpNO(int);
void Insex();
void InIDcardNO();
int GetindividualEmpNO();
char Getsex();
char* GetIDcardNO(char* buf);
friend ostream& operator<<(ostream& os, employee& e);

protected:
int individualEmpNO;
Date birthday;
char sex;
char IDcardNO[20];
};

ostream& operator<<(ostream& os, employee& e)
{
os<<e.birthday.GetYear()<<" "<<e.birthday.GetMonth()<<" "<<e.birthday.GetDay();
return os;
}



//如何实现将‘出生日期’声明为一个‘日期’类的内嵌子对象进而实现类的组合
employee::employee(): individualEmpNO(0000), sex(0)
{
strncpy(IDcardNO, "123456", sizeof(IDcardNO)/sizeof(IDcardNO[0]));
}

//拷贝构造函数又如何实现

void employee::Insex()
{
cout <<"输入员工性别(男用0,女用1)" <<endl;
cin>>sex;
}

void employee::InIDcardNO()
{
cout <<"输入员工的身份证号" <<endl;
cin>>IDcardNO;
}

int employee::GetindividualEmpNO()
{
return individualEmpNO;
}

char employee::Getsex()
{ return sex; }

char* employee::GetIDcardNO(char* buf)
{
strncpy(buf, IDcardNO, sizeof(IDcardNO)/sizeof(IDcardNO[0]));
return IDcardNO;
}

int main ()
{
employee A;
employee B;
employee C;
employee D;

cout <<"输入第一个员工的信息" <<endl;
A.GetindividualEmpNO();
A.Getsex();
A.InIDcardNO();

cout <<"输入下一个员工的信息" <<endl;
B.GetindividualEmpNO();
B.Getsex();
B.InIDcardNO();

cout <<"输入下一个员工的信息" <<endl;
C.GetindividualEmpNO();
C.Getsex();
C.InIDcardNO();

cout <<"输入下一个员工的信息" <<endl;
D.GetindividualEmpNO();
D.Getsex();
D.InIDcardNO();

char ID[20]={0};
A.GetIDcardNO(ID);
cout <<"编号" <<A.GetindividualEmpNO()<<"性别为" <<A.Getsex() <<"身份证号为" <<ID
<<"出生日期为:"<<A<<endl;

return 0;
}

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧