试题源程序文件清单如下:
//proj3.cpp
#include<iostream>
using namespace std ;
class Person
char * idcardno ; //用动态空间存储的身份证号
char * name,//用动态空间存储的姓名
bool ismale ; //性别:true为男,false为女
public :
Person( const char * pid,const char * pname,bool pmale) ;
~Person( )
//**1************found**********
(1) ;
const char * getIDCardNO ( ) const return idcardno ;
const char * getName ( ) const return name ;
void rename( const char * new_name) ;
bool isMale( ) const return ismale ;
;
class Staff: public Person
char * department;
double salary;
public :
Staff( const char * id_card_no,const char * p_name,bool is_male,const char * dept,double sal) ;
~Staff( ) delete [ ] department;
const char * getDepartment( ) const return department;
void setDepartment( const char * d) ;
double getSalary( ) const return salary ,
void setSalary ( double s) salary=s ;
;
Person: :Person( const char * id_card_no,const char * p_name,bool is_male) :ismale(is_male)
idcardno=new char[ strlen( id_card_no) +1] ;
strcpy(idcardno,id_card_no) ;
name=new char[ strlen ( p_name) +1] ;
strcpy( name,p_name) ;
void Person: :rename( const char * new_name)
delete [ ] name;
//**2************found**********
(2) ;
strcpy( name,new_name) ;
Staff::Staff( const char * id_card_no , const char * p_name ,bool is_rnalc,
//**3************found**********
const char * dept,double sal) : (3)
deparlment=new char [ strlen ( clept) +1 ];
strcpy( department,dept) ;
salary=sal;
void Staff::setDepartment( consl char * dept)
delete [ ] department;
department=new char [ strlen ( dept) +1 ] ;
strcpy( department,dept) ;
int main( )
Staff Zhangsan ("123456789012345","张三",false,"人事部",1234.56 ) ;
Zhangsan. rename("张小丽") ;
cout<<Zhangsan. getName ( )<<Zhangsan. getIDCardNO ( )<<endl;
return 0;
参考答案:delete[]idcardno; delete[]name;
解析: 在“//**2************found**********”的下方是rename()函数中的一个语句,它使指针name指向申请到的足够容纳字符串new_name的空间。