请使用VC6或使用【答题】菜单打开考生文件夹pro1下的工程pmj1。程序中位于每个“//ERROR****found****”之后的一行语句=有错误,请加以改正。改正后程序的输出结果应该是: Name:SmithAge:21ID:99999CourseN

admin2015-06-27  32

问题 请使用VC6或使用【答题】菜单打开考生文件夹pro1下的工程pmj1。程序中位于每个“//ERROR****found****”之后的一行语句=有错误,请加以改正。改正后程序的输出结果应该是:
Name:SmithAge:21ID:99999CourseNum:12
Record:970
注意:只修改每个“//ERROR****found****”下的一行,不要改动程序中的其他内容。
#include
usingnamespacestd;
classStudentInfo
{
protected:
//ERROR**********found**********
charName[];
intAge;
intID;
intCourseNum;
floatRecord;
public:
//ERROR**********found**********
voidStudentInfo(char*name,intage,
intID,intcourseNum,floatrecord);
//ERROR**********found**********
void~StudentInfo(){delete[]
Name;}
floatAverageRecord(){
returnRecord/CourseNum;
}
voidshow()const;
};
StudentInfo::StudentInfo(char*name,intage,intID,intcourseNum,floatrecord)
{
Name=strdup(name);
Age=age;
thiS->ID=ID;
CourseNum=courseNum;
Record=record;
}
voidStudentInfo::show()const
{
cout<<"Name:"<}
intmain()
{
StudentInfost(”Smith”,21,99.999,12,970);
st.show();
return0;
}

选项

答案(1)char *Name; (2)StudentInfo(char *name, int age, int ID, int courseNum, float record); (3)~StudentInfo() { delete [] Name; }

解析 (1)根据构造函数的定义可知,Name应定义为指针变量。
(2)主要考查考生对构造函数定义的掌握,构造函数前不能添加任何类型。
(3)主要考查考生对析构函数定义的掌握,析构函数前不能添加任何类型。
转载请注明原文地址:https://jikaoti.com/ti/pkXiFFFM
0

最新回复(0)