




免費預(yù)覽已結(jié)束,剩余2頁可下載查看
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1/*-【程序設(shè)計】-題目:設(shè)計并測試一個矩形類(Rectangle),屬性為矩形的左上與右下角的坐標(biāo),矩形水平放置。操作為計算矩形周長與面積。輸出如下: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; / 以下四個函數(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è)計】-題目:補充構(gòu)造一個日期時間類(Timedate),數(shù)據(jù)成員包括年、月、日和時、分、秒,函數(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è)計】-題目:定義一個圓類(Circle),屬性為半徑(radius)、圓周長和面積,操作為輸入半徑并計算周長、面積,輸出半徑、周長和面積。要求定義構(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è)計】-題目:設(shè)計一個學(xué)校在冊人員類(Person)。數(shù)據(jù)成員包括:身份證號(IdPerson),姓名(Name),性別(Sex),生日(Birthday)和家庭住址(HomeAddress)。成員函數(shù)包括人員信息的錄入和顯示。還包括構(gòu)造函數(shù)與拷貝構(gòu)造函數(shù)。設(shè)計一個合適的初始值。-*/#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(); /吸收回車符,否則地址輸不進去 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)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 超市玩具購銷合同協(xié)議
- 購買協(xié)議和買賣合同
- 訂房協(xié)議換購房合同模板
- 讓路協(xié)議書范本
- 購買電吹風(fēng)合同協(xié)議
- 購買加工產(chǎn)品合同協(xié)議
- b駕駛證試題及答案
- 新疆維吾爾自治區(qū)喀什地區(qū)巴楚縣2024-2025學(xué)年高二下學(xué)期4月期中地理試題(原卷版+解析版)
- 2025年跨境電商政策與實務(wù)考試試題及答案
- 2025年歷史文化研究生入學(xué)考試試題及答案
- 2025年安全生產(chǎn)考試題庫(消防安全應(yīng)急處置)消防設(shè)施運行維護試題
- 2025年臨海市紀(jì)委市監(jiān)委下屬事業(yè)單位公開選聘工作人員1人筆試備考題庫及答案解析
- 湖北武漢市華中師大一附中2025屆高三3月押軸試題物理試題試卷含解析
- 司法雇員考試題目及答案
- 國家金融監(jiān)督管理總局所屬事業(yè)單位招聘真題2024
- 2024年全國高中數(shù)學(xué)聯(lián)賽(浙江預(yù)賽)試題含參考答案
- 人教PEP版(2024)三年級下冊英語Unit5 Old toys單元整體教學(xué)設(shè)計(共6課時)
- 知識產(chǎn)權(quán)投資從理論到實踐的轉(zhuǎn)化
- 《2025年公路工程集料試驗規(guī)程》知識培訓(xùn)
- 客戶生命周期價值預(yù)測-第1篇-深度研究
- 文化轉(zhuǎn)型時代的文化基因與共生教育選擇
評論
0/150
提交評論