操作题   请使用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[];
    int Age;
    int ID;
    int CourseNum;
    float Record;
    public:
    // ERROR ********** found**********
    void StudentInfo(char * name, int age, int ID, int courseNum, float record);
    // ERROR ********** found**********
    void  ~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;
    }
    void StudentInfo::show()const
    {
    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;
    }
 
【正确答案】char*Name; StudentInfo(char*name, int age, int ID, int courseNum, float record); ~StudentInfo(){delete[]Name;}
【答案解析】[考点] 本题考查StudentInfo类,其中涉及构造函数、析构函数和成员函数。 (1)根据构造函数的定义可知,Name应定义为指针变量。 (2)主要考查考生对构造函数定义的掌握,构造函数前不能添加任何类型。 (3)主要考查考生对析构函数定义的掌握,析构函数前不能添加任何类型。