閱讀以下說明和C++代碼,填充代碼中的空缺,將解答填入答題紙的對應(yīng)欄內(nèi)。
【說明】
某學(xué)校在學(xué)生畢業(yè)時要對其成績進(jìn)行綜合評定,學(xué)生的綜合成績(GPA)由其課程加權(quán)平均成績(Wg)與附加分(Ag)構(gòu)成,即GPA= Wg +Ag。
設(shè)一個學(xué)生共修了n門課程,則其加權(quán)平均成績 (Wg) 定義如下:
其中 ,gradei 、Ci 分別表示該學(xué)生第 i 門課程的百分制成績及學(xué)分。
學(xué)生可以通過參加社會活動或?qū)W科競賽獲得附加分(Ag)。學(xué)生參加社會活動所得的活動分(Apoints)是直接給出的,而競賽分(Awards)則由下式計(jì)算(一個學(xué)生最多可參加m項(xiàng)學(xué)科競賽):
其中 ,li 和 Si 分別表示學(xué)生所參加學(xué)科競賽的級別和成績。
對于社會活動和學(xué)科競賽都不參加的學(xué)生,其附加分按活動分為0計(jì)算。
下面的程序?qū)崿F(xiàn)計(jì)算學(xué)生綜合成績的功能,每個學(xué)生的基本信息由抽象類Student描述,包括學(xué)號(stuNo)、姓名(name) 、課程成績學(xué)分(grades) 和綜合成績 (GPA)等,參加社會活動的學(xué)生由類ActStudent描述,其活動分由Apoints表示,參加學(xué)科競賽的學(xué)生由類CmpStudent描述,其各項(xiàng)競賽的成績信息由awards表示。
【 C++代碼】
#include <string>
#include <iostream>
using namespace std;
const int N=5; /*課程數(shù)*/
const int M=2; /*競賽項(xiàng)目數(shù)*/
class Student{
protected:
int stuNo; string name;
double GPA; /*綜合成績*/
int (*grades) [2]; /*各門課程成績和學(xué)分*/
public:
Student ( const int stuNo ,const string &name ,int grades[ ] [2] ){
this->stuNo = stuNo; grades; this->name = name; this->grades =
grades;
}
virtual ~Student( ) { }
int getStuNo( ) {/*實(shí)現(xiàn)略*/ }
string getName( ) {/*實(shí)現(xiàn)略*/ }
(1) ;
double computeWg ( ){
int totalGrades = 0 ,totalCredits = 0;
for (int i = 0; i < N; i++) {
totalGrades += grades [i] [0] * grades [i] [1]; totalCredits +=
grades [i] [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->awards = awards;}
double getGPA( ) {
int Awards = 0;
for (int i = 0; i < M; i++) {
Awards += awards [i] [0] * awards [i] [1];
}
return GPA = (5) ;
}
}
int main ( )
{ //以計(jì)算 3 個學(xué)生的綜合成績?yōu)槔M(jìn)行測試
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* students[3] = {
new ActStudent (101,"John" ,g1,3) , //3 為活動分
new ActStudent (102 ,"Zhang" ,g2 ,0),
new CmpStudent (103 ,"Li" ,g3 ,c3) ,
};
//輸出每個學(xué)生的綜合成績
for(int i=0; i<3; i++)
cout<< (6) <<endl;
delete *students;
return 0;
}