深夜成人在线,chinese国产一区二区,欧美精品乱码,日韩欧美在线视频免费观看,国产午夜不卡,日韩av影院在线,五月天婷婷国产精品

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

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

class Student {
private:
string sNO;   //學(xué)號
int credit;    //分?jǐn)?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;   //學(xué)生總數(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’)) {    //每次讀取一個(gè)學(xué)生的學(xué)號和成績
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)試題