C++課程設(shè)計(jì)報(bào)告——學(xué)生信息管理系統(tǒng)_第1頁(yè)
C++課程設(shè)計(jì)報(bào)告——學(xué)生信息管理系統(tǒng)_第2頁(yè)
C++課程設(shè)計(jì)報(bào)告——學(xué)生信息管理系統(tǒng)_第3頁(yè)
C++課程設(shè)計(jì)報(bào)告——學(xué)生信息管理系統(tǒng)_第4頁(yè)
C++課程設(shè)計(jì)報(bào)告——學(xué)生信息管理系統(tǒng)_第5頁(yè)
已閱讀5頁(yè),還剩14頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、C+課程設(shè)計(jì)報(bào)告學(xué) 院 計(jì)算機(jī)科學(xué)與信息工程學(xué)院 專 業(yè) 計(jì)算機(jī)科學(xué)與技術(shù)年 級(jí) 指 導(dǎo) 老 師 學(xué) 生 姓 名 完 成 時(shí) 間 2021 年08月23 日 編寫(xiě)一個(gè)小型的學(xué)生信息管理系統(tǒng),可以對(duì)中學(xué)生、大學(xué)生和研究生的信息進(jìn)行簡(jiǎn)單的管理。每一類的學(xué)生包括學(xué)生名、成績(jī)1、成績(jī)2、成績(jī)3和平均成績(jī)。,其中平均成績(jī)=成績(jī)1+成績(jī)2+成績(jī)3/3。每類學(xué)生還有區(qū)別于其他類學(xué)生的特殊信息,例如中學(xué)生有家長(zhǎng)。大學(xué)生有專業(yè),研究生有導(dǎo)師。要求通過(guò)本系統(tǒng)實(shí)現(xiàn)以下功能: 1輸入學(xué)生的根本信息; 2根據(jù)學(xué)生名查詢學(xué)生的成績(jī); 3計(jì)算并顯示某個(gè)學(xué)生的平均成績(jī)。 對(duì)于本系統(tǒng)中的的3種不同種類的對(duì)象:中學(xué)生、大學(xué)生和研

2、究生,抽取其共同特性形成一個(gè)基類:根本信息類Record。然后再這個(gè)基類的根底上分別派生出3個(gè)類:中學(xué)生類Student、大學(xué)生類U_student和研究生類Graduate。各類信息存放到文件中。 根本信息類Record中的數(shù)據(jù)成員是num學(xué)生類別編號(hào)、name(學(xué)生名)、score1(成績(jī)1)、score2(成績(jī)2)、score3(成績(jī)3)、average(平均成績(jī))。3個(gè)學(xué)生類除了繼承Record的數(shù)據(jù)外,類Student(中學(xué)生類)還增加了數(shù)據(jù)成員patriarch(家長(zhǎng)),類U_student(大學(xué)生類)增加了數(shù)據(jù)成員specialty(專業(yè)),類Graduate(研究生類)數(shù)據(jù)成員

3、增加了mentor(導(dǎo)師)。 在基類中定義了構(gòu)造函數(shù)和對(duì)所有類型學(xué)生的相同操作,成員函數(shù)Get_num負(fù)責(zé)取出學(xué)生類別編號(hào),成員函數(shù)Get_score1負(fù)責(zé)取出成績(jī)1,成員函數(shù)Get_score2負(fù)責(zé)取出成績(jī)2,成員函數(shù)Get_score3負(fù)責(zé)取出成績(jī)3,成員函數(shù)Computer_average負(fù)責(zé)取出平均成績(jī),成員函數(shù)Input負(fù)責(zé)數(shù)據(jù)輸入,成員函數(shù)Output負(fù)責(zé)數(shù)據(jù)輸出。 系統(tǒng)管理類(System)的主要操作是:成員函數(shù)In_information負(fù)責(zé)輸入學(xué)生信息,成員函數(shù)Search負(fù)責(zé)查詢學(xué)生信息,成員函數(shù)Out_average負(fù)責(zé)計(jì)算并顯示平均成績(jī),成員函數(shù)Interface負(fù)責(zé)界

4、面輸出。class Record /根本信息類protected:int num;char name20;float score1;float score2;float score3;float average;public:Record(char* R_name=" ",float sco1=0,float sco2=0,float sco3=0);Record()int Get_num();float Get_score1();float Get_score2();float Get_score3();float Get_average();char *Getname(

5、);void Compute_average();void Input();void Output();class Student:public Record /中學(xué)生類char patriarch20;public:Student(char* R_name=" ",float sco1=0,float sco2=0,float sco3=0,char *tea=" ");Student()void Input();void Output();class U_student:public Record /大學(xué)生類char specialty20;publ

6、ic:U_student(char* R_name=" ",float sco1=0,float sco2=0,float sco3=0,char *spe=" ");U_student()void Input();void Output();class Graduate:public Record /研究生類char mentor20;public:Graduate(char* R_name=" ",float sco1=0,float sco2=0,float sco3=0,char *men=" ");Gra

7、duate()void Input();void Output();class System /系統(tǒng)管理類Record A;Student B10;U_student C10;Graduate D10;static int j1,j2,j3;void infor1();void infor2();void infor3();void save();void Search1(int h,char ch20);void Out_average1(int h,char* name);void Interface1();public:System();void In_information();voi

8、d Search();void Out_average();void Interface();1將數(shù)據(jù)文件中信息讀入內(nèi)存對(duì)象數(shù)組當(dāng)系統(tǒng)啟動(dòng)成功后,系統(tǒng)管理類System的構(gòu)造函數(shù)自動(dòng)調(diào)用函數(shù)save,將學(xué)生信息從數(shù)據(jù)文件中讀入內(nèi)存各對(duì)象數(shù)組中。每次從數(shù)據(jù)文件中讀取積累大小的一條信息存入基類對(duì)象中,并獲得這條信息的種類編號(hào),通過(guò)學(xué)生類別編號(hào)可以判定學(xué)生的類別,然后將指針指回到這條信息的開(kāi)頭,存入對(duì)應(yīng)的對(duì)象數(shù)組中。就拿中學(xué)生類來(lái)舉例子:根本信息類Record的對(duì)象是A,中學(xué)生類Student的對(duì)象是B【j1】,將數(shù)據(jù)文件里有關(guān)數(shù)據(jù)讀出并存放到對(duì)象B【j1】中,有關(guān)程序段如下:fstream dat

9、afile(fileName,ios:in|ios:out|ios:binary); datafile.read(char*)&A,sizeof(Record); while(!datafile.eof() a=A.Get_num(); switch(a) case 1: datafile.seekp(-1* sizeof(class Record),ios:cur); datafile.read(char*)&Bj1,sizeof(Student); j1+; break; 2信息的輸入 信息的輸入功能由成員函數(shù)In_information來(lái)完成,它根據(jù)要輸入的學(xué)生類別分別調(diào)

10、用對(duì)應(yīng)的學(xué)生信息輸入功能函數(shù)來(lái)完本錢(qián)類學(xué)生的輸入。有3個(gè)類別的學(xué)生信息輸入函數(shù):Void infor1();/輸入中學(xué)生類對(duì)象數(shù)據(jù)Void infor2();/輸入大學(xué)生類對(duì)象數(shù)據(jù)Void infor3();/輸入研究生類對(duì)象數(shù)據(jù)下面以infor1為例說(shuō)明一條學(xué)生信息輸入的實(shí)現(xiàn)過(guò)程:void System:infor1() Student A; fstream datafile(fileName,ios:in|ios:out|ios:binary); datafile.seekp(0,ios:end); A.Input(); datafile.write(char*)&A,sizeof

11、(class Student); Bj1=A; datafile.close(); (3)信息的查詢信息查詢功能有成員函數(shù)Search來(lái)完成。如查詢中學(xué)生信息的程序段如下:if(strcmp(ch,Bs.Getname()=0) Bs.Output(); cout<<"ttt*"<<endl; found=1; 4平均成績(jī)計(jì)算和顯示 平均成績(jī)的計(jì)算和顯示也是按照學(xué)生名來(lái)進(jìn)行。先接收從鍵盤(pán)輸入的學(xué)生類別編號(hào)和學(xué)生名,找到后通過(guò)調(diào)用對(duì)象的平均成績(jī)計(jì)算函數(shù)來(lái)計(jì)算平均成績(jī)并顯示,以中學(xué)生的程序段為例: if(strcmp(name,Bs.Getname()=

12、0) Bs.Compute_average(); average=Bs.Get_average(); found=1; 5界面設(shè)計(jì)和實(shí)現(xiàn)程序運(yùn)行主要由System類中的Interface來(lái)完成。程序段如下:void System:Interface() int rev; cout<<"tt *歡迎使用" cout<<"*"<<endl; cout<<"tt *小型學(xué)生信息管理系統(tǒng)" cout<<"*"<<endl; cout<<&q

13、uot;tt 1.輸入學(xué)生信息 "<<endl; cout<<"tt 2.查詢學(xué)生信息 "<<endl; cout<<"tt 3.計(jì)算平均成績(jī) "<<endl; cout<<"tt 4.退出 "<<endl; cout<<"tt 請(qǐng)您選擇(1-4): " cin>>rev; switch(rev) case 1: In_information(); break; case 2: Search();

14、break; case 3: Out_average(); break; case 4: exit(0); 完整程序如下:class Recordprotected:int num;char name20;float score1;float score2;float score3;float average;public:Record(char* R_name=" ",float sco1=0,float sco2=0,float sco3=0);Record()int Get_num();float Get_score1();float Get_score2();flo

15、at Get_score3();float Get_average();char *Getname();void Compute_average();void Input();void Output();class Student:public Recordchar patriarch20;public:Student(char* R_name=" ",float sco1=0,float sco2=0,float sco3=0,char *tea=" ");Student()void Input();void Output();class U_stud

16、ent:public Recordchar specialty20;public:U_student(char* R_name=" ",float sco1=0,float sco2=0,float sco3=0,char *spe=" ");U_student()void Input();void Output();class Graduate:public Recordchar mentor20;public:Graduate(char* R_name=" ",float sco1=0,float sco2=0,float sco

17、3=0,char *men=" ");Graduate()void Input();void Output();class SystemRecord A;Student B10;U_student C10;Graduate D10;static int j1,j2,j3;void infor1();void infor2();void infor3();void save();void Search1(int h,char ch20);void Out_average1(int h,char* name);void Interface1();public:System();

18、void In_information();void Search();void Out_average();void Interface();#include <iostream>#include <string>#include <fstream>#include "Record.h"using namespace std;#define N 30char fileName="super.dat"Record:Record(char* R_name,float sco1,float sco2,float sco3)

19、 strcpy(name,R_name); score1=sco1; score2=sco2; score3=sco3; int Record:Get_num() return num; float Record:Get_score1() return score1; float Record:Get_score2() return score2; float Record:Get_score3() return score3; float Record:Get_average() return average; char*Record:Getname() return name; void

20、Record:Compute_average() average=(score1+score2+score3)/3; void Record:Input() cout<<"tt 學(xué)生名:" cin>>name; cout<<"tt 成績(jī)1:" cin>>score1;cout<<"tt 成績(jī)2:" cin>>score2;cout<<"tt 成績(jī)3:" cin>>score3; void Record:Output()

21、cout<<endl; cout<<"tt 所要查看的學(xué)生信息:"<<endl;cout<<"tt 學(xué)生類別號(hào):"<<num<<endl;cout<<"tt 學(xué)生名: "<<name<<endl;cout<<"tt 成績(jī)1 : "<<score1<<endl;cout<<"tt 成績(jī)2 : "<<score2<<end

22、l;cout<<"tt 成績(jī)3 : "<<score3<<endl; Student:Student(char* R_name,float sco1,float sco2,float sco3,char*tea):Record(R_name,sco1,sco2,sco3) num=1; strcpy(patriarch,tea); void Student:Input() Record:Input(); cout<<"tt 家長(zhǎng):"cin>>patriarch; void Student:Out

23、put() Record:Output(); cout<<"tt 家長(zhǎng):"<<patriarch<<endl; U_student:U_student(char* R_name,float sco1,float sco2,float sco3,char* spe):Record(R_name,sco1,sco2,sco3) num=2; strcpy(specialty,spe); void U_student:Input() Record:Input(); cout<<"tt 專業(yè):"cin>>

24、;specialty; void U_student:Output() Record:Output(); cout<<"tt 專業(yè):"<<specialty<<endl; Graduate:Graduate(char* R_name,float sco1,float sco2,float sco3,char* men):Record(R_name,sco1,sco2,sco3) num=4; strcpy(mentor,men); void Graduate:Input() Record:Input(); cout<<&quo

25、t;tt 導(dǎo)師:"cin>>mentor; void Graduate:Output() Record:Output(); cout<<"tt 導(dǎo)師:"<<mentor<<endl; int System:j1=0; int System:j2=0; int System:j3=0; System:System() save(); void System:Interface1() cout<<"nnn" cout<<"tt *按學(xué)生類別進(jìn)行管理*"<

26、;<endl;cout<<"tt *學(xué)生類別選擇*"<<endl;類 "<<endl;cout<<"tt 2.大學(xué)生類 "<<endl;cout<<"tt 3.研究生類 "<<endl;cout<<"tt 4.退出 "<<endl;cout<<"tt 請(qǐng)您選擇學(xué)生類別: " void System:In_information() int rev1; int a

27、gain=1;char t;while(again)Interface1(); cin>>rev1; switch(rev1) case 1: infor1(); break; case 2: infor2(); break; case 3: infor3(); break; case 4: Interface(); break; default: cout<<"ttt 沒(méi)有此類學(xué)生!"<<endl; continue; cout<<"ttt 信息存儲(chǔ)成功! "<<endl; cout<&

28、lt;"ttt 是否繼續(xù)輸入(y/n)?" cin>>t; cout<<endl; if(!(t='Y'|t='y') again=0;Interface(); void System:infor1() Student A; fstream datafile(fileName,ios:in|ios:out|ios:binary); datafile.seekp(0,ios:end); A.Input(); datafile.write(char*)&A,sizeof(class Student); Bj1=A;

29、 datafile.close(); void System:infor2() U_student A; fstream datafile(fileName,ios:in|ios:out|ios:binary); datafile.seekp(0,ios:end); A.Input(); datafile.write(char*)&A,sizeof(class U_student); Cj2=A; datafile.close(); void System:infor3() Graduate A; fstream datafile(fileName,ios:in|ios:out|ios

30、:binary); datafile.seekp(0,ios:end); A.Input(); datafile.write(char*)&A,sizeof(class Graduate); Dj3=A; datafile.close(); void System:save() int a; fstream datafile(fileName,ios:in|ios:out|ios:binary); datafile.read(char*)&A,sizeof(Record); while(!datafile.eof() a=A.Get_num(); switch(a) case

31、1: datafile.seekp(-1* sizeof(class Record),ios:cur); datafile.read(char*)&Bj1,sizeof(Student); j1+; break; case 2: datafile.seekp(-1* sizeof(class Record),ios:cur); datafile.read(char*)&Cj2,sizeof(U_student); j2+; break; case 3: datafile.seekp(-1* sizeof(class Record),ios:cur); datafile.read

32、(char*)&Dj3,sizeof(Graduate); j3+; break; default: break; datafile.read(char*)&A,sizeof(Record); datafile.close(); void System:Search1(int h,char ch20) int s=0,found=0; switch(h) case 1: while(s<N) if(strcmp(ch,Bs.Getname()=0) Bs.Output(); cout<<"ttt*"<<endl; found=1

33、; s+; break; case 2: while(s<N) if(strcmp(ch,Cs.Getname()=0) Cs.Output(); cout<<"ttt*"<<endl; found=1; s+; break; case 3: while(s<N) if(strcmp(ch,Ds.Getname()=0) Ds.Output(); cout<<"ttt*"<<endl; found=1; s+; break; if(found=0) cout<<"nntt

34、對(duì)不起,該類別中沒(méi)有您所要查詢的學(xué)生!"<<endl; void System:Search() int rev; char name20;int again=1;char t;while(again)Interface1();cin>>rev;cout<<"tt 請(qǐng)輸入要查詢的學(xué)生名:"cin>>name;Search1(rev,name);cout<<"ttt 是否繼續(xù)查詢(y/n)?"cin>>t;cout<<endl;if(!(t='Y'

35、|t='y')again=0;Interface(); void System:Out_average1(int h,char* name) int s=0,found=0; float average;switch(h)case 1:while(s<N) if(strcmp(name,Bs.Getname()=0) Bs.Compute_average(); average=Bs.Get_average(); found=1; s+; break;case 2:while(s<N) if(strcmp(name,Cs.Getname()=0) Cs.Compute_average(); average=Cs.Get_average(); found=1; s+; break;case 3:while(s<N) if(strcmp(name,Ds.Getname()=0) Ds.Compute_average(); average=Ds.Get_average(); found=1; s+; break;if(found=0)cout<<"nntt 對(duì)不起,該類別中沒(méi)有您所要查看平時(shí)成績(jī)的學(xué)生!"<<e

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 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)論