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