C++學生成績管理系統(tǒng)課程設計報告_第1頁
C++學生成績管理系統(tǒng)課程設計報告_第2頁
C++學生成績管理系統(tǒng)課程設計報告_第3頁
C++學生成績管理系統(tǒng)課程設計報告_第4頁
C++學生成績管理系統(tǒng)課程設計報告_第5頁
已閱讀5頁,還剩12頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、一目的與要求通過本課程設計的實踐,全面總結C+課程學習中的的數(shù)據(jù)類型、程序結構、數(shù)組、函數(shù)、指針、結構體、鏈表等基本概念,掌握其使用方法。掌握面向對象程序設計中有關類、對象、繼承、重載、多態(tài)性、輸入輸出流類體系、文件操作的基本概念,初步學會用類與對象這種面向對象的程序設計方法編寫應用程序。培養(yǎng)使用面向對象的程序設計方法編寫計算機程序的能力。通過設計一個學生成績統(tǒng)計管理,進一步熟悉C+中類的概念、類的封裝、繼承的實現(xiàn)方式。了解系統(tǒng)開發(fā)的需求分析、類層次設計、模塊分解、編碼測試、模塊組裝與整體調試的全過程,加深對C+的理解與Visual C+環(huán)境的使用;逐步熟悉程序設計的方法,并養(yǎng)成良好的編程習慣

2、。程序設計是一門實踐性很強的課程,必須十分重視實踐環(huán)節(jié)。許多實際的知識不是靠聽課和看書學到的,而是通過長時間的實踐積累的。一、 設計內容學生成績管理系統(tǒng)1 基本功能: 這個程序的主要功能是輸入學生姓名、成績,學號,并可以對學生的成績按學號進行查詢。該系統(tǒng)具有存貯學生數(shù)據(jù),按學號按需要修改學生成績,列出學生成績和統(tǒng)計功能。2 擴展功能:學生數(shù)據(jù)的添加、修改、與刪除2.ER修改數(shù)據(jù)刪除數(shù)據(jù)查詢數(shù)據(jù)顯示數(shù)據(jù)平均數(shù)據(jù)添加數(shù)據(jù)學生成績管理系統(tǒng) 二、 過程與結果主要內容如下:1. 關鍵類的設計,繼承層次關系,代碼:首先,創(chuàng)建了一個student類. Student類的聲明如下:class Studentp

3、ublic:int Class,num;char name8;float cpp,math,eng,ave;int order;Student *next;public:Student() Student(int c1,int n1,char*n,float e1,float c2,float m,float e2,float s,float p,float a,int o,Student *next=NULL)Class=c1;num=n1;strcpy(name,n);cpp=c2;math=m;eng=e2;ave=a;order=o;this->next=next; 主要功能函數(shù)

4、的設計:1. 創(chuàng)建學生數(shù)據(jù),對學生的成績的錄入。代碼:friend Student *Create(Student *head,istream& in)int y;Student *p;int Class,num;char name8;float cpp,math,eng;if(&in=&cin)/cout<<"nn請輸入學生數(shù)據(jù)(輸入成績非法,則結束),數(shù)據(jù)輸入格式為:n"/<<"班級 姓名 學號 C+ 數(shù)學 英語 n"/in>>Class>>name>>num>

5、>cpp>>math>>eng;/cout<<"nn請輸入學生數(shù)據(jù):n"cout<<"班級:"<<endl; in>>Class; cout<<"姓名:"<<endl; in>>name;cout<<"學號:"<<endl; in>>num;cout<<"C+的成績:"<<endl; in>>cpp;cout&l

6、t;<"數(shù)學的成績:"<<endl; in>>math;cout<<"英語的成績 :"<<endl; in>>eng;/*while(Valid(elec)&&Valid(cpp)&&Valid(math)&&Valid(eng)&&Valid(sport)&&Valid(polity)*/p=new Student;p->Class=Class;p->num=num;strcpy(p->na

7、me,name);p->cpp=cpp;p->math=math;p->eng=eng;p->ave=(cpp+math+eng)/6;head=Insert(head,p);/in>>Class>>name>>num>>elec>>cpp>>math>>eng>>polity>>sport;cout<<"tt*繼續(xù)添加請按1*n"cout<<"tt*返回主菜單請按2*n" in>>y;

8、if(y=2) ShowMenu(); elsehead=Create(head,cin);SetOrder(head); /設置排名return head;2. 此函數(shù)為查找函數(shù)的實現(xiàn)過程 主要代碼:friend const Student * Lookup(const Student *head,int num) /查找指定學號為num的結點 while(head && head->num!=num)head=head->next;return head;friend void OutputOne(const Student* head) /輸出一個學生數(shù)據(jù)co

9、ut<<head->Class<<'t'<<head->name<<'t'<<head->num<<'t'<<head->cpp<<'t'<<head->math<<'t'<<head->eng<<'t'<<head->order<<endl;3.此函數(shù)為刪除函數(shù)的實現(xiàn)部分。 主要代碼:fri

10、end Student *DeleteStudent(Student *head,int num)Student *p1=head,*p2=p1;while(p2&&p2->num!=num)p1=p2,p2=p2->next;if(p2)if(p2=p1)head=head->next;delete p1;else p1->next=p2->next;delete p2;cout<<"已刪除"<<num<<"號學生數(shù)據(jù)n"SetOrder(head);else cout&

11、lt;<"沒找到指定學生!n"return head;4.排序函數(shù)中平均分來排序,排序結果為降序操作。friend void SetOrder(Student*head) int order=1;while(head)head->order=order+;head=head->next;5修改學生的信息friend Student *Modify(Student *head,int num) /修改學號為學生的數(shù)據(jù)Student *p1=head,*p2=p1;while(p2&&p2->num!=num) /尋找待修改的結點p1=p

12、2,p2=p2->next;if(p2) /修改指定結點數(shù)據(jù)/*cout<<"nn請輸入新數(shù)據(jù),格式為:n"<<"班級 姓名 學號 C+ 數(shù)學 英語 n"cin>>p2->Class>>p2->name>>p2->num>>p2->cpp>>p2->math>>p2->eng;*/ cout<<"班級:"<<endl; cin>>p2->Class; cou

13、t<<"姓名:"<<endl; cin>>p2->name;cout<<"學號:"<<endl; cin>>p2->num;cout<<"C+的成績:"<<endl; cin>>p2->cpp;cout<<"數(shù)學的成績:"<<endl; cin>>p2->math;cout<<"英語的成績 :"<<endl

14、; cin>>p2->eng;while(!Valid(p2->cpp)|!Valid(p2->math)|!Valid(p2->eng)cout<<"nn成績數(shù)據(jù)非法!請重新輸入,格式為:n"<<"班級 姓名 學號 C+ 數(shù)學 英語 n"cin>>p2->Class>>p2->name>>p2->num>>p2->cpp>>p2->math>>p2->eng;p2->ave=(p2

15、->cpp+p2->math+p2->eng)/3;/將修改的指定結點從原鏈表上修改下來,并重新降序插入原鏈表if(p2=p1)head=Insert(p2->next,p2);elsep1->next=p2->next; head=Insert(head,p2);SetOrder(head);else cout<<"沒找到指定學生!n"return head;6.顯示數(shù)據(jù):friend void OutputAll(const Student*head) /輸出所有學生的數(shù)據(jù)if(!head) cout<<&qu

16、ot;nntt沒有任何學生數(shù)據(jù)!nn" return;cout<<"nntt學生成績表nn"cout<<"班級t姓名t學號tC+t數(shù)學t英語t名次n"while(head)OutputOne(head);head=head->next;7.平均數(shù)據(jù)函數(shù)friend void Statistic(const Student *head)int i=0;float ave_cpp=0,ave_math=0,ave_eng=0;while(head)ave_cpp+=head->cpp;ave_math+=head

17、->math;ave_eng+=head->eng;i+;head=head->next;if(!i)cout<<"nn沒有任何學生數(shù)據(jù)!n"return;cout<<"nntt各門課程平均成績表nn"cout<<"tC+t數(shù)學t英語n"cout<<ave_cpp/i<<'t'<<ave_math/i<<'t'<<ave_eng/i<<endl;程序測試結果:1運行程序.會出現(xiàn)如

18、下畫面,按照提示進行選擇.2. 首先選擇1,然后按Enter鍵.按照提示對學生情況進行輸入.如圖:3. 按1鍵可以添加多個學生成績的數(shù)據(jù),按2返回主界面。4. 選擇5, 然后按Enter鍵,顯示剛才輸入的數(shù)據(jù)和排名的情況。5在主界面選擇2可以修改學生的數(shù)據(jù)。6.在主界面選擇3可以按學號查詢學生成績情況7. 在主界面選擇7可以按學號刪除學生的成績信息 三、 設計總結這次課程設計基本上涵蓋了學習到的C+ 語言知識點,課程設計題目要求不僅要求對課本雖然是網(wǎng)上搜來的代碼,但這些代碼沒辦法運行,我把這些代碼改了和增加了自己寫的代碼,終于可以運行,而且到達自己想要的結果,這次課程設計不僅讓我修補了以前學習

19、的漏洞,也讓我知道一個道理:編程需要興趣和實際動手。C+語言程序設計課程設計,我從中受益匪淺,并且對C+語言程序設計這一門課程有了更深一步的認識。附件程序源代碼清單:#include <fstream.h>#include <string.h>class Studentpublic:int Class,num;char name8;float cpp,math,eng,ave;int order;Student *next;public:Student() Student(int c1,int n1,char*n,float e1,float c2,float m,fl

20、oat e2,float s,float p,float a,int o,Student *next=NULL)Class=c1;num=n1;strcpy(name,n);cpp=c2;math=m;eng=e2;ave=a;order=o;this->next=next; friend int Valid(float score) return (score<0|score>100) ?0:1;friend void SetOrder(Student*head) int order=1;while(head)head->order=order+;head=head-

21、>next;friend Student* Insert(Student *head,Student *p) /在head所指的鏈表中降序插入結點p Student*p1,*p2;if(head=0)head=p;p->next=0;else if(head->ave<=p->ave)p->next=head;head=p;elsep2=p1=head;while(p2->next&&p2->ave>p->ave)p1=p2;p2=p2->next;if(p2->ave>p->ave)p2-&g

22、t;next=p;p->next=0;else p->next=p2;p1->next=p;return head;friend Student *Create(Student *head,istream& in)int y;Student *p;int Class,num;char name8;float cpp,math,eng;if(&in=&cin)/cout<<"nn請輸入學生數(shù)據(jù)(輸入成績非法,則結束),數(shù)據(jù)輸入格式為:n"/<<"班級 姓名 學號 C+ 數(shù)學 英語 n"/in

23、>>Class>>name>>num>>cpp>>math>>eng;/cout<<"nn請輸入學生數(shù)據(jù):n"cout<<"班級:"<<endl; in>>Class; cout<<"姓名:"<<endl; in>>name;cout<<"學號:"<<endl; in>>num;cout<<"C+的成績:

24、"<<endl; in>>cpp;cout<<"數(shù)學的成績:"<<endl; in>>math;cout<<"英語的成績 :"<<endl; in>>eng;/*while(Valid(elec)&&Valid(cpp)&&Valid(math)&&Valid(eng)&&Valid(sport)&&Valid(polity)*/p=new Student;p->C

25、lass=Class;p->num=num;strcpy(p->name,name);p->cpp=cpp;p->math=math;p->eng=eng;p->ave=(cpp+math+eng)/6;head=Insert(head,p);/in>>Class>>name>>num>>elec>>cpp>>math>>eng>>polity>>sport;cout<<"tt*繼續(xù)添加請按1*n"cout<<

26、;"tt*返回主菜單請按2*n" in>>y; if(y=2) ShowMenu(); elsehead=Create(head,cin);SetOrder(head); /設置排名return head;friend const Student * Lookup(const Student *head,int num) /查找指定學號為num的結點 while(head && head->num!=num)head=head->next;return head;friend void OutputOne(const Student*

27、 head) /輸出一個學生數(shù)據(jù)cout<<head->Class<<'t'<<head->name<<'t'<<head->num<<'t'<<head->cpp<<'t'<<head->math<<'t'<<head->eng<<'t'<<head->order<<endl;friend

28、void OutputAll(const Student*head) /輸出所有學生的數(shù)據(jù)if(!head) cout<<"nntt沒有任何學生數(shù)據(jù)!nn" return;cout<<"nntt學生成績表nn"cout<<"班級t姓名t學號tC+t數(shù)學t英語t名次n"while(head)OutputOne(head);head=head->next;friend Student *Modify(Student *head,int num) /修改學號為學生的數(shù)據(jù)Student *p1=hea

29、d,*p2=p1;while(p2&&p2->num!=num) /尋找待修改的結點p1=p2,p2=p2->next;if(p2) /修改指定結點數(shù)據(jù)/*cout<<"nn請輸入新數(shù)據(jù),格式為:n"<<"班級 姓名 學號 C+ 數(shù)學 英語 n"cin>>p2->Class>>p2->name>>p2->num>>p2->cpp>>p2->math>>p2->eng;*/ cout<<

30、"班級:"<<endl; cin>>p2->Class; cout<<"姓名:"<<endl; cin>>p2->name;cout<<"學號:"<<endl; cin>>p2->num;cout<<"C+的成績:"<<endl; cin>>p2->cpp;cout<<"數(shù)學的成績:"<<endl; cin>&g

31、t;p2->math;cout<<"英語的成績 :"<<endl; cin>>p2->eng;while(!Valid(p2->cpp)|!Valid(p2->math)|!Valid(p2->eng)cout<<"nn成績數(shù)據(jù)非法!請重新輸入,格式為:n"<<"班級 姓名 學號 C+ 數(shù)學 英語 n"cin>>p2->Class>>p2->name>>p2->num>>p2-&g

32、t;cpp>>p2->math>>p2->eng;p2->ave=(p2->cpp+p2->math+p2->eng)/3;/將修改的指定結點從原鏈表上修改下來,并重新降序插入原鏈表if(p2=p1)head=Insert(p2->next,p2);elsep1->next=p2->next; head=Insert(head,p2);SetOrder(head);else cout<<"沒找到指定學生!n"return head;friend Student *DeleteStude

33、nt(Student *head,int num)Student *p1=head,*p2=p1;while(p2&&p2->num!=num)p1=p2,p2=p2->next;if(p2)if(p2=p1)head=head->next;delete p1;else p1->next=p2->next;delete p2;cout<<"已刪除"<<num<<"號學生數(shù)據(jù)n"SetOrder(head);else cout<<"沒找到指定學生!n&q

34、uot;return head;friend void Statistic(const Student *head)int i=0;float ave_cpp=0,ave_math=0,ave_eng=0;while(head)ave_cpp+=head->cpp;ave_math+=head->math;ave_eng+=head->eng;i+;head=head->next;if(!i)cout<<"nn沒有任何學生數(shù)據(jù)!n"return;cout<<"nntt各門課程平均成績表nn"cout<

35、<"tC+t數(shù)學t英語n"cout<<ave_cpp/i<<'t'<<ave_math/i<<'t'<<ave_eng/i<<endl;friend void DeleteChain(Student *head)Student *p;while(head)p=head;head=head->next;delete p;friend void ShowMenu(void)cout<<"nn"cout<<"tt

36、*歡迎使用學生成績管理系統(tǒng)*n"<<"tt* *n"<<"tt* 1.從鍵盤錄入與添加數(shù)據(jù) *n"/<<"tt* 2.從文件錄入與添加數(shù)據(jù) *n"<<"tt* 2.修改數(shù)據(jù) *n"<<"tt* 3.查詢數(shù)據(jù) *n"<<"tt* 4.刪除數(shù)據(jù) *n"<<"tt* 5.顯示數(shù)據(jù) *n"<<"tt* 6.平均數(shù)據(jù) *n"/<<"tt* 7.保存數(shù)據(jù) *n"<<"tt* *n"<<"tt* 0.退出系統(tǒng)

溫馨提示

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

評論

0/150

提交評論