




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第2頁共41頁中南大學(xué)面向?qū)ο缶幊藽++課程設(shè)計(jì)報(bào)告題目研究生成績(jī)管理系統(tǒng)學(xué)生姓名神孟秋指導(dǎo)教師學(xué)院信息科學(xué)與工程學(xué)院_專業(yè)班級(jí)計(jì)算機(jī)科學(xué)與技術(shù)1604二○一七年十月
目錄1. 課程設(shè)計(jì)內(nèi)容 32. 課程設(shè)計(jì)目的 43. 背景知識(shí) 44. 工具/準(zhǔn)備工作 45. 設(shè)計(jì)步驟、方法等 45.1. 步驟1:相關(guān)類的定義,重載 75.2. 步驟2:?jiǎn)捂湵硐嚓P(guān)函數(shù) 135.3. 步驟3:文件操作函數(shù)的聲明與定義 225.4. 步驟4:統(tǒng)計(jì)函數(shù)的聲明與定義 265.5. 步驟5:菜單函數(shù)的書寫 285.6. 步驟6:登錄界面(密碼),歡迎界面的實(shí)現(xiàn) 316. 設(shè)計(jì)結(jié)果及分析 327. 設(shè)計(jì)結(jié)論與感想 398. 對(duì)本設(shè)計(jì)過程及方法、手段的改進(jìn)建議 399. 參考文獻(xiàn) 40
作軟件VisualStudio2017。設(shè)計(jì)步驟、方法等思路:首先,仔細(xì)閱讀課程設(shè)計(jì)題目的具體要求(這點(diǎn)很關(guān)鍵),先寫出自己的思路,如何實(shí)現(xiàn)各個(gè)功能,然后就是分幾個(gè)大塊敲代碼,每完成一個(gè)函數(shù)功能,去調(diào)試運(yùn)行,如果能運(yùn)行的話說明這塊函數(shù)大體應(yīng)該是沒有問題了,可以進(jìn)入下一模塊的書寫,否則這段代碼沒有通過。第一次進(jìn)入:登錄界面登錄界面輸入兩類研究生相關(guān)數(shù)據(jù)輸入兩類研究生相關(guān)數(shù)據(jù)退出函數(shù)退出函數(shù)exit(0)之后進(jìn)入:登錄界面登錄界面菜單界面菜單界面6.信息查找2.信息插入3.信息6.信息查找2.信息插入3.信息刪除4.信息輸出5.信息修改7.信息統(tǒng)計(jì)8.退出函數(shù)9.初始化該系統(tǒng)1.信息錄入模塊的書寫構(gòu)建順序:進(jìn)行類的定義,基類研究生,派生類學(xué)術(shù)研究生和工程研究生,類中變量的聲明,進(jìn)行重載<<,>>,使之能夠?qū)崿F(xiàn)cincout的輸入和輸出。進(jìn)行單鏈表操作的函數(shù)的書寫,使之能夠?qū)深惻缮芯可M(jìn)行鏈表的建立、輸出、插入、修改、刪除等基本操作。進(jìn)行相關(guān)文件的操作函數(shù)的聲明與定義,使程序能夠?qū)彺嬷械臄?shù)據(jù)讀到磁盤中,也可以將磁盤中的數(shù)據(jù)讀取到內(nèi)存中。統(tǒng)計(jì)函數(shù)的書寫,這部分用到了靜態(tài)變量和靜態(tài)函數(shù),程序可以實(shí)現(xiàn)基本的統(tǒng)計(jì)功能。菜單函數(shù)的書寫,這部分就是美觀,簡(jiǎn)單大方,cout語句進(jìn)行圖形繪制即可,比較容易。密碼,歡迎界面的實(shí)現(xiàn):使程序更加美觀,也能夠填寫正確的用戶名和口令方可進(jìn)入系統(tǒng)。1->2->3->4->5->6下面進(jìn)行代碼的說明:步驟1:相關(guān)類的定義,重載這部分對(duì)于整個(gè)代碼來說相對(duì)比較簡(jiǎn)單,運(yùn)用c++對(duì)類的定義,類中數(shù)據(jù)成員的聲明,重載函數(shù)的使用即可實(shí)現(xiàn),這里我著重說明一下重載部分,以學(xué)術(shù)碩士的>>重載為例(其他相似),重載的過程中輸出語句要盡可能的美觀,而輸入語句的話,我想要能夠?qū)τ脩舻恼`操作進(jìn)行處理,因?yàn)閷W(xué)號(hào)為0是退出錄入,所以當(dāng)用戶輸入0時(shí),if判斷語句判斷是否為0,若為零,returninput結(jié)束函數(shù),其他比如說成績(jī),等級(jí)的輸入都有限定,同理,if語句判斷,若為真,配合goto語句回到輸入數(shù)據(jù)前,重新輸入,這么做的好處,用戶一旦輸入錯(cuò)誤一個(gè)數(shù)據(jù),馬上會(huì)令用戶重新輸入(個(gè)人認(rèn)為,相對(duì)于一些作品,等待用戶將其全部數(shù)據(jù)輸入之后,每個(gè)數(shù)據(jù)進(jìn)行判斷,若有一個(gè)不符和要求,即不錄入數(shù)據(jù)好一些),其中浮點(diǎn)型數(shù)據(jù)的判斷比較關(guān)鍵(不能準(zhǔn)確的保存數(shù)據(jù),判斷浮點(diǎn)型數(shù)據(jù)是否==一個(gè)固定的值需要調(diào)用fabs函數(shù)實(shí)現(xiàn)),還有,在輸入的過程中有一些數(shù)據(jù)是通過計(jì)算得到,這樣的數(shù)據(jù)我在用戶輸入一些必要的數(shù)據(jù)后就會(huì)進(jìn)行賦值,調(diào)用計(jì)算函數(shù)計(jì)算賦值,用戶一旦輸入完畢,相關(guān)值便賦值給該對(duì)象的數(shù)據(jù)域。但是也是有缺點(diǎn)的,goto語句用的偏多,這點(diǎn)不利于程序的穩(wěn)定性,應(yīng)努力加強(qiáng)。源代碼(部分)://重載函數(shù)(派生類:學(xué)術(shù)碩士)istream&operator>>(istream&input,academicGraduateStudent&astu){ cout<<"學(xué)號(hào):"; input>>astu.num; if(astu.num==0) { returninput; } cout<<"姓名:"; input>>;loopse: cout<<"性別:"; input>>astu.sex; //判斷性別是否合法 if(!(astu.sex=="男"||astu.sex=="女")) { cerr<<"性別輸入有誤,請(qǐng)重新輸入!"<<endl; gotoloopse; } cout<<"年齡:"; input>>astu.age;loopc: cout<<"課程成績(jī):"; input>>astu.courseScore; if(astu.courseScore<0||astu.courseScore>100) { cerr<<"課程成績(jī)輸入有誤,請(qǐng)重新輸入!"<<endl; gotoloopc; } cout<<"專業(yè):"; input>>astu.major;looppn: cout<<"發(fā)表論文篇數(shù):"<<endl; input>>astu.paperNumber; if(!(astu.paperNumber<=3&&astu.paperNumber>0)) { cerr<<"輸入有誤,論文篇數(shù)范圍1-3"<<endl; gotolooppn; } if(astu.paperNumber>=1) { cout<<"論文一:"; input>>astu.apaper.paper1; loopff: cout<<"級(jí)別(1,2,3):"; input>>astu.apaper.paperLevel1; //判斷級(jí)別是否合法 if(!(astu.apaper.paperLevel1==1||astu.apaper.paperLevel1==2||astu.apaper.paperLevel1==3)) { cerr<<"輸入的級(jí)別有誤(級(jí)別為123),請(qǐng)重新輸入!"<<endl; gotoloopff; } loopf: cout<<"分?jǐn)?shù)一:"; input>>astu.apaper.paper1Score; //判斷分?jǐn)?shù)是否合法 if(astu.apaper.paper1Score<0||astu.apaper.paper1Score>90) { cerr<<"輸入的分?jǐn)?shù)一有誤,請(qǐng)重新輸入!"<<endl; gotoloopf; } } if(astu.paperNumber>=2) { cout<<"論文二:"; input>>astu.apaper.paper2; loopss: cout<<"級(jí)別(1,2,3):"; input>>astu.apaper.paperLevel2; if(!(astu.apaper.paperLevel2==1||astu.apaper.paperLevel2==2||astu.apaper.paperLevel2==3)) { cerr<<"輸入的級(jí)別有誤(級(jí)別為123),請(qǐng)重新輸入!"<<endl; gotoloopss; } loops: cout<<"分?jǐn)?shù)二:"; input>>astu.apaper.paper2Score; if(astu.apaper.paper2Score<0||astu.apaper.paper2Score>90) { cerr<<"輸入的分?jǐn)?shù)二有誤,請(qǐng)重新輸入!"<<endl; gotoloops; } } if(astu.paperNumber>=3) { cout<<"論文三:"; input>>astu.apaper.paper3; looptt: cout<<"級(jí)別(1,2,3):"; input>>astu.apaper.paperLevel3; if(!(astu.apaper.paperLevel3==1||astu.apaper.paperLevel3==2||astu.apaper.paperLevel3==3)) { cerr<<"輸入的級(jí)別有誤(級(jí)別為123),請(qǐng)重新輸入!"<<endl; gotolooptt; } loopt: cout<<"分?jǐn)?shù)三:"; input>>astu.apaper.paper3Score; if(astu.apaper.paper3Score<0||astu.apaper.paper3Score>90) { cerr<<"輸入的分?jǐn)?shù)三有誤,請(qǐng)重新輸入!"<<endl; gotoloopt; } } cout<<"論文成績(jī):"; astu.paperScore=astu.calculatePaperScore(); cout<<astu.paperScore<<endl; cout<<"總成績(jī):"; astu.sumScore=astu.calculateSumScore(); cout<<astu.sumScore<<endl; returninput;}classgraduateStudent{public: graduateStudent(){};//構(gòu)造函數(shù) ~graduateStudent(){};//析構(gòu)函數(shù)protected: intnum;//學(xué)號(hào) stringname;//姓名 stringsex;//性別 intage;//年齡 floatcourseScore;//課程成績(jī)};//學(xué)術(shù)碩士classacademicGraduateStudent:publicgraduateStudent{public: academicGraduateStudent*paNext;//定義一個(gè)指針,鏈表操作 academicGraduateStudent() { apaper.paper1Score=0.0; apaper.paper2Score=0.0; apaper.paper3Score=0.0; apaper.paperLevel1=0; apaper.paperLevel2=0; apaper.paperLevel3=0; };//構(gòu)造函數(shù) ~academicGraduateStudent(){};//析構(gòu)函數(shù) intgetNum()const{returnnum;}//獲取學(xué)號(hào) stringgetName()const{returnname;}//獲取姓名 floatcalculatePaperScore();//計(jì)算論文分?jǐn)?shù) floatcalculateSumScore();//計(jì)算總成績(jī) //重載函數(shù) friendostream&operator<<(ostream&,academicGraduateStudent&); friendistream&operator>>(istream&,academicGraduateStudent&); //統(tǒng)計(jì)函數(shù) staticvoidstatisticalData(academicGraduateStudent*);protected: staticfloatsumAcademicScore;//學(xué)術(shù)碩士全體總成績(jī) staticintcountAcademicNumber;//學(xué)術(shù)碩士總?cè)藬?shù) staticfloataverageAcademicScore;//學(xué)術(shù)碩士平均成績(jī) staticinta[6];//學(xué)術(shù)碩士總分分段人數(shù) stringmajor;//專業(yè) structpaper//發(fā)表論文 { stringpaper1; floatpaper1Score; intpaperLevel1; stringpaper2; floatpaper2Score; intpaperLevel2; stringpaper3; floatpaper3Score; intpaperLevel3; }apaper;//apaper代表的是academicGraduateStudent的paper intpaperNumber;//發(fā)表的論文數(shù) floatpaperScore;//論文成績(jī) floatsumScore;//總成績(jī)};//工程碩士classengineeringGraduateStudent:publicgraduateStudent{public: engineeringGraduateStudent*peNext;//定義一個(gè)指針,鏈表操作 engineeringGraduateStudent(){};//構(gòu)造函數(shù) ~engineeringGraduateStudent(){};//析構(gòu)函數(shù) intgetNum()const{returnnum;}//獲取學(xué)號(hào) stringgetName()const{returnname;}//獲取姓名 floatcalculateSumScore();//計(jì)算總分?jǐn)?shù)//重載函數(shù) friendostream&operator<<(ostream&,engineeringGraduateStudent&); friendistream&operator>>(istream&,engineeringGraduateStudent&); //統(tǒng)計(jì)函數(shù) staticvoidstatisticalData(engineeringGraduateStudent*);protected: staticfloatsumEngineeringScore;//工程碩士全體總成績(jī) staticintcountEngineeringNumber;//工程碩士總?cè)藬?shù) staticfloataverageEngineeringScore;//工程碩士平均成績(jī) staticinte[6];//學(xué)術(shù)碩士總分分段人數(shù) stringfield;//領(lǐng)域 structproject//參加項(xiàng)目 { stringpName;//項(xiàng)目名稱 charpLevel;//項(xiàng)目等級(jí)A,B,C }eproject; floatprojectScore;//項(xiàng)目成績(jī) floatsumScore;//總成績(jī)};步驟2:?jiǎn)捂湵硐嚓P(guān)函數(shù)這一塊代碼的書寫我的思路:因?yàn)橛袃深惻缮芯可?,而文件操作需要的是告訴計(jì)算機(jī)字節(jié)數(shù)的讀取,所以,建立兩個(gè)單鏈表,分別對(duì)學(xué)術(shù),工程類的研究生進(jìn)行操作,鏈表的優(yōu)勢(shì)確實(shí)比數(shù)組好,可以說,鏈表就是一個(gè)動(dòng)態(tài)的數(shù)組,鏈表的書寫過程中是我又復(fù)習(xí)了一遍上學(xué)期學(xué)的知識(shí),更加加深了頭結(jié)點(diǎn)的關(guān)鍵作用(頭結(jié)點(diǎn)中數(shù)據(jù)域是沒有用的,只有指針域有用),我將兩個(gè)頭結(jié)點(diǎn)均聲明為全局變量,方便函數(shù)的調(diào)用使用,下面展示學(xué)術(shù)類的源代碼,工程類的同理。源代碼(部分)://學(xué)術(shù)類研究生普通函數(shù)的定義academicGraduateStudent*seekAcademicData(academicGraduateStudent*head)//查找某個(gè)學(xué)術(shù)研究生數(shù)據(jù){ if(head->paNext==NULL)//判斷緩存中是否有數(shù)據(jù) { cerr<<"錯(cuò)誤代碼:0x123458!"<<endl; cerr<<"異常錯(cuò)誤?。ㄕ?qǐng)上報(bào)管理員處理)"<<endl; system("pause"); exit(0); }loop: cout<<"學(xué)號(hào)(1),姓名(2)?"<<endl; inti=0; cin>>i; if(!(i==1||i==2)) { cerr<<"輸入有誤,請(qǐng)重新輸入!"<<endl; gotoloop; } academicGraduateStudent*p=head->paNext; inttargetNum; stringtargetName; switch(i) { case1: loopnu: cout<<"請(qǐng)輸入學(xué)號(hào):"<<endl; cin>>targetNum; while(p->getNum()!=targetNum) { p=p->paNext; } if(p==NULL) { cerr<<"沒有這個(gè)數(shù)據(jù)!請(qǐng)重新輸入!"<<endl; gotoloopnu; } returnp; break; case2: loopna: cout<<"請(qǐng)輸入姓名:"<<endl; cin>>targetName; while(p->getName()!=targetName) { p=p->paNext; } if(p==NULL) { cerr<<"沒有這個(gè)數(shù)據(jù)!請(qǐng)重新輸入!"<<endl; gotoloopna; } returnp; break; default: cerr<<"錯(cuò)誤代碼:0x123459!"<<endl; cerr<<"異常錯(cuò)誤!(請(qǐng)上報(bào)管理員處理)"<<endl; system("pause"); exit(0); }}academicGraduateStudent*inputAcademicData(academicGraduateStudent*head)//錄入學(xué)術(shù)研究生數(shù)據(jù){ academicGraduateStudent*p,*q; p=q=newacademicGraduateStudent; if(p==NULL||q==NULL)//申請(qǐng)內(nèi)存失敗操作 { cerr<<"錯(cuò)誤代碼:0x123456!"<<endl; cerr<<"異常錯(cuò)誤?。ㄕ?qǐng)上報(bào)管理員處理)"<<endl; system("pause"); exit(0); } cout<<"開始錄入數(shù)據(jù)(學(xué)號(hào)為零時(shí)結(jié)束)"<<endl; cin>>*p; cout<<"錄入成功!"<<endl; inti=1; while(p->getNum()!=0) { if(i==1) { head->paNext=p; } else { q->paNext=p; } q=p; p=newacademicGraduateStudent; if(p==NULL)//申請(qǐng)內(nèi)存失敗操作 { cerr<<"錯(cuò)誤代碼:0x123457!"<<endl; cerr<<"異常錯(cuò)誤?。ㄕ?qǐng)上報(bào)管理員處理)"<<endl; system("pause"); exit(0); } cin>>*p; p->getNum(); if(p->getNum()!=0) { cout<<"錄入成功!"<<endl; } else { cout<<"錄入結(jié)束!"<<endl; } i++; } q->paNext=NULL; returnhead;}academicGraduateStudent*insertAcademicData(academicGraduateStudent*head)//插入某個(gè)學(xué)術(shù)研究生數(shù)據(jù){ if(head->paNext==NULL)//判斷緩存中是否有數(shù)據(jù) { cerr<<"錯(cuò)誤代碼:0x123458!"<<endl; cerr<<"異常錯(cuò)誤?。ㄕ?qǐng)上報(bào)管理員處理)"<<endl; system("pause"); exit(0); } academicGraduateStudent*p,*q; cout<<"請(qǐng)輸入一個(gè)新的數(shù)據(jù)(學(xué)術(shù)研究生)"<<endl; p=newacademicGraduateStudent; if(p==NULL) { cerr<<"錯(cuò)誤代碼:0x123458!"<<endl; cerr<<"異常錯(cuò)誤?。ㄕ?qǐng)上報(bào)管理員處理)"<<endl; system("pause"); exit(0); } cin>>*p; cout<<"錄入成功!"<<endl; cout<<"請(qǐng)輸入插入在哪個(gè)數(shù)據(jù)之后?"<<endl; //找到要插入的人 q=seekAcademicData(aHead); p->paNext=q->paNext; q->paNext=p; returnhead;}academicGraduateStudent*delAcademicData(academicGraduateStudent*head)//刪除某個(gè)學(xué)術(shù)研究生數(shù)據(jù){ if(head->paNext==NULL)//判斷緩存中是否有數(shù)據(jù) { cerr<<"錯(cuò)誤代碼:0x123458!"<<endl; cerr<<"異常錯(cuò)誤!(請(qǐng)上報(bào)管理員處理)"<<endl; system("pause"); exit(0); } academicGraduateStudent*p,*q;loop: cout<<"學(xué)號(hào)(1),姓名(2)?"<<endl; inti=0; cin>>i; if(!(i==1||i==2)) { cerr<<"輸入有誤,請(qǐng)重新輸入!"<<endl; gotoloop; } p=head->paNext; q=head; inttargetNum; stringtargetName; switch(i) { case1: loopnu: cout<<"請(qǐng)輸入學(xué)號(hào):"<<endl; cin>>targetNum; while(p->getNum()!=targetNum) { q=p; p=p->paNext; } if(p==NULL) { cerr<<"沒有這個(gè)數(shù)據(jù)!請(qǐng)重新輸入!"<<endl; gotoloopnu; } break; case2: loopna: cout<<"請(qǐng)輸入姓名:"<<endl; cin>>targetName; while(p->getName()!=targetName) { q=p; p=p->paNext; } if(p==NULL) { cerr<<"沒有這個(gè)數(shù)據(jù)!請(qǐng)重新輸入!"<<endl; gotoloopna; } break; default: cerr<<"錯(cuò)誤代碼:0x123459!"<<endl; cerr<<"異常錯(cuò)誤?。ㄕ?qǐng)上報(bào)管理員處理)"<<endl; system("pause"); exit(0); } i=0;loopq: cout<<"是否確定刪除?是(1),否(2)"<<endl; cin>>i; if(i==1) { q->paNext=p->paNext; } elseif(i==2) { cerr<<"取消成功!"<<endl; } else { cout<<"輸入有誤,請(qǐng)重新輸入!"<<endl; gotoloopq; } returnhead;}voidprintAcademicData(academicGraduateStudent*head)//輸出學(xué)術(shù)研究生數(shù)據(jù){ academicGraduateStudent*p=head->paNext; if(head->paNext==NULL) { cerr<<"錯(cuò)誤代碼:0x156456(鏈表中無數(shù)據(jù))"<<endl; cerr<<"請(qǐng)聯(lián)系管理員處理!"<<endl; system("pause"); exit(0); } while(p!=NULL) { cout<<*p<<endl; p=p->paNext; } return;}voidmodifyAcademicData()//修改學(xué)術(shù)研究生的數(shù)據(jù){ academicGraduateStudent*p,*q; p=seekAcademicData(aHead); q=newacademicGraduateStudent; q->paNext=p->paNext; if(q==NULL) { cerr<<"錯(cuò)誤代碼0x156112"<<endl; cerr<<"請(qǐng)聯(lián)系管理員解決!"<<endl; system("pause"); exit(0); } cin>>*q; inti=0;loop: cout<<"是否確定修改是(1),否(2)?"<<endl; cin>>i; if(i==1) { *p=*q; cout<<"修改成功"<<endl; } elseif(i==2) { cout<<"取消成功!"<<endl; deleteq; } else { cerr<<"輸入有誤,請(qǐng)重新輸入!"<<endl; gotoloop; } return;}步驟3:文件操作函數(shù)的聲明與定義文件操作是一個(gè)程序很關(guān)鍵的部分,數(shù)據(jù)是不可能長(zhǎng)期的保存在緩存中的,所以需要對(duì)緩存中的數(shù)據(jù)存盤操作,需要注意的細(xì)節(jié)比較多(二進(jìn)制文件,文本文件操作的不同,打開文件,關(guān)閉文件等等),但是只是一些細(xì)節(jié)需要注意,思維上的難度并不是很大,嚴(yán)格按照文件操作的步驟即可,從內(nèi)存中將文件讀到磁盤問題相對(duì)簡(jiǎn)單,而將磁盤中的數(shù)據(jù)讀到內(nèi)存,不光要讀,讀完還需操作,所以,建立一個(gè)單鏈表,這個(gè)鏈表不是用戶輸入數(shù)據(jù),而是讀取文件輸入數(shù)據(jù)(思想是一樣的),之后內(nèi)存中有了數(shù)據(jù),就可以進(jìn)行相關(guān)的操作了,之后保存即可。源代碼(部分)://保存數(shù)據(jù)到磁盤voidsaveAcademicStudentData(academicGraduateStudent*head)//保存學(xué)術(shù)研究生數(shù)據(jù)到磁盤{ //建立一個(gè)txt文本文件 academicGraduateStudent*p=head->paNext; ofstreamoutfile("AcademicStudentData.txt",ios::out); if(!outfile) { cerr<<"文件打開失敗!"<<endl; cerr<<"錯(cuò)誤代碼0x125158"<<endl; cerr<<"請(qǐng)聯(lián)系管理員處理"<<endl; system("pause"); exit(0); } while(p!=NULL) { outfile<<*p; p=p->paNext; } outfile.close(); //建立一個(gè)dat二進(jìn)制文件,方便以后讀取 p=head->paNext;//重新賦值 ofstreamoutfiled("AcademicStudentData.dat",ios::out|ios::binary); if(!outfiled) { cerr<<"文件打開失敗!"<<endl; cerr<<"錯(cuò)誤代碼0x125158"<<endl; cerr<<"請(qǐng)聯(lián)系管理員處理"<<endl; system("pause"); exit(0); } while(p!=NULL) { outfiled.write((char*)p,sizeof(*p)); p=p->paNext; } outfiled.close(); return;}//讀取磁盤數(shù)據(jù)到內(nèi)存academicGraduateStudent*getAcademicStudentData(academicGraduateStudent*head)//獲取磁盤中學(xué)術(shù)研究生數(shù)據(jù)到緩存{ loop: ifstreaminfile("AcademicStudentData.dat",ios::in|ios::binary); if(!infile) { cerr<<"歡迎您第一次使用該系統(tǒng),您首先要做的錄入數(shù)據(jù)!"<<endl; cerr<<"警告:如果您不是第一次使用該系統(tǒng),錯(cuò)誤代碼0x125158(請(qǐng)聯(lián)系管理員處理)"<<endl; firstInputData(); saveStudentData(); exit(0); gotoloop; } infile.seekg(0,ios::beg);//重置指針的位置 academicGraduateStudent*p,*q; p=q=newacademicGraduateStudent; if(p==NULL||q==NULL)//申請(qǐng)內(nèi)存失敗操作 { cerr<<"錯(cuò)誤代碼:0x123456!"<<endl; cerr<<"異常錯(cuò)誤?。ㄕ?qǐng)上報(bào)管理員處理)"<<endl; system("pause"); exit(0); } infile.read((char*)p,sizeof(*p)); inti=1; while(!infile.eof()) { if(i==1) { head->paNext=p; } else { q->paNext=p; } q=p; p=newacademicGraduateStudent; if(p==NULL)//申請(qǐng)內(nèi)存失敗操作 { cerr<<"錯(cuò)誤代碼:0x123457!"<<endl; cerr<<"異常錯(cuò)誤?。ㄕ?qǐng)上報(bào)管理員處理)"<<endl; system("pause"); exit(0); } infile.read((char*)p,sizeof(*p)); i++; } q->paNext=NULL; infile.close(); returnhead;}//追加函數(shù)voidaddAcademicStudentData(academicGraduateStudent*head)//追加學(xué)術(shù)研究生數(shù)據(jù){ //建立一個(gè)txt.dat文件 academicGraduateStudent*p=head->paNext; academicGraduateStudent*q=NULL; if(p==NULL) { cerr<<"錯(cuò)誤代碼0x1566(鏈表緩存中無數(shù)據(jù))"<<endl; cerr<<"請(qǐng)聯(lián)系管理員處理!"<<endl; system("pause"); exit(0); } ofstreamoutfile("AcademicStudentData.txt",ios::app); if(!outfile) { cerr<<"文件打開失敗!"<<endl; cerr<<"錯(cuò)誤代碼0x125158"<<endl; cerr<<"請(qǐng)聯(lián)系管理員處理"<<endl; system("pause"); exit(0); } ofstreamoutfiled("AcademicStudentData.dat",ios::app); if(!outfiled) { cerr<<"文件打開失敗!"<<endl; cerr<<"錯(cuò)誤代碼0x125158"<<endl; cerr<<"請(qǐng)聯(lián)系管理員處理"<<endl; system("pause"); exit(0); } //開始尋找鏈表末尾 while(p!=NULL) { q=p; p=p->paNext; } //尋找完畢 cout<<"開始添加!"<<endl; q=inputAcademicData(q); while(q!=NULL) { outfile<<*q; outfiled.write((char*)q,sizeof(*q)); q=q->paNext; } cout<<"添加成功"<<endl; outfile.close(); outfiled.close(); return;}步驟4:統(tǒng)計(jì)函數(shù)的聲明與定義這部分運(yùn)用靜態(tài)數(shù)據(jù)變量和靜態(tài)函數(shù)的相關(guān)知識(shí),因?yàn)楸热缯f總?cè)藬?shù)等數(shù)據(jù)不需要再每一個(gè)對(duì)象中均聲明定義,這部分完成的較快,將頭結(jié)點(diǎn)當(dāng)做實(shí)參傳給函數(shù)形參,對(duì)每一個(gè)節(jié)點(diǎn)的數(shù)據(jù)進(jìn)行判斷,最后進(jìn)行輸出統(tǒng)計(jì)出的結(jié)果,cout語句,注意美觀,整潔,細(xì)節(jié)。源代碼(部分)://學(xué)術(shù)類靜態(tài)變量賦初值floatacademicGraduateStudent::sumAcademicScore=0.0;intacademicGraduateStudent::countAcademicNumber=0;floatacademicGraduateStudent::averageAcademicScore=0.0;intacademicGraduateStudent::a[6]={0,0,0,0,0,0};//統(tǒng)計(jì)函數(shù)voidacademicGraduateStudent::statisticalData(academicGraduateStudent*head){ if(head->paNext==NULL) { cerr<<"錯(cuò)誤0x456121"<<endl; cerr<<"請(qǐng)聯(lián)系管理員解決(鏈表中無數(shù)據(jù))"<<endl; system("pause"); exit(0); } academicGraduateStudent*p=head->paNext; while(p!=NULL) { countAcademicNumber++; sumAcademicScore=(float)(sumAcademicScore+p->sumScore); if(fabs(p->sumScore-100)<0.00001)//注意說明 { a[0]++; } elseif(p->sumScore>=90.0000&&p->sumScore<=99.0000) { a[1]++; } elseif(p->sumScore>=80.0000&&p->sumScore<=89.0000) { a[2]++; } elseif(p->sumScore>=70.0000&&p->sumScore<=79.0000) { a[3]++; } elseif(p->sumScore>=60.0000&&p->sumScore<=69.0000) { a[4]++; } elseif(p->sumScore<60.0000) { a[5]++; } p=p->paNext; } averageAcademicScore=(float)((sumAcademicScore)*1.0/countAcademicNumber); //統(tǒng)計(jì)完畢,開始輸出相關(guān)信息 cout<<"學(xué)術(shù)碩士總?cè)藬?shù)為:"<<countAcademicNumber<<endl; cout<<"其中他們的平均分為:"<<averageAcademicScore<<endl; cout<<"成績(jī)分布為:"<<endl; cout<<"100人數(shù)為:"<<a[0]<<"占總?cè)藬?shù)百分比為:"<<100*(float)(a[0]*1.0/countAcademicNumber)<<"%"<<endl; cout<<"90~99人數(shù)為:"<<a[1]<<"占總?cè)藬?shù)百分比為:"<<100*(float)(a[1]*1.0/countAcademicNumber)<<"%"<<endl; cout<<"80~89人數(shù)為:"<<a[2]<<"占總?cè)藬?shù)百分比為:"<<100*(float)(a[2]*1.0/countAcademicNumber)<<"%"<<endl; cout<<"70~79人數(shù)為:"<<a[3]<<"占總?cè)藬?shù)百分比為:"<<100*(float)(a[3]*1.0/countAcademicNumber)<<"%"<<endl; cout<<"60~69人數(shù)為:"<<a[4]<<"占總?cè)藬?shù)百分比為:"<<100*(float)(a[4]*1.0/countAcademicNumber)<<"%"<<endl; cout<<"不及格人數(shù)為:"<<a[5]<<"占總?cè)藬?shù)百分比為:"<<100*(float)(a[5]*1.0/countAcademicNumber)<<"%"<<endl; return;}步驟5:菜單函數(shù)的書寫這部分要求的是cout語句輸出一些語句和‘*’,緊接著用switch進(jìn)行選擇判斷,雖說操作簡(jiǎn)單,但要畫出美觀的界面還不是很簡(jiǎn)單的源代碼:voidmenu()//菜單界面{ inti=0;loop: cout<<"***************************************************"<<endl; cout<<"*"<<"****研究生管理系統(tǒng)****"<<"*"<<endl; cout<<"*"<<"1.研究生信息錄入*"<<"*"<<endl; cout<<"*"<<"2.研究生信息插入"<<"*"<<endl; cout<<"*"<<"3.研究生信息刪除"<<"*"<<endl; cout<<"*"<<"4.研究生信息輸出"<<"*"<<endl; cout<<"*"<<"5.研究生信息修改"<<"*"<<endl; cout<<"*"<<"6.研究生信息查找"<<"*"<<endl; cout<<"*"<<"7.研究生信息統(tǒng)計(jì)"<<"*"<<endl; cout<<"*"<<"8.退出系統(tǒng)"<<"*"<<endl; cout<<"*"<<"9.初始化該系統(tǒng)"<<"*"<<endl; cout<<"****************************************************"<<endl; cout<<"請(qǐng)選擇:"<<endl; cin>>i; switch(i) { case1: addStudentData();//信息錄入 cout<<"錄入成功!"<<endl; system("pause"); system("cls"); break; case2: insertData();//信息插入 cout<<"插入成功!"<<endl; system("pause"); system("cls"); break; case3: delData();//信息刪除 cout<<"刪除成功!"<<endl; system("pause"); system("cls"); break; case4: printData();//信息輸出 cout<<"輸出成功!"<<endl; system("pause"); system("cls"); break; case5: modifyData();//信息修改
溫馨提示
- 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. 人人文庫網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度環(huán)保項(xiàng)目項(xiàng)目負(fù)責(zé)人聘用專項(xiàng)合同
- 2025年度礦山資源整合居間合同范本
- 家庭保潔居間協(xié)議范本
- 做眼袋手術(shù)合同范本
- 供暖公司供暖合同范例
- 個(gè)體店鋪轉(zhuǎn)租合同范例
- ppp顧問服務(wù)合同范例
- 農(nóng)機(jī)設(shè)備施工合同范例
- 會(huì)計(jì)兼職合同范例
- 低價(jià)轉(zhuǎn)讓船只合同范例
- 臨時(shí)工雇傭合同范本2025年度
- (二調(diào))武漢市2025屆高中畢業(yè)生二月調(diào)研考試 地理試卷
- “艾梅乙”感染者消除醫(yī)療歧視制度-
- 2024-2025學(xué)年八年級(jí)地理下冊(cè)第七章《南方地區(qū)》檢測(cè)卷(人教版)
- 森林防火知識(shí)
- 2025年黑龍江林業(yè)職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)適應(yīng)性測(cè)試題庫帶答案
- 2025-2030年中國測(cè)序儀市場(chǎng)運(yùn)行態(tài)勢(shì)及發(fā)展規(guī)劃分析報(bào)告
- 第二單元第1課《精彩瞬間》第2課時(shí) 課件-七年級(jí)美術(shù)下冊(cè)(人教版2024)
- 《物理前沿科學(xué)》課件
- 2025年公共營養(yǎng)師三級(jí)理論試題及答案
- 餐廳市場(chǎng)調(diào)研與定位
評(píng)論
0/150
提交評(píng)論