2023年全國碩士研究生考試考研英語一試題真題(含答案詳解+作文范文)_第1頁
已閱讀1頁,還剩5頁未讀, 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、<p><b>  C++課程設計作業</b></p><p>  題目:學 生 成 績 管 理</p><p><b>  班級:xxxx</b></p><p><b>  學號:xxxxxx</b></p><p><b>  姓名:xxx</b

2、></p><p>  設計題目:學生成績管理</p><p>  設計內容:完成學生信息(學號,姓名,性別,年齡,高數成績,英語成績,C++程序設計成績)的初始化、統計及結果輸出。</p><p> ?、俪跏蓟簭逆I盤輸入基本信息,或者從磁盤文件中讀取。</p><p> ?、诓樵兗敖y計信息如下:</p><p&g

3、t;  ·按學號查詢某學生信息,并將結果輸出顯示。</p><p>  ·統計平均分不及格的學生,并輸出其學號、姓名、平均成績。</p><p>  ·按平均分由高到低排序輸出學生的所有信息(但不能破壞原有的存儲信息)。</p><p>  ·在完成排序輸出的同時,在“平均成績”后面列出每個同學的名次,若分數相同,則名次相同(

4、選做)。</p><p> ?、鄞鎯Γ簩⑴判蚪Y果存儲到磁盤文件中去,</p><p><b>  系統大致流程圖如下</b></p><p><b>  實現代碼:</b></p><p>  #include<iostream.h></p><p>  #inc

5、lude<string.h></p><p>  #include <fstream.h></p><p>  class Student{ //學生類</p><p>  protected:</p><p>  int no; //學號</p><p>  int

6、age,sex; //性別,年齡</p><p>  char name[10]; //姓名</p><p>  float math,cpp,en; //數學成績、C++成績</p><p>  static int count; //累計總人數</p><p>  Student* next;<

7、;/p><p>  float aver;</p><p><b>  int l;</b></p><p><b>  public:</b></p><p>  Student( ){ }</p><p>  Student(int,char*,int,int,float,

8、float,float,Student* =NULL);</p><p>  void show1( ) const //輸出每位學生的基本信息</p><p>  { cout<<no<<'\t'<<name<<'\t'<<sex<<'\t'<<age

9、<<'\t'</p><p>  <<math<<'\t'<<cpp<<'\t'<<en<<endl;</p><p><b>  }</b></p><p>  void show2() //輸出平均分不及格的

10、學生</p><p>  {aver=(math+cpp+en)/3;</p><p>  if (aver<60) cout<<no<<'\t'<<name<<'\t'<<aver<<endl;</p><p><b>  }</b>

11、</p><p>  float outa()</p><p><b>  {</b></p><p>  return (math+cpp+en)/3;</p><p><b>  }</b></p><p>  void show3( ) //輸出每位學生的基本信息&

12、lt;/p><p>  { cout<<no<<'\t'<<name<<'\t'<<sex<<'\t'<<age<<'\t'</p><p>  <<math<<'\t'<<cpp&

13、lt;<'\t'<<en<<'\t'<<l<<endl;</p><p><b>  }</b></p><p>  friend class StuList; //友元類</p><p><b>  };</b></p>

14、<p>  Student::Student(int no,char*name,int age,int sex,float math,</p><p>  float cpp,float en,Student*next)</p><p>  { Student::no=no; strcpy(Student::name,name);</p><p>  t

15、his->math=math; this->cpp=cpp; this->next=next;</p><p>  this->age=age;this->sex=sex;this->en=en;</p><p>  count++; }</p><p>  class StuList{</p><p>

16、  Student*head;</p><p><b>  public:</b></p><p>  StuList( )</p><p>  { head=NULL; }</p><p>  ~StuList( );</p><p>  void create( );

17、 //創建鏈表</p><p>  void print( ) const; //輸出鏈表</p><p>  void find(); //根據學號查詢</p><p>  void nopass(); //輸出不不及格</p><p>

18、;  void paixu();</p><p>  void save();</p><p><b>  };</b></p><p>  StuList::~StuList( ){</p><p>  Student*p;</p><p>  while(head)</p>&l

19、t;p>  { p=head; head=head->next; delete p; }</p><p><b>  }</b></p><p>  void StuList::create( ){ //尾結點插入法創建單向鏈表</p><p>  Student*p1,*p2;</p><p>  

20、int no,age,sex;</p><p>  char name[10];</p><p>  float math,cpp,en;</p><p>  cout<<"輸入學號,-1表示結束:";</p><p><b>  cin>>no;</b></p>

21、<p>  while(no!=-1){</p><p>  cout<<"輸入姓名、年齡、性別(0代表男性,1代表女性)及數學、C++語言成績、英語成績:";</p><p>  cin>>name>>age>>sex>>math>>cpp>>en;</p>

22、<p>  p1=new Student(no,name,age,sex,math,cpp,en);</p><p>  if(!head) head=p1,p2=p1;else p2->next=p1,p2=p1;</p><p>  cout<<"輸入學號,-1表示結束:";</p><p><b>  

23、cin>>no;</b></p><p><b>  }</b></p><p><b>  }</b></p><p>  void StuList::print( ) const</p><p>  { Student* p=head;</p><

24、p>  cout<<"學號\t姓名\t性別\t年齡\t數學\tC++\t英語\n";</p><p>  while( p ){ p->show1( ); p=p->next; }</p><p><b>  }</b></p><p>  void StuList::save( ) <

25、;/p><p><b>  { </b></p><p>  ofstream outfile("data.txt");</p><p>  Student* p=head;</p><p>  outfile<<"學號\t姓名\t性別\t年齡\t數學\tC++\t英語\n&qu

26、ot;;</p><p>  while( p ){outfile<<p->no<<'\t'<<p->name<<'\t'<<p->sex<<'\t'<<p->age<<'\t'<<p->math<<&

27、#39;\t'<<p->cpp<<'\t'<<p->en<<'\t'<<endl;</p><p>  ; p=p->next; }</p><p>  cout<<"保存完畢"<<endl; </p><

28、;p><b>  }</b></p><p>  int Student::count; //定義靜態數據成員并初始化</p><p>  void StuList::find() //查找函數</p><p><b>  { int t;</b></p><p>  int

29、flag=0; //標志是否查到數據,查到為1,否則為0</p><p>  cout<<"請輸入學號:";</p><p><b>  cin>>t;</b></p><p>  Student* p=head;</p><p>  while( p )</p&g

30、t;<p>  {if (t==p->no){cout<<"學號\t姓名\t性別\t年齡\t數學\tC++\t英語\n"; p->show1();flag=1;};</p><p>  p=p->next; }</p><p>  if (flag==0){cout<<"很抱歉,沒有此記錄存在!&quo

31、t;<<endl;}</p><p><b>  }</b></p><p>  void StuList::nopass()</p><p>  { Student* p=head;</p><p>  cout<<"學號\t姓名\t平均分\n";</p>&l

32、t;p>  while( p ){ p->show2( ); p=p->next; }</p><p><b>  }</b></p><p>  void StuList::paixu()</p><p><b>  {int n=0;</b></p><p>  Stude

33、nt* p=head;</p><p>  while( p ){p->l=0;Student* q=head; </p><p>  while( q ){if (p->outa()<q->outa()&&p!=q) (p->l)++; </p><p>  //cout<<"p:"

34、;<<p->outa()<<"q:"<<q->outa()<<"排名1:"<<p->l<<endl;</p><p>  q=q->next; </p><p><b>  }</b></p><p><

35、b>  (p->l)++;</b></p><p>  p=p->next; </p><p><b>  }</b></p><p>  Student* s=head;</p><p>  while( s ){ n++; s=s->next; } //得到鏈表的數目<

36、;/p><p>  cout<<"學號\t姓名\t性別\t年齡\t數學\tC++\t英語\t排名\n";</p><p>  for (int i=1;i<=n;i++)</p><p><b>  {</b></p><p>  Student* r=head;</p>

37、<p>  while( r ){if(r->l==i) r->show3(); r=r->next; }</p><p><b>  }</b></p><p><b>  }</b></p><p>  int main( )</p><p><b>  

38、{int n;</b></p><p>  cout<<"**********學生成績管理**********"<<endl;</p><p>  cout<<"--------------------------------"<<endl;</p><p>  co

39、ut<<"----------初始化數據------------"<<endl;</p><p>  StuList li;</p><p>  li.create( );</p><p>  li.print( );</p><p>  menu:cout<<"\n\n

40、 ☆☆☆☆主菜單☆☆☆☆"<<endl</p><p>  <<" * * * * * * * * * * * * * * * * * * * * * * * *"<<endl</p><p>  <<" 1: 按學號查詢學生 "<<e

41、ndl</p><p>  <<" 2: 輸出平均分不及格的學生 "<<endl</p><p>  <<" 3: 按平均分從高到低輸出學生信息 "<<endl</p><p>  <<" 4:

42、 保存數據 "<<endl</p><p>  <<" 0: 退出系統 "<<endl</p><p>  <<" * * * * * * * * * * * * * * * * * * * * * * * *"<<end

43、l</p><p>  <<" 請選擇:";</p><p><b>  cin>>n;</b></p><p>  switch (n)</p><p>  {case 1: li.find();break;</p><p&

44、gt;  case 2: li.nopass();break;</p><p>  case 3:li.paixu();break;</p><p>  case 4:li.save();break;</p><p>  case 0:;return 0;</p><p>  default:cout<<"輸入錯誤&qu

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論