阅读下列说明和C++代码,填充代码中的空缺,将解答填入答题纸的对应栏内。 【说明】 某学校在学生毕业时要求对其成绩进行综合评定,学生的综合成绩(GPA)由其课程加权平均成绩(Wg)与附加分(Ag)构成,即GPA=Wg+Ag。 设一个

admin2013-07-03  19

问题 阅读下列说明和C++代码,填充代码中的空缺,将解答填入答题纸的对应栏内。
    【说明】
    某学校在学生毕业时要求对其成绩进行综合评定,学生的综合成绩(GPA)由其课程加权平均成绩(Wg)与附加分(Ag)构成,即GPA=Wg+Ag。
    设一个学生共修了n门课程,则其加权平均成绩(Wg)定义如下:
    其中,gradei、Ci分别表示该学生第i门课程的百分制成绩及学分。
    学生可以通过参加社会活动或学科竞赛获得附加分(Ag)。学生参加社会活动所得的活动分(Apoints)是直接给出的,而竞赛分(Awards)则由下式计算(一个学生最多可参加m项学科竞赛):
    其中,li和Si分别表示学生所参加学科竞赛的级别和成绩。
    对于社会活动和学科竞赛都不参加的学生,其附加分按活动分为0计算。
    下面的程序实现计算学生综合成绩的功能,每个学生的基本信息由抽象类Student描述,包括学号(stuNo)、姓名(name)、课程成绩学分(grades)和综合成绩(GPA)等,参加社会活动的学生由类ActStudent描述,其活动分由Apoints表示,参加学科竞赛的学生由类CmpStudent描述,其各项竞赛的成绩信息由awards表示。
    【C++代码】
    #include
    #include
    using namespace std;
    const int n=5;    /*课程数*/
    const int m=2;    /*竞赛项目数*/
    class Student{
    protected:
        int stuNo;string name;
        double GPA;    /*综合成绩*/
        int(*grades)[2];    /*各门课程成绩和学分*/
    public:
        Student(const int stuNo,const string&name,int grades[][2]){
            this->stuNo=stuNo;this->name=name;this->grades=grades;
    }
    Virtual~Student(){}
    int getstuNo(){/*实现略*/}
    string getName(){/*实现略*/}
      (1)  
    double computeWg(){
        int totalGrades=0,totalCredits=0:
        for(int i=0;i<N;i++){
            totalGrades+=grades[0]*grades[1];totalGredits+=grades[1];
        }
     return GPA=(double)totalGrades/totalCredits;
  }
};
class ActStudent;public Student{
int Apoints;
public;
  ActStudent(const int stuNo,const string&name,int gs[][2],int Apoints)
  (2)  {
    this->Apoints=Apoints:
  }
  double getGPA(){return GPA=  (3)  ;}
};
    class CmpStudent:public Student{
    private:
        int(*awards)[2];
    public:
        cmpstudent(const int stuNo,const string&name,int gs[][2],int awards[][2])
        :  (4)  {    this->award=award;}
        double getGPA()f
            int Awards=0;
            for(int i=0;i<M;i++){
                Awards+=awards[0]*awards[1]:
            }
            Return GPA=  (5)  
        }
    };
int main()
{    //以计算3个学生的综合成绩为例进行测试
    int g1[][2]={{80,3},{90,2},{95,3},{85,4},{86,3}},
        g2[][2]={{60,3},{60,2),{60,3},{60,4},{65,3}},
        g3[][2]={{80,3},(90,2},{70,3},{65,4},{75,3}};    //课程成绩
    int c3[][2]={{2,3},{3,3)};    //竞赛成绩
    Student*student[3]={
        new ActStudent(101,”John”,g1,3),    //3为活动分
        new ActStudent(102,”Zhang”,g2,0),
        new ActStudent(103,”Li”,g3,c3),
    };
    //输出每个学生的综合成绩
    for(int i=0;i<3;i++)
        cout<<  (6)  <<end1;
    delete*student;
    return 0;
}

选项

答案(1)virtual double getGPA()=0 (2)Student(stuNo,name,gs) (3)computeWg()+Apoints或Student::computeWg()+Apoints (4)Student(stuNo,name,gs) (5)computeWg()+Awards或Student::computeWg()+Awards (6)students[i]->getGPA()

解析 本题的程序功能是计算学生的综合成绩(GPA)其中GPA由其课程加权平均成绩Wg与附加分Ag构成,即GPA=Wg+Ag。首先定义了一个getGPA()函数并为函数赋初始为0,(1)填virtual double getGPA()=0,其中virtual是指在windows下C++的开发环境,double定义了GPA的值都为双精度浮点数。(2)是计算学生的活动的附加分,调用Student()函数,括号内的变量用已经定义过的变量名替代,即Student(stuNo,name,gs)。在Student()函数中调用了getGPA函数,引用了题目中给的公式GPA=Wg+Ag,所以(3)应填computeWg()+Apoints。(4)是计算学生竞赛的附加分的函数,其中又调用了一次Student函数,所以同(2)一样填Student(stuNo,name,gs)。(5)同(3)一样,是在Student函数中调用了get-GPA函数,引用了题目中给的公式GPA=Wg+Ag,所以(5)应填computeWg()+Awards,与(3)不同的是,这次Wg加的是竞赛的附加分。(6)是在主函数的for循环里面,由于共有3个学生,所以i的取值范围为0~3,并将students的值赋值给GPA,所以(6)应填students->getGPA()。
转载请注明原文地址:https://kaotiyun.com/show/knjZ777K
0

相关试题推荐
最新回复(0)