c++與數(shù)據(jù)結(jié)構(gòu) 哈理工 編寫程序_第1頁
c++與數(shù)據(jù)結(jié)構(gòu) 哈理工 編寫程序_第2頁
c++與數(shù)據(jù)結(jié)構(gòu) 哈理工 編寫程序_第3頁
c++與數(shù)據(jù)結(jié)構(gòu) 哈理工 編寫程序_第4頁
免費(fèi)預(yù)覽已結(jié)束,剩余1頁可下載查看

下載本文檔

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

文檔簡(jiǎn)介

1、c+與數(shù)據(jù)結(jié)構(gòu) 哈理工 編寫程序c+與數(shù)據(jù)結(jié)構(gòu) 哈理工 編寫程序c+與數(shù)據(jù)結(jié)構(gòu) 哈理工 編寫程序V:1.0精細(xì)整理,僅供參考 c+與數(shù)據(jù)結(jié)構(gòu) 哈理工 編寫程序日期:20 xx年X月編寫程序擴(kuò)充日期類Date的定義,增加一個(gè)成員函數(shù)NumberOfDays(),計(jì)算當(dāng)前對(duì)象中的日期是其年份的第幾天,并編寫一個(gè)主函數(shù)用來測(cè)試這個(gè)成員函數(shù)。#include class Date public: void SetDate(int y=2006,int m=1,int d=1) year=y; month=m0&m13m:1; day=d; int IsLeap_Year() if(year%400=0

2、)|(year%4=0&year%100!=0)return 1; return 0; int GetYear() return year; int Getmonth() return month; int GetDay() return day; void Print() coutyear.month.dayendl; int NumberOfDays() int days=31,28,31,30,31,30,31,31,30,31,30,31; int days_leap=31,29,31,30,31,30,31,31,30,31,30,31; int SumDays=day; if(Is

3、Leap_Year()=1) for(int i=0;imonth-1;i+)SumDays=SumDays+days_leapi; else for(int i=0;iSetDate(2008,11,28); date-Print(); coutIt is the NumberOfDays()th day of the year.endl;定義一個(gè)名為Integer的證書類,具有數(shù)據(jù)成員d和以下成員函數(shù),成員函數(shù)包括GetD()獲取d的值,SetD(int)設(shè)置d的值,IsOdd()判斷d是否為一個(gè)偶數(shù),IsPrime()判斷d是否為一個(gè)素?cái)?shù),并涉及主函數(shù)用一個(gè)對(duì)象分別設(shè)置d的值為15和31

4、,編寫一個(gè)主函數(shù)測(cè)試這個(gè)類。#include class Integerint d; 計(jì)一個(gè)father類,一個(gè)mother類和一個(gè)child類。其中child類繼承father類和mother類。Father類和mother類都包含星河明兩個(gè)數(shù)據(jù)成員。Child類僅包含名數(shù)據(jù)成員。要求一個(gè)child類的對(duì)象能夠輸出父母和自己的姓名#includeclass fatherchar a100;public:father()cout輸入父親姓名:a;void outputName()cout父親姓名:aendl;class motherchar b100;public:mother()cout輸入

5、母親姓名:b;void outputName()cout母親姓名:bendl;class child:public father,public motherchar c100;public:child()cout輸入孩子姓名:c;void outputName() father:outputName(); mother:outputName();cout孩子姓名:cendl;void main()child d1;();用虛函數(shù)和抽象類的概念設(shè)計(jì)求正方體,圓柱體和球體體積的程序#include const double PI=3.;class circle public: circle(dou

6、ble r) radius = r; virtual double area() return ; virtual double volume() return ; protected: double radius;class sphere:public circle public: sphere( double r ):circle( r ) double area() return * PI * radius * radius; double volume() return * PI * radius * radius * radius / ; ;class column:public c

7、ircle public: column( double r,double h ):circle( r ) height = h; double area() return * PI * radius * ( height + radius ); double volume() return PI * radius * radius * height; private: double height;void main() circle *p; sphere sobj(2); p = &sobj; cout 球體: endl; cout 體積 = volume() endl; cout 表面積 = area() endl; column cobj( 3,5 ); p = &cobj; cout 圓柱體: endl; cout 體積

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(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ǔ)空間,僅對(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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論