C++學(xué)生管理系統(tǒng)課程設(shè)計(jì)-源代碼_第1頁
C++學(xué)生管理系統(tǒng)課程設(shè)計(jì)-源代碼_第2頁
C++學(xué)生管理系統(tǒng)課程設(shè)計(jì)-源代碼_第3頁
C++學(xué)生管理系統(tǒng)課程設(shè)計(jì)-源代碼_第4頁
C++學(xué)生管理系統(tǒng)課程設(shè)計(jì)-源代碼_第5頁
已閱讀5頁,還剩6頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上精選優(yōu)質(zhì)文檔-傾情為你奉上專心-專注-專業(yè)專心-專注-專業(yè)精選優(yōu)質(zhì)文檔-傾情為你奉上專心-專注-專業(yè)/=/student.h 定義了抽象類Person,派生了student(及為信息類)、定義了節(jié)點(diǎn)類Node、定義了鏈表類List/=#ifndef STUDATA_H#define STUDATA_H#include /=int GetID();class List;/-class Person /抽象類protected:int ID; /學(xué)號(hào)char Name15; /姓名public:virtual bool operator(Person&)=0; /=(Pe

2、rson&)=0; /=運(yùn)算符重載;/-class Student:public Person /學(xué)生類int Score4; /成績(jī)void SwapData(Student*); /交換數(shù)據(jù)public:Student(int =0,char* =NULL,int* =NULL); /構(gòu)造函數(shù)bool operator(Person&); /=(Person&); /=運(yùn)算符重載friend ofstream&operator(ofstream&,Student*); /(ifstream&,Student*); /運(yùn)算符重載從文件輸入 friend ostream_withassign&

3、 operator(ostream_withassign&,Student*); /(istream_withassign&,Student*); /運(yùn)算符重載從鍵盤輸入friend class List;/-class Node /結(jié)點(diǎn)類Student *Stup; /指向?qū)W生對(duì)象指針Node *Prev,*Next; /指向前后結(jié)點(diǎn)指針public:Node(); /構(gòu)造函數(shù)Node(Student*); /構(gòu)造函數(shù)Node(Node&); /拷貝構(gòu)造函數(shù)Node(); /析構(gòu)函數(shù)friend class List;/-class ListNode *Head,*Tail; /鏈表頭尾指針

4、void InitList(); /初始化函數(shù)public:List(); /構(gòu)造函數(shù)List(); /析構(gòu)函數(shù)void ClearList(); /清空鏈表Node *FindID(int&); /根據(jù)學(xué)號(hào)尋找學(xué)生所在結(jié)點(diǎn) 指針型函數(shù)void Insert(Node*); /插入一個(gè)學(xué)生Node *CreateNode(Student*); /建立一個(gè)學(xué)生結(jié)點(diǎn) 指針型函數(shù)void Add(); /增加一個(gè)學(xué)生void Update(); /修改學(xué)生成績(jī)void Delete(); /刪除一個(gè)學(xué)生void Query(); /查找一個(gè)學(xué)生void SortID(); /按學(xué)號(hào)排序void So

5、rtScore(); /按學(xué)生總成績(jī)排序void SaveBin(); /以二進(jìn)制形式保存數(shù)據(jù)void PrintList(); /顯示鏈表void PrintTitle(); /顯示標(biāo)題void PrintOne(Student*); /顯示一個(gè)學(xué)生數(shù)據(jù);#endif/=/student.cpp的實(shí)現(xiàn)/=#include #include #include #include student.h/=Student:Student(int id,char *name,int *score) /構(gòu)造函數(shù)ID=id;if(name!=NULL)strcpy(Name,name);if(score!=

6、NULL)for(int i=0;i=3;i+)Scorei=scorei;bool Student:operator(Person& per) Student &stu=(Student&)per; return (Score3=(Person& per) return (!operator=stu.Score3)void Student:SwapData(Student* stup) /學(xué)生數(shù)據(jù)交換 this指針指向調(diào)用成員函數(shù)的對(duì)象 Student t=*this; *this=*stup; *stup=t;ifstream& operator(ifstream& in,Student*

7、 stup) /運(yùn)算符重載從文件輸入in.read(char*)stup,sizeof(Student); /從相應(yīng)的流中提取sizeof(Student)個(gè)字節(jié),并把它們放入stup所指的緩沖區(qū)中return in;ofstream& operator(ofstream& out,Student* stup) /(istream_withassign& in,Student *stup) /運(yùn)算符重載從標(biāo)準(zhǔn)文件輸入int i;coutInput Name,Score1-Score3endl;coutstup-Name;stup-Score3=0;for(i=0;i3;i+)coutScore

8、istup-Scorei;stup-Score3+=stup-Scorei;return in; /輸入流對(duì)象in返回的到調(diào)用處ostream_withassign& operator(ostream_withassign& out,Student *stup) /運(yùn)算符重載輸出至標(biāo)準(zhǔn)文件 outIDsetw(8)Namesetw(8) Score0setw(10)Score1setw(10) Score2setw(10)Score3endl; outendl;return out; /輸處流對(duì)象out返回的調(diào)用處/*int i;outIDtNamet ;for (i=0;i4;i+)outS

9、coreit;outendl;return out;*/=/node.cpp的實(shí)現(xiàn)/=#include#includestudent.h/-Node:Node()Stup=NULL;Prev=Next=NULL;Node:Node(Student *stup)/默認(rèn)的構(gòu)造函數(shù),完成建立一個(gè)空節(jié)點(diǎn)Stup=stup;Prev=Next=NULL;Node:Node(Node &node) /復(fù)制構(gòu)造函數(shù)的實(shí)現(xiàn)OKStup=node.Stup;Prev=node.Prev;Next=node.Next;Node:Node() /釋放空間delete Stup; /=/list.cpp的實(shí)現(xiàn)/=#i

10、nclude #include #include student.h/=List:List() /構(gòu)造函數(shù)Head=Tail=new Node(); /建立鏈表頭結(jié)點(diǎn) Head-Next=NULL;Head-Prev=NULL;InitList(); /從文件讀取數(shù)據(jù) 在下面調(diào)用此函數(shù)List:List() /析構(gòu)函數(shù)ClearList(); /在下面調(diào)用此函數(shù)delete Head; /釋放空間void List:InitList() /從文件讀取數(shù)據(jù) ifstream inStudent;ofstream outStudent;inStudent.open(gx.dat,ios:binar

11、y); /打開學(xué)生文件if(!inStudent) /文件不存在,建立該文件inStudent.close();outStudent.open(gx.dat,ios:binary);outStudent.close(); /關(guān)閉文件else /文件存在,讀取學(xué)生數(shù)據(jù)Student *stup=new Student();Node *nodep;inStudentstup;while(!inStudent.eof() /未達(dá)到文件尾端則執(zhí)行循環(huán),否則退出循環(huán)nodep=CreateNode(stup); /調(diào)用GreateNode()函數(shù) 建立一個(gè)學(xué)生結(jié)點(diǎn) 指針型函數(shù)Insert(nodep);

12、stup=new Student();inStudentstup;delete stup;inStudent.close();void List:Add() /增加一個(gè)學(xué)生Student *stup;Node *nodep;int id=GetID();if(nodep=FindID(id)!=NULL)throw(1); /輸入學(xué)號(hào)相同,拋出異常stup=new Student();stup-ID=id;cinstup; /運(yùn)算符重載nodep=CreateNode(stup);Insert(nodep);PrintTitle();PrintOne(stup);void List:Updat

13、e() /修改學(xué)生成績(jī) int id=GetID(); Node *nodep;if (FindID(id)!=NULL)nodep=FindID(id);elsecoutStup-Score3=0; for(int i=0;i3;i+)coutscoreinodep-Stup-Scorei;nodep-Stup-Score3+=nodep-Stup-Scorei;PrintTitle(); PrintOne(nodep-Stup);void List:Delete() /刪除一個(gè)學(xué)生 int id=GetID();Node *nodep;if (nodep=FindID(id)!=NULL)

14、nodep-Prev-Next=nodep-Next;if(nodep=Tail)Tail=nodep-Prev;elsenodep-Next-Prev=nodep-Prev;delete nodep;PrintList();void List:Query() /查詢學(xué)生數(shù)據(jù)int id=GetID();Node *nodep;if (FindID(id)!=NULL)nodep=FindID(id);PrintTitle();PrintOne(nodep-Stup);elsecoutNext!=NULL)nodep=Head-Next;Head-Next=Head-Next-Next;del

15、ete nodep;Tail=Head;Node*List:FindID(int& id) /查找學(xué)號(hào)Node *nodep=Head-Next;while(nodep!=NULL&nodep-Stup-ID!=id)nodep=nodep-Next;return nodep;void List:Insert(Node *nodep) /在鏈表尾插入一個(gè)學(xué)生 *我有問題* Tail-Next=nodep;nodep-Prev=Tail;Tail=nodep;void List:SortID() /按學(xué)號(hào)排序 *我有問題*Node *nodef,*nodel=Tail;if(Head!=Tail

16、)while(Head-Next!=nodel)nodef=Head-Next;while(nodef!=nodel)if(nodef-Stup-IDnodef-Next-Stup-ID)nodef-Stup-SwapData(nodef-Next-Stup);nodef=nodef-Next;nodel=nodel-Prev;PrintList();void List:SortScore() /按總成績(jī)排序/學(xué)生設(shè)計(jì) Node*nodef,*nodel=Tail; if(Head!=Tail)while(Head-Next!=nodel)nodef=Head-Next;while(nodef

17、!=nodel)if(nodef-Stup-Score3Next-Stup-Score3)nodef-Stup-SwapData(nodef-Next-Stup);nodef=nodef-Next;nodel=nodel-Prev;PrintList();void List:SaveBin() /鏈表數(shù)據(jù)保存在二進(jìn)制文件 ofstream outStudent; outStudent.open(gx.dat,ios:binary); Node *nodep=Head-Next; while(nodep!=NULL) outStudentStup; nodep=nodep-Next; outSt

18、udent.close();Node*List:CreateNode(Student*stup) /建立一個(gè)學(xué)生對(duì)象Node *nodep=new Node(stup);return nodep;void List:PrintList() /顯示鏈表中數(shù)據(jù)Node *nodep=Head-Next ;if(Head!=Tail)/學(xué)生設(shè)計(jì)PrintTitle();while(nodep!=NULL)PrintOne(nodep-Stup);nodep=nodep-Next;coutendl;elsecoutNo studentendl; void List:PrintTitle()coutID Name Score1 Score2 Score3 Scoreendl;void List:PrintOne(Student*stup)coutstup; /運(yùn)算符重載/=/main.cpp主函數(shù)的實(shí)現(xiàn)/=#include #include student.h/=int EnterChoice(); /輸入選項(xiàng)int GetID(); /輸入學(xué)號(hào)enum ChoicesADD=1,UPDATE,DELETE,QUERY,DISPLAY,SORTID,SORTSCORE,END;void main()List ls;int choice;while(choice=EnterCho

溫馨提示

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

評(píng)論

0/150

提交評(píng)論