请使用“答题”菜单或使用VC6打开考生文件夹proj1

请使用“答题”菜单或使用VC6打开考生文件夹proj1下的工程文件 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[30] ;
    int Age;
    int ID;
    int CourseNum;
    float Record;
public:
    // ERROR ********* found *********
    void StudentInfo (char * name , int age, int ID , int courseNum , float record );
    ~StudentInfo( ) { delete [ ] Name ; }
    float AverageRecord( ) {
        return Record/CourseNum;
    }
    void show( ) const;
};
StudentInfo :: StudentInfo ( char * name, int age, int ID, int courseNum, float record)
{
    Name = strdup(name);
    Age = age;
    this -> ID = ID;
    CourseNum = courseNum;
    Record = record;
}
// ERROR ********* found *********
void StudentInfo::show( )
{
    cout << "Name: " << Name << " " << "Age: " << Age << " " << " ID: " << ID
         << "    CourseNum: " <<CourseNum<< "    Record: " <<Record<< endl;
}
int main()
{
    StudentInfo st("Smith",21,99999,12,970);
    st.show();
    return 0;
}
答案
第1空:Char *Name;
第2空:StudentInfo(char *name,int age,int ID,int courseNum,float record);
解析

第1处应该定义一个指向字符型的指针char *Name,并与下面的函数语句(char *name,int age,int ID,int courseNum,float record)对应,所以应该将charName[30]修改为char *Name。

第2处因为该函数内有返回值Record/CourseNum,所以应该删掉void。

第3处const表示对上一个函数的重载,所以需要加上const,改为void StudentInfo::show()const。

题目信息

题号:7752
题型:填空题
知识点:计算机二级
难度:普通