如何編寫程式,實現由定義抽象基類Shape(形狀)派生出

時間 2021-09-17 08:22:56

1樓:

不曉得你顯示所有圖形的總面積的函式放在**?

const double pi = 3.14;

class shape

;class circle:public shapedouble showarea()

};class rectangle:public shapedouble showarea()

};class square:public shapedouble showarea()

};void main()

;for(int i=0; i<3; i++)}

2樓:愛笑的暖言兒

定義抽象基類shape,由它派生出3個派生類: circle(圓形)、rectangle(矩形)、********(三角形),用一個函式printarea分別輸出以上三者的面積,3個圖形的資料在定義物件時給定。

#includeusing namespace std;  class shape  ;    };  class circle:public shape

protected:  float radius; };  circle::circle(float r):

radius(r)    class rectangle:public shape  ;

rectangle::rectangle(float w,float h):width(w),height(h)

float rectangle::printarea()const

class ********:public shape  {   public:  ********(float =0,float =0);

virtual float printarea() const;  protected:  float height;  float width;

抽象類(abstract base class,abc)就是類裡定義了純虛成員函式的類。純虛擬函式 只提供了介面,並沒有具體實現。抽象類不能被例項化(不能建立物件),通常是作為基類供子類繼承,子類中重寫虛擬函式,實現具體的介面。

簡言之,abc描述的是至少使用一個純虛擬函式的介面,從abc派生出的類將根據派生類的具體特徵,使用常規虛擬函式來實現這種介面。

vb 編寫編寫程式,輸出由1,2,3,4,5,6這數字組

dim a dim temp as string dim n as integer dim i,j,k,t,y,u as integera split 1,2,3,4,5,6 temp n ubound a dim cou as integer 0if trim a ubound a then n ...

編寫程式實現從鍵盤上任意輸入正整數,找出其中的素數

include include void main for j 0 j printf 按從小到大順序排列為 d n ptr j free ptr includevoid main i,j,flag,k 0,temp,n printf 請輸入正整數的個數 scanf d n printf 請輸入 d個...

如何在android下用c 進行編寫程式

臺綺雲 在電腦上可以安裝eclipse,只需裝載cdt元件就可進行c程式程式設計 codeblocks 如果是想在安卓手機上進行c程式設計的話, 平臺不一樣,語言也不一樣,android語法也差不多,想好演算法用android編寫一樣的 如何在 android 系統中用 c 語言編寫程式並執行 創作...