![C++上機(jī)練習(xí)第四章.docx_第1頁(yè)](http://file.renrendoc.com/FileRoot1/2020-1/6/7cc825c1-be57-4bf6-9432-d9b7314d0d20/7cc825c1-be57-4bf6-9432-d9b7314d0d201.gif)
![C++上機(jī)練習(xí)第四章.docx_第2頁(yè)](http://file.renrendoc.com/FileRoot1/2020-1/6/7cc825c1-be57-4bf6-9432-d9b7314d0d20/7cc825c1-be57-4bf6-9432-d9b7314d0d202.gif)
![C++上機(jī)練習(xí)第四章.docx_第3頁(yè)](http://file.renrendoc.com/FileRoot1/2020-1/6/7cc825c1-be57-4bf6-9432-d9b7314d0d20/7cc825c1-be57-4bf6-9432-d9b7314d0d203.gif)
![C++上機(jī)練習(xí)第四章.docx_第4頁(yè)](http://file.renrendoc.com/FileRoot1/2020-1/6/7cc825c1-be57-4bf6-9432-d9b7314d0d20/7cc825c1-be57-4bf6-9432-d9b7314d0d204.gif)
![C++上機(jī)練習(xí)第四章.docx_第5頁(yè)](http://file.renrendoc.com/FileRoot1/2020-1/6/7cc825c1-be57-4bf6-9432-d9b7314d0d20/7cc825c1-be57-4bf6-9432-d9b7314d0d205.gif)
已閱讀5頁(yè),還剩2頁(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/*-【程序設(shè)計(jì)】-題目:設(shè)計(jì)并測(cè)試一個(gè)矩形類(Rectangle),屬性為矩形的左上與右下角的坐標(biāo),矩形水平放置。操作為計(jì)算矩形周長(zhǎng)與面積。輸出如下:left-top point is (100,200)right-bottom point is (300,400)面積40000 周長(zhǎng)800-*/#include #include using namespace std;/*Program*/class Rectangle double left, top ;double right, bottom;public:Rectangle(double l=0, double t=0, double r=0, double b=0); Rectangle(); /析構(gòu)函數(shù),在此函數(shù)體為空void Assign(double l,double t,double r,double b);double getLeft() return left; / 以下四個(gè)函數(shù)皆為內(nèi)聯(lián)成員函數(shù)double getRight() return right;double getTop()return top;double getBottom()return bottom;void Show();double Area();double Perimeter();/ 構(gòu)造函數(shù),帶缺省參數(shù),缺省值為全0,在聲明中指定Rectangle:Rectangle(double l , double t, double r, double b) left = l; top = t;right = r; bottom = b; void Rectangle:Assign(double l, double t, double r, double b)/賦值left = l; top = t;right = r; bottom = b;void Rectangle:Show()/成員函數(shù)直接使用私有的數(shù)據(jù)成員coutleft-top point is (left,top)n;coutright-bottom point is (right,bottom)n;double Rectangle:Area()return fabs(right-left)*(bottom-top);double Rectangle:Perimeter()return 2*(fabs(right-left)+fabs(bottom-top);/* End */int main() Rectangle rect; rect.Show(); rect.Assign(100,200,300,400); rect.Show(); Rectangle rect1(0,0,200,200); rect1.Show(); Rectangle rect2(rect1); rect2.Show(); coutleft-top point is (rect.getLeft(),rect.getTop()n; coutright-bottom point is (rect.getRight(),rect.getBottom()n; cout面積rect.Area()t周長(zhǎng)rect.Perimeter()endl; return 0;2/*-【程序設(shè)計(jì)】-題目:補(bǔ)充構(gòu)造一個(gè)日期時(shí)間類(Timedate),數(shù)據(jù)成員包括年、月、日和時(shí)、分、秒,函數(shù)成員包括設(shè)置日期時(shí)間和輸出時(shí)間,其中年、月請(qǐng)用整型,并完成測(cè)試。注意:自己寫的代碼中不能有cout-*/#include #include using namespace std;/*Program*/class Timedateint year,month,date;int hh,mm,ss;public:Timedate(int=0,int =0,int =0);void putdate(int y,int m,int d);void puttime(int h,int m,int s);void list();Timedate:Timedate(int y,int m,int d)year=y;month=m;date=d;hh=0;mm=0;ss=0;void Timedate:putdate(int y,int m,int d)year=y;month=m;date=d;void Timedate:puttime(int h,int m,int s)hh=h;mm=m;ss=s;/* End */void Timedate:list()/成員函數(shù),直接訪問(wèn)私有的數(shù)據(jù)成員 coutyear/month/date :; switch(year) case 2000:cout2000;break; case 2001:cout2001;break; case 2002:cout2002;break; case 2003:cout2003;break; case 2004:cout2004;break; case 2005:cout2005;break; switch(month) case 1:cout/Jan;break; case 2:cout/Feb;break; case 3:cout/Mar;break; case 4:cout/Apr;break; case 5:cout/May;break; case 6:cout/Jun;break; case 7:cout/Jul;break; case 8:cout/Aug;break; case 9:cout/Sep;break; case 10:cout/Oct;break; case 11:cout/Nov;break; case 12:cout/Dec;break; cout/dateendl; couthour:minite:second :; couthh:mm:ssendl;int main() Timedate A(2004,3,3),B; A.list(); B.list(); B.putdate(2005,10,18); B.puttime(17,30,00); B.list(); return 0;3/*-【程序設(shè)計(jì)】-題目:定義一個(gè)圓類(Circle),屬性為半徑(radius)、圓周長(zhǎng)和面積,操作為輸入半徑并計(jì)算周長(zhǎng)、面積,輸出半徑、周長(zhǎng)和面積。要求定義構(gòu)造函數(shù)(以半徑為參數(shù),缺省值為0,周長(zhǎng)和面積在構(gòu)造函數(shù)中生成)和拷貝構(gòu)造函數(shù)。注意:類中不能有cout-*/#include#includeusing namespace std;const double PI=3.14159265;/*Program*/class Circleprivate:double r,Area,Circumference;public:Circle(double a=0);Circle(Circle &);void SetR(double R); double GetR()return r; double GetAreaCircle()return Area;double GetCircumference()return Circumference;Circle:Circle(double a)r=a;Area=PI*r*r;Circumference=2*PI*r;Circle:Circle(Circle &cl)r=cl.r;Area=cl.Area;Circumference=cl.Circumference;void Circle:SetR(double R)r=R;Area=PI*r*r;Circumference=2*PI*r;4/*-【程序設(shè)計(jì)】-題目:設(shè)計(jì)一個(gè)學(xué)校在冊(cè)人員類(Person)。數(shù)據(jù)成員包括:身份證號(hào)(IdPerson),姓名(Name),性別(Sex),生日(Birthday)和家庭住址(HomeAddress)。成員函數(shù)包括人員信息的錄入和顯示。還包括構(gòu)造函數(shù)與拷貝構(gòu)造函數(shù)。設(shè)計(jì)一個(gè)合適的初始值。-*/#include#includeusing namespace std;class Person char IdPerson19; /身份證號(hào),18位數(shù)字 char Name20; /姓名 char Sex; /性別 int Birthday; /生日,格式1986年8月18日寫作19860818 char HomeAddress50; /家庭地址public: Person(char *,char *,char,int,char *); Person(Person &); Person(); Person(); void PrintPersonInfo(); void inputPerson(); /其他接口函數(shù);/*Program*/Person:Person(char *id,char *name,char sex,int birthday,char *homeadd)cout構(gòu)造Personendl;strcpy(IdPerson,id);strcpy(Name,name);Sex=sex;Birthday=birthday;strcpy(HomeAddress,homeadd);Person:Person()cout缺省構(gòu)造Personendl;IdPerson0=0;Name0=0;Sex=0;Birthday=0;HomeAddress0=0;Person:Person(Person & Ps)cout拷貝構(gòu)造Personendl;strcpy(IdPerson,Ps.IdPerson);strcpy(Name,Ps.Name);Sex=Ps.Sex;Birthday=Ps.Birthday;strcpy(HomeAddress,Ps.HomeAddress);Person:Person()cout析構(gòu)Personendl;/* End */void Person:inputPerson() cout請(qǐng)輸入身份證號(hào),18位數(shù)字:endl; cin.getline(IdPerson,19); cout請(qǐng)輸入姓名:endl; cin.getline(Name,20); cout請(qǐng)輸入性別m或w:Sex; cout請(qǐng)輸入生日,格式1986年8月18日寫作19860818:Birthday; cin.get(); /吸收回車符,否則地址輸不進(jìn)去 cout請(qǐng)輸入地址:endl; cin.getline(HomeAddress,50);void Person:PrintPersonInfo() int i; cout身份證號(hào):IdPersonn姓名:Namen性別:; if(Sex=m |Sex=M)cout男n; else if(Sex=w |Sex=M)cout女n; else cout n; cout出生年月日:; i=Bir
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 國(guó)慶節(jié)聯(lián)誼活動(dòng)方案
- 現(xiàn)代經(jīng)濟(jì)環(huán)境下的市場(chǎng)動(dòng)態(tài)與趨勢(shì)分析
- 弱電施工方案范本
- 1 有余數(shù)的除法 第二課時(shí)(說(shuō)課稿)-2023-2024學(xué)年二年級(jí)下冊(cè)數(shù)學(xué)蘇教版
- 2023三年級(jí)英語(yǔ)下冊(cè) Unit 1 My Body第1課時(shí)說(shuō)課稿 陜旅版(三起)
- 6 有多少浪費(fèi)本可避免 第一課時(shí) 說(shuō)課稿-2023-2024學(xué)年道德與法治四年級(jí)下冊(cè)統(tǒng)編版001
- 2024年八年級(jí)物理下冊(cè) 12.1杠桿說(shuō)課稿 (新版)新人教版001
- 《14學(xué)習(xí)有方法》(說(shuō)課稿)-部編版(五四制)道德與法治二年級(jí)下冊(cè)
- 2023九年級(jí)語(yǔ)文下冊(cè) 第三單元 11 送東陽(yáng)馬生序說(shuō)課稿 新人教版001
- Unit8 We're twins(說(shuō)課稿)-2023-2024學(xué)年譯林版(三起)英語(yǔ)三年級(jí)下冊(cè)
- 長(zhǎng)江委水文局2025年校園招聘17人歷年高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2025年湖南韶山干部學(xué)院公開(kāi)招聘15人歷年高頻重點(diǎn)提升(共500題)附帶答案詳解
- 廣東省廣州市番禺區(qū)2023-2024學(xué)年七年級(jí)上學(xué)期期末數(shù)學(xué)試題
- JGJ46-2024 建筑與市政工程施工現(xiàn)場(chǎng)臨時(shí)用電安全技術(shù)標(biāo)準(zhǔn)
- 家譜、宗譜頒譜慶典講話
- 2023年版勞動(dòng)實(shí)踐河北科學(xué)技術(shù)出版社一年級(jí)下冊(cè)全冊(cè)教案
- 方案報(bào)審表(樣表)
- pp顧問(wèn)的常見(jiàn)面試問(wèn)題
- 法理學(xué)原理與案例完整版教學(xué)課件全套ppt教程
- 隧道仰拱施工之仰拱棧橋結(jié)構(gòu)計(jì)算書
- 軟體家具、沙發(fā)質(zhì)量檢驗(yàn)及工藝
評(píng)論
0/150
提交評(píng)論