




已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1/*-【程序設(shè)計(jì)】-題目:設(shè)計(jì)并測試一個(gè)矩形類(Rectangle),屬性為矩形的左上與右下角的坐標(biāo),矩形水平放置。操作為計(jì)算矩形周長與面積。輸出如下:left-top point is (100,200)right-bottom point is (300,400)面積40000 周長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周長rect.Perimeter()endl; return 0;2/*-【程序設(shè)計(jì)】-題目:補(bǔ)充構(gòu)造一個(gè)日期時(shí)間類(Timedate),數(shù)據(jù)成員包括年、月、日和時(shí)、分、秒,函數(shù)成員包括設(shè)置日期時(shí)間和輸出時(shí)間,其中年、月請用整型,并完成測試。注意:自己寫的代碼中不能有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ù),直接訪問私有的數(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)、圓周長和面積,操作為輸入半徑并計(jì)算周長、面積,輸出半徑、周長和面積。要求定義構(gòu)造函數(shù)(以半徑為參數(shù),缺省值為0,周長和面積在構(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é)校在冊人員類(Person)。數(shù)據(jù)成員包括:身份證號(IdPerson),姓名(Name),性別(Sex),生日(Birthday)和家庭住址(HomeAddress)。成員函數(shù)包括人員信息的錄入和顯示。還包括構(gòu)造函數(shù)與拷貝構(gòu)造函數(shù)。設(shè)計(jì)一個(gè)合適的初始值。-*/#include#includeusing namespace std;class Person char IdPerson19; /身份證號,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請輸入身份證號,18位數(shù)字:endl; cin.getline(IdPerson,19); cout請輸入姓名:endl; cin.getline(Name,20); cout請輸入性別m或w:Sex; cout請輸入生日,格式1986年8月18日寫作19860818:Birthday; cin.get(); /吸收回車符,否則地址輸不進(jìn)去 cout請輸入地址:endl; cin.getline(HomeAddress,50);void Person:PrintPersonInfo() int i; cout身份證號:IdPersonn姓名:Namen性別:; if(Sex=m |Sex=M)cout男n; else if(Sex=w |Sex=M)cout女n; else cout n; cout出生年月日:; i=Bir
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030年中國非標(biāo)壓力容器行業(yè)發(fā)展?fàn)顩r及營銷戰(zhàn)略研究報(bào)告
- 2025-2030年中國表演服市場創(chuàng)新前景分析及投資預(yù)測報(bào)告
- 2025-2030年中國薺藍(lán)油市場競爭格局規(guī)劃研究報(bào)告
- 2025-2030年中國自助回單打印終端市場發(fā)展?fàn)顩r及營銷戰(zhàn)略研究報(bào)告
- 2025-2030年中國羽毛(絨)加工業(yè)市場規(guī)模分析及發(fā)展建議研究報(bào)告
- 2025-2030年中國粉末冶金模產(chǎn)業(yè)運(yùn)行狀況及發(fā)展趨勢預(yù)測報(bào)告
- 2025-2030年中國空氣凈化系統(tǒng)工程行業(yè)發(fā)展規(guī)模規(guī)劃研究報(bào)告
- 2025-2030年中國電腦機(jī)箱市場現(xiàn)狀分析規(guī)劃研究報(bào)告
- 株洲師范高等??茖W(xué)?!盾囕v動(dòng)力學(xué)與強(qiáng)度》2023-2024學(xué)年第二學(xué)期期末試卷
- 重慶青年職業(yè)技術(shù)學(xué)院《電力電子技術(shù)及應(yīng)用課程設(shè)計(jì)》2023-2024學(xué)年第二學(xué)期期末試卷
- 法規(guī)解讀丨2024新版《突發(fā)事件應(yīng)對法》及其應(yīng)用案例
- JGJ46-2024 建筑與市政工程施工現(xiàn)場臨時(shí)用電安全技術(shù)標(biāo)準(zhǔn)
- 2024年世界職業(yè)院校技能大賽高職組“關(guān)務(wù)實(shí)務(wù)組”賽項(xiàng)參考試題庫(含答案)
- 河北美術(shù)出版社小學(xué)六年級下冊書法練習(xí)指導(dǎo)教案
- 電鍍廢水中各種重金屬廢水處理反應(yīng)原理及控制條件
- 數(shù)據(jù)結(jié)構(gòu)英文教學(xué)課件:chapter3 Linked Lists
- 《汽車文化》全套教案
- 會(huì)計(jì)英語專業(yè)詞匯全
- 拆除工程檢驗(yàn)批質(zhì)量檢驗(yàn)記錄
- 怎樣把握文章線索
- LED與金鹵燈對比(共4頁)
評論
0/150
提交評論