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

admin2015-06-27  24

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

选项

答案(1)char*Name; (2)~StudentInfo(){} (3)Studentlnfo::StudentInfo(char*nalne,intage,intID,intcourseNum,floatrecord)

解析 (1)主要考查考生对动态数组的掌握,由题目可知Name应该指向一个动态数组,而不是一个有效char型字符,因此要定义成char型指针。
(2)主要考查考生对析构函数的掌握,析构函数不需要函数返回类型,应把void去掉。
(3)主要考查考生对构造函数定义的掌握,构造函数也要使用作用域符号“::”。
转载请注明原文地址:https://kaotiyun.com/show/CDNp777K
0

最新回复(0)