请帮忙把下面的问题做一下,谢谢.
要求把Staff中的char name[10];改为char *name;,并把Staff需要修改的部份做相应的修改,使得整个程序仍能完成原有的功能(用动态空间存储姓名数据,设计析构函数释放姓名数据所占用的动态空间)
#include
#include
class Date{
short year;
short month;
short day;
public:
Date();
Date(int y,int m,int d):year(y),month(m),day(d){}
void show(){cout<};
class Staff{
char staffNo[5];
char name[10];
char sex;
Date birthDay;
public:Staff();
Staff(const char st_no[],const char st_name[],
char st_sex,short year,short month,short day)
:birthDay( year,month,day),sex(st_sex)
{
strncpy(staffNo,st_no,5);
strncpy(name,st_name,10);
}
void show()
{
cout< < < birthDay.show();
}
};
Date::Date(){ }
Staff::Staff(){}
void main()
{ short year;
short month;
short day;
char staffNo[5];
char name[10];
char sex;
Staff s[4];
for(int i=0;i<4;i++)
{
cout< cin>>year>>month>>day;
cin.ignore(80,'\n');
cout.setf(ios::left,ios::adjustfield);
cout< cin.getline(staffNo,5);
cin.ignore(80,'\n');
cout< cin.getline(name,10);
cin.ignore(80,'\n');
cout< cin>>sex;
cin.ignore(80,'\n');
Staff ss(staffNo,name,sex,year,month,day);
s[i]=ss;
}
for(i=0;i<4;i++)
s[i].show();
cin.get();
}
--------------------next---------------------
阅读(1142) | 评论(0) | 转发(0) |