




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、面向?qū)ο蟮某绦蛟O(shè)計(jì)課程設(shè)計(jì)報(bào)告姓 名: 學(xué) 號(hào): 班 級(jí): 院 系: 數(shù)學(xué)與計(jì)算機(jī)學(xué)院 日 期: 2015.1.3 1. 課程題目 題目1:通過(guò)組合和派生構(gòu)成新的類本設(shè)計(jì)題目的任務(wù)是使用point類產(chǎn)生line類。分別通過(guò)組合類及派生類兩種方法實(shí)現(xiàn),并要求分別給出使用類模板實(shí)現(xiàn)的程序。本設(shè)計(jì)題的目的是使學(xué)生掌握在不同的實(shí)現(xiàn)方法中,如何設(shè)計(jì)相應(yīng)的構(gòu)造函數(shù)和拷貝構(gòu)造函數(shù),進(jìn)一步理解程序調(diào)用它們及析構(gòu)函數(shù)的執(zhí)行順序,掌握組合類和派生類。另外本設(shè)計(jì)題目要讓學(xué)生進(jìn)一步掌握和理解類模板的技術(shù)及其實(shí)現(xiàn)方法。題目2:成績(jī)管理系統(tǒng) 輸入一個(gè)班級(jí)的學(xué)生基本信息(包括學(xué)號(hào),姓名,性別,科目),對(duì)n門考試的成績(jī)進(jìn)行管
2、理(例n=5) 要求 l 用戶錄入每個(gè)學(xué)生每門課程的分?jǐn)?shù); l 能夠計(jì)算每個(gè)學(xué)生的各門功課總分和平均分,并按總分將成績(jī)排序,顯示每個(gè)學(xué)生的總分和排名; l 計(jì)算全班各門功課的平均分,顯示每門課程中低于平均分的每一個(gè)學(xué)生的學(xué)號(hào),姓名,性別,科目,成績(jī)等信息; l 顯示每門科目中,成績(jī)?cè)?0分以上的學(xué)生信息。另外還輸出每門科目中不及格的學(xué)生信息; l 能按姓名或者學(xué)號(hào)查找,增加,刪除和保存各個(gè)學(xué)生的信息。2. 設(shè)計(jì)分析題目1:point1,point2作為point類的對(duì)象,兩個(gè)點(diǎn)確定一條直線。題目2:3. 代碼設(shè)計(jì)題目一:a:組合類#include #include using namespac
3、e std; template class point protected: t x; t y; public : point(); point(t,t); point(point &); point(); void setx(t); t getx(); void sety(t); t gety(); void displaypoint(); ; template point:point() x=0; y=0; coutpoint 類默認(rèn)構(gòu)造函數(shù)!endl; template point:point(t x,t y) this-x=x; this-y=y; coutpoint 類帶參構(gòu)造函數(shù)!
4、endl; template point:point(point &newpoint) this-x=newpoint.x; this-y=newpoint.y; coutpoint 類拷貝構(gòu)造函數(shù)!endl; template point:point() coutpoint 類析構(gòu)函數(shù)!endl; template void point:setx(t x) this-x=x; template t point:getx() return this-x; template void point:sety(t y) this-y=y; template t point:gety() return
5、 this-y; template void point:displaypoint() cout (x,y)endl; template class line private: point point1; point point2; public: line(); line(point,point); line(t,t,t,t); line(line &); line(); void setpoint1(point); point getpoint1(); void setpoint2(point); point getpoint2(); void displayline(); t lengt
6、h(); ; template line:line() coutline類默認(rèn)構(gòu)造函數(shù)!endl; template line:line(point p1,point p2) this-point1=p1; this-point2=p2; coutline類帶參構(gòu)造函數(shù)!endl; template line:line(t x1,t y1,t x2,t y2):point1(x1,y1),point2(x2,y2) coutline類構(gòu)造函數(shù)!endl; template line:line(line &line):point1(line.point1),point2(line.point2)
7、 coutline類拷貝構(gòu)造函數(shù)!endl; template line:line() coutline類析構(gòu)函數(shù)!endl; template void line:setpoint1(point point1) this-point1=point1; template point line:getpoint1() return this-point1; template void line:setpoint2(point point2) this-point2=point2; template point line:getpoint2() return this-point2; templa
8、te t line:length() return sqrt(fabs(point1.getx()-point2.getx()*(point1.getx()-point2.getx()+fabs(point1.gety()-point2.gety()*(point1.gety()-point2.gety(); template void line:displayline() cout!endl; coutline直線上兩點(diǎn)是:endl; point1.displaypoint(); point2.displaypoint(); coutline兩點(diǎn)之間的距離是:length()endl; co
9、ut!endl; ;void main() line line(2,3,7,7); line.displayline();b:派生類:#include #include using namespace std; template class point protected: t x; t y; public : point(); point(t,t); point(point &); point(); void setx(t); t getx(); void sety(t); t gety(); void displaypoint(); ; template point:point() x=0
10、; y=0; coutpoint 類默認(rèn)構(gòu)造函數(shù)!endl; template point:point(t x,t y) this-x=x; this-y=y; coutpoint 類帶參構(gòu)造函數(shù)!endl; template point:point(point &newpoint) this-x=newpoint.x; this-y=newpoint.y; coutpoint 類拷貝構(gòu)造函數(shù)!endl; template point:point() coutpoint 類析構(gòu)函數(shù)!endl; template void point:setx(t x) this-x=x; template t
11、 point:getx() return this-x; template void point:sety(t y) this-y=y; template t point:gety() return this-y; template void point:displaypoint() cout (x,y)endl; template class line:public point private: t x1; t y1; public : line(); line(t,t); line(t,t,t,t); line(line &); line(); void setx1(t); t getx1
12、(); void sety1(t); t gety1(); void displayline(); t length(); ; template line:line() coutline 類的默認(rèn)構(gòu)造函數(shù)!endl; template line:line(t x1,t y1) this-x1=x1; this-y1=y1; coutline類的帶參構(gòu)造函數(shù)!endl; template line:line(t x1,t y1,t x ,t y):point(x,y) this-x1=x1; this-y1=y1; coutline類的帶參構(gòu)造函數(shù)!endl; template line:lin
13、e(line &newline):point(newline) this-x1=newline.x1; this-y1=newline.y1; coutline類的拷貝構(gòu)造函數(shù)!endl; template line:line() coutline 類的析構(gòu)函數(shù)!endl; template void line:setx1(t x1) this-x1=x1; template t line:getx1() return this-x1; template void line:sety1(t y1) this-y1=y1; template t line:gety1() return this-
14、y1; template t line:length() return sqrt(fabs(x-x1)*(x-x1)+fabs(y-y1)*(y-y1); template void line:displayline() cout!endl; coutline直線上兩點(diǎn)是:endl; cout (x1,y1)endl; displaypoint(); coutline兩點(diǎn)之間的距離是:length()endl; cout!endl; void main() line line(2,3,7,7); line.displayline();題目2:#include#include#includeus
15、ing namespace std;class studentpublic:char name20;double maths,chinese,english,physics,chemistry,average,sum;student()coutstudent的默認(rèn)構(gòu)造函數(shù)被調(diào)用!endl;student(char n20,double m,double c,double e,double p,double c)strcpy(name,n);maths=m;chinese=c;english=e;physics=p;chemistry=c;coutstudent帶參數(shù)的構(gòu)造函數(shù)被調(diào)用!endl;
16、double getsum()sum=maths+chinese+english+physics+chemistry;return sum;double getaverage()average=getsum()/5;return average;friend main();main(void)cout請(qǐng)選擇您需要的操作:endl; cout操作數(shù)據(jù):endl; cout(0)數(shù)據(jù)錄入endl;cout(1)增加人員endl; cout(2)刪除人員endl; cout(3)修改數(shù)據(jù)endl; cout查詢數(shù)據(jù):endl; cout(4)按總成績(jī)查詢endl;cout(5)按姓名查詢endl;
17、cout(6)輸出所有學(xué)生的數(shù)據(jù)endl; cout成績(jī)排名:endl; cout(7)按總分查詢排名endl; cout(8)按數(shù)學(xué)查詢排名endl;cout(9)按語(yǔ)文查詢排名endl; cout(10)按英語(yǔ)查詢排名endl; cout(11)按物理查詢排名endl;cout(12)按化學(xué)查詢排名endl;coutp; if(p=0&p=12) flag2=1; else cout指令錯(cuò)誤!請(qǐng)重新輸入:endl; while(flag2=0);doswitch(p)case 0:char c; char name20;double chinese,maths,english,physic
18、s,chemistry; do coutname; coutchinese; coutmaths; coutenglish; coutphysics;coutchemistry;filej=new ofstream(d:document,ios:ate); *filej姓名:name數(shù)學(xué)成績(jī)maths語(yǔ)文成績(jī)chinese英語(yǔ)成績(jī)english物理成績(jī)physics化學(xué)成績(jī)chemistryendl;j+;si=new student(name, maths, chinese, english,physics,chemistry); i+; cout數(shù)據(jù)錄入成功,想繼續(xù)錄入嗎(y/n)c; f
19、lag2=0;do if(c!=y&c!=n) cout指令錯(cuò)誤!請(qǐng)重新輸入!c; else flag2=1; while(flag2=0); while(c=y); break; case 1: char name20;double chinese,maths,english,physics,chemistry; char c; do coutname; coutchinese; coutmaths; coutenglish; coutphysics;coutchemistry;filej=new ofstream(d:document,ios:ate); *filej姓名:name語(yǔ)文成績(jī)
20、chinese數(shù)學(xué)成績(jī)maths外語(yǔ)成績(jī)english物理成績(jī)physics化學(xué)成績(jī)chemistryendl; j+; si=new student(name, maths, chinese, english,physics,chemistry); i+;cout數(shù)據(jù)錄入成功,想繼續(xù)錄入嗎?(y/n)c; if(c!=y&c!=n) cout指令錯(cuò)誤!請(qǐng)重新輸入!c; while(c=y); break; case 2: char name20;bool flag3=0;char c; do cout請(qǐng)輸入您要?jiǎng)h除的學(xué)生姓名:name; for(int h=0;hname)=0) flag3
21、=1;i-; do sh=sh+1; h+; while(h=i); if(flag3=0) cout您要求刪除的對(duì)象本來(lái)就不存在!請(qǐng)檢查輸入的正確性!; cout要繼續(xù)刪除嗎?(y/n)c; if(c!=y&c!=n) cout指令錯(cuò)誤!請(qǐng)重新輸入!c; while(c=y);break; case 3: char name20;double mat,chin,eng,phy,che;flag2=0; char c;do coutname;for(int h=0;hname)=0) flag2=1; coutchin; coutmat; couteng; coutphy; coutche;s
22、h-maths=mat; sh-chinese=chin;sh-english=eng; sh-physics=phy;sh-chemistry=phy;cout數(shù)據(jù)修改成功!; if(flag2=0) cout您要修改的學(xué)生本來(lái)就不存在!請(qǐng)檢查重新輸入!endl; cout想繼續(xù)修改嗎?(y/n)c; if(c!=y&c!=n) cout指令錯(cuò)誤!請(qǐng)重新輸入!c; while(c=y); break; case 4: double t;char c; do int flag1=0; cout請(qǐng)輸入你要查詢學(xué)生的總成績(jī):t;for(int q=0;qgetsum()=t) flag1=1; c
23、out”要查詢的學(xué)生是:(*sq).nameendl; if(flag1=0) cout對(duì)不起,您要查詢的學(xué)生不存在!endl; cout您想繼續(xù)查詢嗎?(y/n)c;if(c!=y&c!=n) cout指令錯(cuò)誤!請(qǐng)重新輸入!c; while(c=y); break; case 5: char n20;int j=0;char c; do int flag=0; coutn; for(int j=0;ji;j+) if(strcmp(n,(*sj).name)=0) flag=1; cout您要查詢的學(xué)生是:(*sj).nameendl; cout(*sj).name 語(yǔ)文:(*sj).chi
24、nese 數(shù)學(xué):(*sj).maths 英語(yǔ):(*sj).english 物理:(*sj).physics 化學(xué):(*sj).chemistryendl的總成績(jī)成績(jī)是(*sj).getsum() 平均成績(jī)是:(*sj).getaverage()endl; if(flag=0) cout對(duì)不起!您要查詢的學(xué)生不存在!endl; cout您想繼續(xù)查詢嗎?(y/n)c; if(c!=y&c!=n) cout指令錯(cuò)誤!請(qǐng)重新輸入!c; while(c=y); break; case 6: cout本系統(tǒng)所有學(xué)生數(shù)據(jù)如下:endl; if(i=0) cout管理系統(tǒng)中沒(méi)有錄入數(shù)據(jù)或者數(shù)據(jù)已經(jīng)被刪除!en
25、dl;for(int k=0;ki;k+) coutk+1姓名:name 語(yǔ)文:chinese 數(shù)學(xué):maths 英語(yǔ):english 物理:physics 化學(xué):chemistry 總分:(*sk).getsum() 平均分:(*sk).getaverage()endl; break; case 7: int t;student b; cout本系統(tǒng)所以學(xué)生排名如下:endl; for(int x=0;xi-1;x+) t=x; for(int y=x+1;ygetsum()getsum() t=y; if(t!=x) b=*sx; *sx=*st; *st=b; if(i=0) cout管
26、理系統(tǒng)中沒(méi)有錄入數(shù)據(jù)或者數(shù)據(jù)已經(jīng)被刪除!;for(int k=0;ki;k+) coutk+1 姓名: name語(yǔ)文: chinese數(shù)學(xué): maths 英語(yǔ): english物理: physics化學(xué): chemistry總分: (*sk).getsum() 平均分: (*sk).getaverage()endl; break; case 8: int t;student b; cout本系統(tǒng)所以學(xué)生數(shù)學(xué)排名如下:endl; for(int x=0;xi-1;x+) t=x; for(int y=x+1;ymaths)maths) t=y; if(t!=x) b=*st; *st=*sx;
27、*sx=b; if(i=0) cout管理系統(tǒng)中沒(méi)有錄入數(shù)據(jù)或者數(shù)據(jù)已經(jīng)被刪除!;for(int k=0;ki;k+) coutk+1 姓名: name語(yǔ)文: chinese數(shù)學(xué): maths 英語(yǔ): english物理: physics化學(xué): chemistry總分: (*sk).getsum() 平均分: (*sk).getaverage()endl;break;case 9: int t;student b; cout本系統(tǒng)所以學(xué)生語(yǔ)文排名如下:endl; for(int x=0;xi-1;x+) t=x; for(int y=x+1;ychinese)chinese) t=y; if(
28、t!=x) b=*st; *st=*sx; *sx=b; if(i=0) cout管理系統(tǒng)中沒(méi)有錄入數(shù)據(jù)或者數(shù)據(jù)已經(jīng)被刪除!;for(int k=0;ki;k+) coutk+1 姓名: name語(yǔ)文: chinese數(shù)學(xué): maths 英語(yǔ): english物理: physics化學(xué): chemistry總分: (*sk).getsum() 平均分: (*sk).getaverage()endl;break;case 10: int t;student b; cout本系統(tǒng)所以學(xué)生英語(yǔ)排名如下:endl; for(int x=0;xi-1;x+) t=x; for(int y=x+1;yen
29、glish)english) t=y; if(t!=x) b=*st; *st=*sx; *sx=b; if(i=0) cout管理系統(tǒng)中沒(méi)有錄入數(shù)據(jù)或者數(shù)據(jù)已經(jīng)被刪除!;for(int k=0;ki;k+) coutk+1 姓名: name語(yǔ)文: chinese數(shù)學(xué): maths 英語(yǔ): english物理: physics化學(xué): chemistry總分: (*sk).getsum() 平均分: (*sk).getaverage()endl;break;case 11: int t;student b; cout本系統(tǒng)所以學(xué)生物理排名如下:endl; for(int x=0;xi-1;x+) t=x; for(int y=x+1;yphysics)physics) t=y; if(t!=x) b=*st; *st=*sx; *sx=b; if(i=0) cout
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 交通信號(hào)控制系統(tǒng)操作規(guī)程
- 三農(nóng)村電商售后服務(wù)與客戶關(guān)系管理實(shí)戰(zhàn)指南
- 安裝光伏發(fā)電劃算不
- 汽車 充電樁 新能源
- 課題研究可行性分析格式模板
- 項(xiàng)目進(jìn)度管理與風(fēng)險(xiǎn)控制的工作計(jì)劃
- 三農(nóng)產(chǎn)品三農(nóng)村市場(chǎng)風(fēng)險(xiǎn)防控方案
- 消防中級(jí)監(jiān)控練習(xí)試題及答案
- 中級(jí)養(yǎng)老護(hù)理練習(xí)試題
- 茶藝師復(fù)習(xí)測(cè)試題
- 智研咨詢發(fā)布:汽車雨刮器總成產(chǎn)業(yè)百科(附行業(yè)現(xiàn)狀、相關(guān)政策及發(fā)展驅(qū)動(dòng)因素分析)
- DL∕T 2577-2022 軸流轉(zhuǎn)漿式水輪發(fā)電機(jī)組檢修規(guī)程
- 2023年四川省綿陽(yáng)市中考數(shù)學(xué)試卷
- 《統(tǒng)編教材背景下小學(xué)語(yǔ)文整本書(shū)閱讀策略的研究》中期報(bào)告
- (正式版)JBT 2930-2024 低壓電器產(chǎn)品型號(hào)編制方法
- 【課件】2024屆新高考英語(yǔ)語(yǔ)法填空專項(xiàng).解題技巧課件
- 九年級(jí)物理《第5節(jié) 磁生電》課件(三套)
- 腎上腺腺瘤切除術(shù)的圍術(shù)期護(hù)理
- 人工智能在健康管理與疾病預(yù)防中的應(yīng)用
- 高中英語(yǔ)作文感謝信寫作格式及范文
- 馬工程《思想政治教育學(xué)原理 第二版》課后習(xí)題詳解
評(píng)論
0/150
提交評(píng)論