请帮忙把下面的问题做一下,谢谢.
要求把Staff中的char name[10];改为char *name;,并把Staff需要修改的部份做相应的修改,使得整个程序仍能完成原有的功能(用动态空间存储姓名数据,设计析构函数释放姓名数据所占用的动态空间)
#include<iomanip.h>
#include<string.h>
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<<year<<'.'<<month<<'.'<<day;}
};
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<<endl<<setw(5)<<staffNo
<<setw(10)<<name
<<setw(3)<<sex;
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<<endl<<"请输入年月日:";
cin>>year>>month>>day;
cin.ignore(80,'\n');
cout.setf(ios::left,ios::adjustfield);
cout<<endl<<"请输入职工号:";
cin.getline(staffNo,5);
cin.ignore(80,'\n');
cout<<endl<<"请输入姓名:";
cin.getline(name,10);
cin.ignore(80,'\n');
cout<<endl<<"请输入性别(M/F):";
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();
}