日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[YTU]_2918( Shape系列-4)

發布時間:2025/4/16 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [YTU]_2918( Shape系列-4) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Description

小聰送給小亮和小華的形狀他們都很喜歡,小亮和小華非要比一下他們兩個的形狀,來看看小聰更愛誰,請完成RsubC類。RsubC類中包括Rectangle類和Circle類的數據成員,新增布爾類型的數據成員sign(sign等于0時,新面積等于Rectangle+Circle,sign等于1時,新面積等于Rectangle-Circle,新定義了求面積的成員函數area()。但是小聰沒有為RsubC類寫構造函數和成員函數,請幫助小聰完成RsubC類。

小強寫的文件頭和Shape類

#include<iostream>#define PI 3.14using namespace std; class Shape{public: Shape();Shape(int c);int getcolor();double area();protected:int color;};Shape::Shape(){color=0;}Shape::Shape(int c){color=c;}int Shape::getcolor(){return color;}double Shape::area(){return 10000;}

小聰寫的Rectangle類class Rectangle:public Shape{public:Rectangle(int c,double w,double h);double getwidth();double getheight();double area();double price();protected:double height;double width;};Rectangle::Rectangle(int c,double w,double h):Shape(c){width=w;height=h;}double Rectangle::getwidth(){return width;}double Rectangle::getheight(){return height;}double Rectangle::area(){return height*width;}double Rectangle::price(){return height*width*color;}

小聰寫的Circle類

class Circle:public Shape{public:Circle(int c,double r);double getradius();double area();double price();protected:double radius;};

Circle::Circle(int c,double r):Shape(c){radius=r;}double Circle::getradius(){return radius;}

double Circle::area(){return PI*radius*radius;}double Circle::price(){return PI*radius*radius*color;}

小聰的測試函數:

int main()

{

RsubC rc=RsubC(1,2,3,1,1);cout<<"RsubC area:"<<rc.area()<<endl;return 0;

}

提示:不用提交全部程序,只提交補充部分。

Input

Output

輸出小聰測試的RsubC的面積。

Sample Output

RsubC area:2.86#include<iostream>#define PI 3.14using namespace std;class Shape{public: Shape(); Shape(int c); int getcolor(); double area();protected: int color;};Shape::Shape(){ color=0;}Shape::Shape(int c){ color=c;}int Shape::getcolor(){ return color;}doubleShape::area(){ return 10000;} class Rectangle:public Shape{public: Rectangle(int c,double w,double h); double getwidth(); double getheight(); double area(); double price();protected: double height; double width;};Rectangle::Rectangle(int c,double w,doubleh):Shape(c){ width=w; height=h;}double Rectangle::getwidth(){ return width;}double Rectangle::getheight(){ return height;}double Rectangle::area(){ return height*width;}double Rectangle::price(){ return height*width*color;} class Circle:public Shape{public:Circle(int c,double r); double getradius(); double area(); double price();protected: double radius;}; Circle::Circle(int c,double r):Shape(c){ radius=r;}double Circle::getradius(){ return radius;} double Circle::area(){ return PI*radius*radius;}double Circle::price(){return PI*radius*radius*color;}class RsubC:public Rectangle,public Circle{public: RsubC(int c,double w,double h,double r,bool s):Rectangle(c,w,h),Circle(c,r),sign(s){} float area();private: bool sign;};float RsubC::area(){ if(sign==1) return Rectangle::area()-Circle::area();if(sign==1) return Rectangle::area()+Circle::area();}int main(){ RsubC rc=RsubC(1,2,3,1,1);cout<<"RsubC area:"<<rc.area()<<endl;return 0; }

總結

以上是生活随笔為你收集整理的[YTU]_2918( Shape系列-4)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。