问答题
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:Name:SmithAge:21ID:99999CourseNum:12Record:970注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。#include<iostream>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:¨<<Name<<"Age:"<<Age<<"ID:"<<ID<<"CourseNum:"<<CourseNum<<”Record:"<<Record<<end1; }};//ERROR**********found**********StudentInfoStudentInfo(char*Name,intAge,intID,intCourseNumlfloatRecord){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)主要考查考生对构造函数定义的掌握,构造函数也要使用作用域符号“::”。