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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[YTU]_2919( Shape系列-5)

發(fā)布時(shí)間:2025/4/16 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [YTU]_2919( Shape系列-5) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Description

JC和Kitty聽說小亮和小華有了Rectangle和Circle并用RsubC類比較了大小,于是想借小亮和小華的Rectangle和Circle來仿制自己的形狀,于是JC和Kitty完成了自己的rectangle類和circle類,他們兩個(gè)也要比較一下形狀大小。但是JC和Kitty沒有為RsubC1類(其中的布爾類型sign等于0時(shí),新面積等于Rectangle+Circle,sign等于1時(shí),新面積等于Rectangle-Circle寫構(gòu)造函數(shù)與area面積函數(shù),請幫助JC和Kitty完成RsubC1類。

//小強(qiáng)寫的文件頭和各種類

#include<iostream>
using namespace std;
#define pi 3.14
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 1000;
}
class Rectangle:public Shape
{
public:
?Rectangle();
?Rectangle(int c, double w,double h);
?double getwidth();
?double getheight();
?double area();
?double price();
protected:
?double width,height;
};
Rectangle::Rectangle()
{
?width=10;height=5;
}
Rectangle::Rectangle(int c, double w,double h):Shape(c)
{
?width=w;
?height=h;
}
double Rectangle::getwidth()
{
?return width;
}

double Rectangle::area()
{
?return width*height;
}
double Rectangle::getheight()
{
?return height;
}

double Rectangle::price()
{
?return color*width*height;
}
class Circle:public Shape
{
public:
?Circle();
?Circle(int c,double r);
?double getradius()
?{
??return radius;
?}
?double area();
protected:
?double radius;
};
Circle::Circle()
{
?radius=10;
}
Circle::Circle(int c,double r):Shape(c)
{
?radius=r;
}
double Circle::area()
{
?return radius*radius*pi;
}

// RsubC1類

class RsubC1:public Shape
{
public:
?RsubC1(int c,double w,double h,double r,bool s);
?double area();
private:
?Rectangle rectangle;
?Circle circle;
?bool sign;
};

//JC和Katy的測試函數(shù):


int main()
{
?RsubC1 rc1=RsubC1(3,2,3,1,1);
?
?RsubC1 rc2=RsubC1(1,2,1,2,0);

?cout<<"rc1 area="<<rc1.area()<<endl;
?
?cout<<"rc2 area="<<rc2.area()<<endl;

?return 0;
}

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


Input

Output

輸出JC和Katy測試的RsubC類的面積。

Sample Output

rc1 area=2.86rc2 area=14.56#include<iostream> using namespace std; #define pi 3.14 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 1000; } class Rectangle:public Shape { public:Rectangle();Rectangle(int c, double w,double h);double getwidth();double getheight();double area();double price(); protected:double width,height; }; Rectangle::Rectangle() {width=10;height=5; } Rectangle::Rectangle(int c, double w,double h):Shape(c) {width=w;height=h; } double Rectangle::getwidth() {return width; }double Rectangle::area() {return width*height; } double Rectangle::getheight() {return height; }double Rectangle::price() {return color*width*height; } class Circle:public Shape { public:Circle();Circle(int c,double r);double getradius(){return radius;}double area(); protected:double radius; }; Circle::Circle() {radius=10; } Circle::Circle(int c,double r):Shape(c) {radius=r; } double Circle::area() {return radius*radius*pi; }class RsubC1:public Shape { public:RsubC1(int c,double w,double h,double r,bool s);double area(); private:Rectangle rectangle;Circle circle;bool sign; };RsubC1::RsubC1(int c,double w,double h,double r,bool s):Shape(c),rectangle(c,w,h),circle(c,r),sign(s){} double RsubC1::area() {if(sign==1)return rectangle.area()-circle.area();if(sign==0)return rectangle.area()+circle.area(); } int main() { RsubC1 rc1=RsubC1(3,2,3,1,1);RsubC1 rc2=RsubC1(1,2,1,2,0);cout<<"rc1 area="<<rc1.area()<<endl; cout<<"rc2 area="<<rc2.area()<<endl; return 0; }

總結(jié)

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。