如何編寫程式,實現由定義抽象基類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派生出的類將根據派生類的具體特徵,使用常規虛擬函式來實現這種介面。

編寫程式自定義的遞迴函式long power int m,i

無語的店鋪 2010 12 2 09 09 提供答案有錯誤我將其修改如下 include long power int m,int n void main 另一解法 include long power int m,int n return y int main 這兩個辦法都可以解決這一個問題 遞迴...

急求幫助,matlab編寫程式起泡法對數由小到大排序

隱匿望默唸 步驟如下 clcclear all s 9 8 4 2 7 10 6 1 5 3 要排序的數列ls length s for i 1 ls 1 for j 1 ls i if s j s j 1 t s j s j s j 1 s j 1 t endend ends 輸出排序後結果 拓展...

編寫程式,實現輸出3到1000之間的所有素數。用冒泡法對整數進行排序 從小到大要求 這

先佔位.哈哈.等等.1.include include include include conio.h void main void if prime printf d num 2.include void main int i,j int tmp printf please 10 int numb...