#include#includeusingnamespacestd;classStudent{private:stringsNO;//學號intcre..."/>

中文字幕综合一区,伊人av网,欧美中日韩在线,亚洲国产香蕉视频,黄视频在线免费,天天操天天爱天天爽,狠狠躁天天躁

軟題庫 移動APP 掃碼下載APP 隨時隨地移動學習 培訓課程
試卷名稱 2010年下半年程序員考試下午真題試題(案例分析)
考試中心《2010年下半年程序員考試下午真題試題(案例分析)》在線考試
試卷年份2010年下半年
試題題型【分析簡答題】
試題內容

閱讀以下說明和C++代碼,將應填入 (n) 處的語句或語句成分寫在答題紙的對應欄內。
【說明】
某數(shù)據(jù)文件students.txt的內容為100名學生的學號和成績,下面的程序將文件中的數(shù)據(jù)全部讀入對象數(shù)組,按分數(shù)從高到低進行排序后選出排名前30%的學生。
【C++代碼】
#include <iostream>
#include <fstream>
#include <string>
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%: "<<end1;
   for(k = 0; k < number * 0.3; k++) {
    testStudent[k].out();
   }
   delete [ ]testStudent;
   return 0;
}


相關試題

推薦文章
合作網站內容