10 3 繼承與派生之圓柱體

2021-06-06 01:29:31 字數 2011 閱讀 4768

* 程式的版權和版本宣告部分

* 檔名稱:

* 作 者: 張傳新

* 完成日期: 2012 年 4 月 23 日

* 版 本 號: 1.0

* 對任務及求解方法的描述部分

* 輸入描述:

* 問題描述:

* 程式輸出: ......

* 程式頭部的注釋結束 */

#include#include#include#define pi 3.141592653   

using namespace std;

class point //定義座標點類

point(double x0,double y0)

~point(){}

double getx()

double gety()

friend ostream &operator << (ostream & output, point & c);

protected:

double x, y; //點的橫座標和縱座標

};

//輸出點的座標資訊

ostream &operator << (ostream & out, point & c)

class circle: public point //定義圓類

circle(double x0, double y0, double r); //建構函式

~circle(){};

double getr()

friend ostream &operator << (ostream & out, circle & c);

protected:

double r;

};

circle::circle(double x0, double y0, double r):point(x0, y0),r(r){}

//輸出圓的資訊

ostream &operator << (ostream & out, circle & c)

class cylinder: public circle

cylinder(double x1,double y1, double r1, double h);

~cylinder(){}

double geth()

double area();

double volume();

friend ostream &operator << (ostream & out, cylinder & c);

private:

double height;

};

cylinder::cylinder(double x1,double y1, double r1, double h):circle(x1, y1, r1), height(h){}

//計算圓柱體的面積

double cylinder::area()

//計算圓柱體的體積

double cylinder::volume()

//輸出圓柱體的資訊

ostream &operator << (ostream & out, cylinder & c)

int main()

{ point po(3,4);

circle ci(3,4,5);

cylinder cy(3, 4, 5, 6);

cout << po << endl;

cout << ci <

執行結果:

點座標為:(3,4)

所建圓的圓心為:(3,4), 半徑為:5

圓心為:(3,4), 半徑為:5, 高為:6的圓柱體

表面積是:267.04

體積是:471.24

請按任意鍵繼續. . .

感言:不容易啊。。。。

學習OpenGL ES之繪製圓柱體

為了更方便的進行頂點資料的管理,我建立了乙個glgeometry類。typedef enum nsuinteger glgeometrytype typedef struct glvertex inte ce glgeometry property strong,nonatomic nsmutabl...

利用繼承,實現圓柱體體積的計算

根據下圖實現類。在testcylinder類中建立cylinder類的物件,設定圓柱的底面半徑和高,並輸出圓柱的體積。circle 圓 radius double circle 構造方法,將radius屬性初始化為1 setradius double radius void getradius do...

YTU 2621 B 繼承 圓到圓柱體

定義了circle圓形類,在此基礎上派生出cylinder圓柱體類。circle圓形類定義如下 class circle double area 圓面積 protected double radius 圓半徑 請在下面的程式段基礎上完成整個設計。在主程式中輸出指定半徑的圓的面積 area 輸出指定圓...