请打开考生文件夹下的解决方案文件proj1,程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:Name:Smith Age:21 ID:99999 CourseNum:12 Record:970
注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。
#include< iostream >
using namespace std;
class StudentInfo
{
protected:
//ERROR*******found*******
char Name;
int Age;
int ID;
int CourseNum;
float Record;
public:
StudentInfo(char*name,intAge,int ID,int courseNum,float record);
//ERROR*******found*******
VOid~StudentInfo( ){}
float AVerageRecord( ){
return Record/CourseNum;
}
void show( )const{
cout< < "Name:"< < Name< < "Age:"< < Age< < "ID:"< < ID
< < "CourSeNum:"< <
CourSeNum< < "ReCOrd:"< < Re-cord< < endl;
}
};
//ERROR*******found*******
StudentInfo StudentInfo(char*Name,int Age,int ID,intCourseNum,float Record)
{
Name=name;
Age=age;
this- >ID=ID;
CourSeNum=courSeNum;
Record=record;
}
int main( )
{
StudentInfo st("Smith",21,99999,12,970);
st.show( );
return0;
}
【正确答案】(1)char*Name;
(2)~StudentInfo( ){}
(3)Studentlnfo::Studentlnfo(char*name,int age,int ID,int courseNum,float record)
【答案解析】(1)主要考查考生对动态数组的掌握,由题目可知Name应该指向一个动态数组,而不是一个有效char型字符,因此要定义成char型指针。
(2)主要考查考生对析构函数的掌握,析构函数不需要函数返回类型,应把void去掉。
(3)主要考查考生对构造函数定义的掌握,构造函数也要使用作用域符号“::”。