第二周 項目三 用結構體資料做運算

來源:互聯網
上載者:User

上機目的:資料結構體

上機內容:獲得獎學金的人以及排名

 

/*    .* 程式的著作權和版本聲明部分    .* Copyright (c)2013, 煙台大學電腦學院學生    .* All rightsreserved.    .* 檔案名稱:text.cpp    .* 作者:劉玉金   .* 完成日期: 2013年3月18日    .* 版本號碼: v1.0    .* 輸入描述:從檔案中獲得學生名單.* 問題描述:  求學生的排名以及獲得獎學金的人.* 輸出:  學生的排名以及獲得獎學金的的人 */    #include <iostream>  #include <iostream>   #include <fstream>   #include <cstdlib> using namespace std;  struct Student  {      char num[13];    char name[10]; int  cpp;    int math;      int english;      int grade;  };  const int N=200;  int main( )  {      int i, j, k, stuNum=0;         Student stu[N], t_stu;          ifstream infile("score.txt",ios::in);          if(!infile)                     {          cerr<<"open error!"<<endl;          exit(1);  }      i=0;      while(!infile.eof())      {          infile>>stu[i].num>>stu[i].name>>stu[i].cpp>>stu[i].math>>stu[i].english;          stu[i].grade=stu[i].cpp+stu[i].math+stu[i].english;          ++stuNum;          ++i;      }      infile.close();      for(i=0; i<stuNum-1; i++)      {          k=i;          for(j=i+1; j<stuNum; j++)              if(stu[j].grade>stu[k].grade) k=j;   t_stu=stu[k];         stu[k]=stu[i];  stu[i]=t_stu;      }      for(i=0; i<stuNum; ++i)      {          cout<<stu[i].num<<"\t"<<stu[i].name<<"\t"<<stu[i].cpp<<"\t"<<stu[i].math<<"\t"<<stu[i].english<<"\t"<<stu[i].grade<<endl;      }  cout<<"恭喜以下同學獲得獎學金"<<endl;      i=0,j=1;  while (j<=30)      {          if (stu[i].cpp>=60&&stu[i].math>=60&&stu[i].english>=60)          {              cout<<j<<'\t'<<stu[i].name<<'\t'<<stu[i].grade<<endl;              j++;  }          i++;      }           return 0;  }

運行結果:

 

心得體會:這個根據項目一與項目二的結合,進行運算的。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.