宅男噜噜噜666在线观看,国产1区二区三区,国产日韩欧美大片,国产超碰97,国产自产视频,99久久国产综合精品色伊,亚洲午夜高清

軟題庫 學習課程
當前位置:信管網(wǎng) >> 在線考試中心 >> 試題查看
試題題型【分析簡答題】
試題內(nèi)容

閱讀以下說明和C++代碼,將應(yīng)填入 (n) 處的語句或語句成分寫在答題紙的對應(yīng)欄內(nèi)。
【說明】
某數(shù)據(jù)文件students.txt的內(nèi)容為100名學生的學號和成績,下面的程序?qū)⑽募械臄?shù)據(jù)全部讀入對象數(shù)組,按分數(shù)從高到低進行排序后選出排名前30%的學生。
【C++代碼】
#include
#include
#include
using namespace std;

class Student {
private:
string sNO;   //學號
int credit;    //分數(shù)
public:
Student(string a,int b) { sNO = a; credit = b;}
Student( ){ }
int getCredit( );
void out( );
};
(1)  ::getCredit( ) {
return credit;
}
(2)  ::out( ) {
cout << "SNO: " << sNO << ", Credit=" << credit << end1;
}
class SortStudent {
public:
void sort(Student *s, int n);
SortStudent(){}
};
void SortStudent::sort(Student *s,int n) {
for(int i = 0; i < n-1; i++) {
for(int j = i+1; j < n; j++) {
if(s[i].  (3)  < s[j]. (4) ) {
Student temp = s[i];    s[i] = s[j];    s[j] = temp;
}
}
}
}
int main(int argc, char* argv[ ])
{
const int number = 100;   //學生總數(shù)
ifstream students;
students.open("students.txt");
if(!students.is_open()) {
throw 0;
}

Student *testStudent =   (5)  [number];
int k = 0;
string s;
while (getline(students,s,’\n’)) {    //每次讀取一個學生的學號和成績
Student student(s.substr(0,s.find(’,’)), atoi(s.substr(s.find
(’,’)+1).c_str()));
testStudent[k++] = student;
}
students.close();

(6)  ;
ss.sort(testStudent,k);
cout <<"top 30%: "<for(k = 0; k < number * 0.3; k++) {
testStudent[k].out();
}
delete [ ]testStudent;
return 0;
}

查看答案

相關(guān)試題