2022年完整版,c++課程設計任務書1421813-15_第1頁
2022年完整版,c++課程設計任務書1421813-15_第2頁
2022年完整版,c++課程設計任務書1421813-15_第3頁
2022年完整版,c++課程設計任務書1421813-15_第4頁
2022年完整版,c++課程設計任務書1421813-15_第5頁
已閱讀5頁,還剩22頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、精選學習資料 - - - 歡迎下載面對對象程序設計課程設計任務書一.課程設計的目的與要求1.教學目的綜合運用所學過的學問進行實際程序設計;2.教學要求從課程設計的目的動身,用c+ 編寫簡潔的的程序,程序要求如下:( 1)算法正確,容錯性能好;( 2)完成從用戶需求分析.到上機編程.調(diào)試和應用等全過程;二.課程設計的題目.內(nèi)容及要求part 1:小程序練習(必需全部完成)1 函數(shù)重載定義重載函數(shù)max3用于運算三個數(shù)的最大值(參數(shù)類型分別為int 和 double);#include <iostream> using namespace std; int max3int a、int

2、b、int cifb>a a=b; ifc>a a=c; return a;double max3double a、double b、double cifb>a a=b; ifc>a a=c; return a;int main int max3int a、int b、int c;double max3double a、double b、double c; int i1、i2、i3、i;cout<<”請輸入三個數(shù):”<<endl;cin>>i1>>i2>>i3; i=max3i1、i2、i3; cout<

3、<"i.max3="<<i<<endl; double d1、d2、d3、d; cin>>d1>>d2>>d3; d=max3d1、d2、d3; cout<<"d.max3="<<d<<endl;2 類的組合定義 point類,數(shù)據(jù)成員包括x、y ,成員函數(shù)包括構(gòu)造函數(shù),拷貝構(gòu)造函數(shù)和析構(gòu)函數(shù),以及 setx ,getx ,sety , gety四個屬性函數(shù);定義line 類,端點由兩個point類的對象組成,包括構(gòu)造函數(shù),析構(gòu)函數(shù)以及運算線段長度的函數(shù)

4、getlength;在 main函數(shù)中,定義line 的對象,并輸出其長度;#include<iostream>1精品學習資料精選學習資料 - - - 歡迎下載#include<cmath> using namespace std; class pointprivate: int x、y; public:pointint x、int y:xx、yypointpoint &p; int getxreturn x; void setxint xthis->x=x; int getyreturn y; void setyint ythis->y=y;poi

5、nt;point:pointpoint &px=p.x;y=p.y; class lineprivate: point p1、p2; double len; public:linepoint pt1、point pt2; lineline &l;double getlenreturn len;line;line:linepoint pt1、point pt2:p1pt1、p2pt2double x=p1.getx-p2.getx; double y=p1.gety-p2.gety; len=sqrtx*x+y*y;line:lineline &l:p1l.p1、p2l.

6、p2len=l.len; int mainpoint po11、2、po23、4;line linepo1、po2;cout<<"the length of line is:"<<endl; cout<<line.getlen<<endl;3 對象數(shù)組和函數(shù)定義 student類,數(shù)據(jù)成員包括姓名name和成果 score ,成員函數(shù)包括構(gòu)造函數(shù),拷貝構(gòu)造函數(shù)和析構(gòu)函數(shù); 定義函數(shù)void highestscorestudent s、輸出分數(shù)最高的同學姓名和分數(shù);在 main函數(shù)中定義 student sn,調(diào)用 highes

7、tscore函數(shù) 、輸出分數(shù)最高的同學姓名和分數(shù);#include<iostream>2精品學習資料精選學習資料 - - - 歡迎下載#include<string> const int n=3;using namespace std;class studentprivate: string name; int score; public:studentstring n=""、int s=0:namen、scores studentstudent &stuname=; score=stu.score;studentfriend

8、 istream &operator>>istream &is、student &stuis>>>>stu.score; return is;friend void highestscorestudent s;void highestscorestudent stuint i、h、t; t=stu0.score; fori=0;i<n;i+ift<stui.scoret=stui.score; h=i;cout<<"name:"<<<<

9、;"score:"<<stuh.score<<endl;void mainstudent s1n; forint i=0;i<n;i+ cin>>s1i; highestscores1;4 靜態(tài)數(shù)據(jù)成員設計一個書類,能夠儲存書名.定價,全部書的本數(shù)和總價;(將書名和定價設計為一般數(shù)據(jù)成員;將書的本數(shù)和總價設計為靜態(tài)數(shù)據(jù)成員)#include<iostream>#include<string> using namespace std; class bookprivate:string name; int pri

10、ce、num;static int count、sum;3精品學習資料精選學習資料 - - - 歡迎下載public:bookstring na、int p、int n:namena、pricep、numncount+=num; sum+=num*price;void displaycout<<" 書名 :"<<name<<endl;cout<<" 價格 :"<<price<<endl;cout<<" 全部書的本數(shù):"<<num<&l

11、t;endl;cout<<" 總價 :"<<sum<<endl;book;int book:count=0; int book:sum=0; void mainbook a"c grammer"、100、10、b"c+ grammer"、50、6; a.display;b.display;5 動態(tài)內(nèi)存安排定義 point類,數(shù)據(jù)成員包括x、y ,成員函數(shù)包括構(gòu)造函數(shù),拷貝構(gòu)造函數(shù)和析構(gòu)函數(shù),以及 setx ,getx ,sety , gety四個屬性函數(shù);在main函數(shù)中,用new和 delete安

12、排和釋放n 個 point的數(shù)組;( n 為const常量, n=10 )#include<iostream> using namespace std; class pointprivate:int x、y;void setxint xthis->x=x; void setyint ythis->y=y;public:pointint x=0、int y=0; pointconst point &px=p.x;y=p.y;void setxyint x、int ysetxx;setyy; int getxreturn x; int gety4精品學習資料精選學習

13、資料 - - - 歡迎下載return y;void showpointcout<<"x="<<x<<"y="<<y<<endl;point;inline point:pointint x、int ythis->x=x; this->y=y;void mainpoint *pt=new point10; *pt.setxy1、2;*pt.showpoint;delete pt;6 類的繼承定義一個point類,包含私有數(shù)據(jù)成員x ,y ,成員函數(shù)包括無參構(gòu)造函數(shù),帶參構(gòu)造函數(shù),set

14、 和 get屬性函數(shù);定義circle類,從 point類公有派生,增加數(shù)據(jù)成員半徑r,成員函數(shù)包括無參構(gòu)造函數(shù),帶 參構(gòu)造函數(shù),運算面積函數(shù)getarea;在 main函數(shù)中定義一個circle的對象,并運算其面積;#include<iostream> using namespace std; class pointprivate:int x、y; public:point:x0、y0pointint x、int y:xx、yy int getxreturn x; void setxint xthis->x=x; int getyreturn y;void setyint

15、ythis->y=y;point;class circle:public pointprivate: int r; public:circleint x、int y、int r:pointx、y、rr int getrreturn r;void setrint r5精品學習資料精選學習資料 - - - 歡迎下載this->r=r; void getareacout<<"area:"<<r*r*3.14<<endl;int maincircle c1、2、3; c.getarea;7 虛基類定義 vehicle類,數(shù)據(jù)成員包括私

16、有的weight,公有的構(gòu)造函數(shù), 析構(gòu)函數(shù)和輸出函數(shù)dispaly ; 從 vehicle類公有派生car類,增加數(shù)據(jù)成員載人數(shù)personnum,公有的構(gòu)造函數(shù)、析構(gòu)函數(shù)和輸出display;從vehicle類公有派生truck類,增加數(shù)據(jù)成員載貨量laod、 公有的構(gòu)造函數(shù), 析構(gòu)函數(shù)和輸出函數(shù)display;從 car類和 truck類共同公有派生出pickup類,包括公有的構(gòu)造函數(shù)和輸出函數(shù);在 main函數(shù)中, 定義 pickup類對象,并輸出其基本信息;#include<iostream> using namespace std; class vehiclepriva

17、te: int weight; public:vehicleint w:weightw void displaycout<<"weight:"<<weight<<endl;vehicle;class car:virtual public vehicleprivate:int personnum; public:carint p、int w:vehiclew、personnump void displaycout<<"personnum:"<<personnum<<endl;car;c

18、lass truck:virtual public vehicleprivate: int load; public:truckint w、int l:vehiclew、loadl void displaycout<<"load:"<<load<<endl;truck6精品學習資料精選學習資料 - - - 歡迎下載;class pickup:virtual public car、public truckpublic:pickupint w、int l、int p、int w1、int w2:vehiclew、carw1、p、truckw2

19、、l void display;void mainpickup p10、20、30、40、50;p.vehicle:display; p.car:display;p.truck:display;p.pickup:display;8 運算符重載,友元函數(shù)和this 指針定義一個計數(shù)器類counter,具備自增,自減功能(前后綴);輸入輸出>>、<< 功能;在main函數(shù)里測試該類;#include<iostream> using namespace std; class counterprivate:double number; public:counterd

20、ouble num=0:numbernum friend counter operator +counter &c、int; friend counter operator -counter &c、int; friend counter operator +counter &c; friend counter operator -counter &c;friend istream &operator>>istream &is、counter &cis>>c.number; return is;friend ostr

21、eam &operator<<ostream &os、counter &cos<<c.number; return os;counter;counter operator +counter &c c+;return c;counter operator -counter &c c-;return c;counter operator +counter &c、intcounter ctemp;7精品學習資料精選學習資料 - - - 歡迎下載ctemp=c.number; c.number+; return ctemp;cou

22、nter operator -counter &c、intcounter ctemp; ctemp=c.number; c.number-; return ctemp;int main counter c1、c2; cin>>c1; c2=operator+c1、2;cout<<"count before:"<<c2<<"count after:"<<c1<<endl;9 虛函數(shù)和抽象類定義一個抽象類shape ,包括公有的運算面積area函數(shù),運算體積volume函數(shù),輸出

23、基本信息函數(shù) printinfo(三個函數(shù)均為純虛函數(shù));從shape公有派生point類,增加私有數(shù)據(jù)成員x、y 坐標,以及構(gòu)造函數(shù), 析構(gòu)函數(shù); 從 point公有派生circle類,增加私有數(shù)據(jù)成員半徑r,以及構(gòu)造函數(shù), 析構(gòu)函數(shù);從 circle公有派生cylinder類,增加私有數(shù)據(jù)成員高度h ,以及構(gòu)造函數(shù),析構(gòu)函數(shù);(在定義三個派生類的過程中,自己考慮需要重定義哪個虛函數(shù));在main函數(shù)中,定義shape類的指針,指向派生類的對象,輸出三類對象的基本信息,面積,體積;(將shape指針改為引用再嘗試);#include<iostream> using namespa

24、ce std; class shapepublic:virtual double area=0; virtual double volume=0; virtual void printinfo=0;class point:public shape private: int x、y; public:pointint x、int y:xx、yydouble areareturn 0; double volumereturn 0; void printinfocout<<"point:x="<<x<<"、y="<<

25、;y<<endl;point;class circle:public pointprivate: int r; public:8精品學習資料精選學習資料 - - - 歡迎下載circleint x、int y、int r:pointx、y、rr double areareturn 3.14*r*r;void printinfocout<<"area:"<<area<<endl;circle;class cylinder:public circleprivate: int h; public:cylinderint x、int

26、y、int r、int h:circlex、y、r、hh double volumereturn circle:area*h; void printinfocout<<"volume:"<<volume<<endl;cylinder;void funshape *pp->printinfo;void mainpoint p1、1;circle c1、1、3;cylinder c1、1、3、4;/*p.printinfo; c.printinfo; c.printinfo;*/ fun&p;fun&c;fun&

27、c;10 模板設計一個堆棧的類模板stack ,在模板中用類型參數(shù)t 表示棧中存放的數(shù)據(jù),用非類型參數(shù)maxsize 代表棧的大??;#include<iostream.h> const int maxsize=5; template<typename t> class stackprivate:t elemmaxsize; int top;public:stacktop=0;void pusht eif top=maxsize9精品學習資料精選學習資料 - - - 歡迎下載cout<<" 棧已滿! "<<endl; retur

28、n ;elemtop=e; top+;t popiftop=0cout<<"???! "<<endl; return -1;top -;return elemtop;void mainstack <int> s; s.push1;s.push2;s.push3;s.push4;s.push5;s.push6; cout<<s.pop<<endl;11 文件讀寫定義同學類數(shù)組,有n 個人( n=5 ),包括姓名和語數(shù)外三名課的成果,通過重載<< 和>> 運算符實現(xiàn)同學數(shù)組的文件讀寫;(姓名用st

29、ring name;)#include<iostream>#include<fstream> using namespace std; class stuprivate:char name10; int chi、mat、eng; public:stuchar s=""、int c=0、int m=0、int e=0strcpyname、s; chi=c;mat=m; eng=e;friend ostream&operator<<ostream &os、stu &sos<<<<&q

30、uot; "<<s.chi<<" "<<s.mat<<" "<<s.eng<<endl; return os;friend istream&operator>>istream &is、stu &sis>>>>s.chi>>s.mat>>s.eng;10精品學習資料精選學習資料 - - - 歡迎下載return is;const int n=5; void mainstu sn;i

31、nt i=0;fstream iof"c:student.txt"、ios:out|ios:binary; if.iof.is_open cout<<"file open failed"<<endl; return ;elseforint i=0;i<n;i+cin>>si; cout<<si;iof.writechar *&si、sizeofstu ;iof.close ;stu s1n; iof.open"c:student.txt"、ios:out|ios:binar

32、y; if.iof.is_openreturn ;elseint i=0;iof.readchar *&s1i、sizeofstu; while.iof.eofcout<<s1i;i+;iof.readchar *&s1i、sizeofstu;iof.close;part 2:小型軟件的開發(fā)(選做一題,且由個人獨立開發(fā)完成)1 老師通信錄的設計基本要求:定義老師 ( teacher )類,其中至少包括姓名.性別. 電話. 地址. 郵政編碼. 郵箱. qq號和類別 (例如:同學.伴侶等);功能要求:1.設計菜單實現(xiàn)功能挑選;2.輸入功能:輸入人員信息,并儲存到文件中;

33、3.查詢功能:1)能夠依據(jù)姓名.電話精確查詢?nèi)藛T信息;11精品學習資料精選學習資料 - - - 歡迎下載2)能夠依據(jù)地址進行模糊查詢?nèi)藛T信息;3)依據(jù)人員類別查詢?nèi)藛T信息4 .依據(jù)姓名對人員信息排序輸出5 .能依據(jù)姓名.電話修改人員信息6 .能依據(jù)姓名.電話刪除人員信息2 職工工資治理基本要求:定義職工( employee)類,其中至少包括姓名.性別.工號.電話.所在科室和工資;功能要求:1.設計菜單實現(xiàn)功能挑選;2.輸入功能:輸入職工信息,并儲存到文件中;3.查詢功能:1)能夠依據(jù)工號精確查詢職工信息;2)能夠依據(jù)姓名.科室查詢職工信息43)分科室進行工資統(tǒng)計,運算各科室的平均工資.依據(jù)職工

34、的工資排序輸出5.依據(jù)工號修改職工信息6.依據(jù)工號刪除職工信息#include<iostream>#include<string> using namespace std; class employeeprivate:string name、sex、office;int id、phone number、salary; public:employee3 公司員工治理系統(tǒng)基本要求:設計一個虛基類 staff (員工) ,包括編號. 姓名和年齡愛護數(shù)據(jù)成員以及相關的成員函數(shù); 由 staff 派生出工程師類 engineer 包含專業(yè)和職稱愛護數(shù)據(jù)成員以及相關的成員函數(shù), 再

35、由 staff 派生出領導類 leader ,包括職務和部門愛護數(shù)據(jù)成員以及相關的成員函數(shù);然后由 engineer 和 leader 類派生出主任工程師類 chairman ;功能要求:1.增加員工數(shù)據(jù)信息2.更新員工數(shù)據(jù)信息3.查詢員工數(shù)據(jù)信息4.刪除員工數(shù)據(jù)信息5.良好的人際交互界面.便利操作12精品學習資料精選學習資料 - - - 歡迎下載4 三角形的種類與面積基本要求:定義點( point )類,包含點的坐標x 和 y;通過繼承點類派生出線段(line )類;通過線段(line)類的組合定義三角形(triangle)類;功能要求:1 .設計菜單實現(xiàn)功能挑選;2 .輸入三角形的三個頂點

36、坐標;3 .判定三角形的種類(一般三角形.等腰三角形.等邊三角形.直角三角形和不能構(gòu)成三精品學習資料精選學習資料 - - - 歡迎下載角形);4 .運算并輸出三角形的面積;精品學習資料精選學習資料 - - - 歡迎下載5 字符串類的設計基本要求:定義點字符串(string)類,包含存放字符串的字符數(shù)組和字符串中字符的個數(shù);功能要求:1.設計菜單實現(xiàn)功能挑選;2.字符串的輸入與賦值;31.字符串的運算,包括:)連接2)復制3)查找4)交換5)求子串6)比較4.字符串的輸出6 同學成果治理基本要求:定義同學( student)類,其中至少包括姓名.性別.學號.班級和四門功課的成果;功能要求:1.設計菜單實現(xiàn)功能挑選;2.輸入功能:輸入同學信息,并儲存到文件中;3.運算每個同學的總分與平均分并排

溫馨提示

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

評論

0/150

提交評論