# 喜刷刷4——shape类—4（完成RsubC类）

#include<iostream>
#define PI 3.14
using 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;
}

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;
}

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;

}

#include<iostream>
#define PI 3.14
using 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;
}
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;
}

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 Shape
{
public:
RsubC(int c,double w,double h,double r,bool s);
double area();
private:
Rectangle rectangle;
Circle circle;
bool sign;
};
RsubC::RsubC(int c,double w,double h,double r,bool s):Shape(c),rectangle(c,w,h),circle(c,r),sign(s){}
double RsubC::area()
{
if(sign==0)
return rectangle.area()+circle.area();
else
return rectangle.area()-circle.area();
}
int main()
{
RsubC rc=RsubC(1,2,3,1,1);
cout<<"RsubC area:"<<rc.area()<<endl;
return 0;

}


#### caffe源码 之　Blob类

2016-11-15 11:41:32

#### 7.30定义一个公共基类Shape,实现运行时的多态性

2014-08-29 18:46:48

#### 实验报告：定义一个名为MyRectangle的矩形类，完成如下要求

2018-06-03 09:00:52

#### 5.1（接口）1）定义shape接口,包含求面积和求周长的方法；2）定义Circle类、Rectangle类、Square类；

2017-04-03 16:55:45

#### 6.根据主类，设计类Shape, Rectangle和Circle。

2015-07-21 16:32:20

#### Spring+SpringMVC+Mybatis（SSM）框架搭建教程（四）-应用功能开发实例

2018-02-28 08:31:07

#### 飛飛（四十七）定义抽象基类Shape，由它派生出3个派生类，Circle（圆形）、Rectangle（矩形）、Triangle（三角形）。用如下的main()函数，求出定义的几个几何体的面积和。

2016-05-25 13:29:21

#### Shape是一个几何图形的基类，它至少有求自身周长函数Circumference()和求自身面积函数Area()。从Shape类派生出Circle类、Ellipse类、Triangle类和Rectan

2012-05-13 15:48:19

#### 第10周-Person类

2015-11-03 20:18:22

#### 4.1（抽象类）1）定义shape抽象类，包含求面积和求周长的方法；2）定义Circle类和Rectangle类继承shape类；3）定义Square类继承Rectangle类；4）运行时，让用户

2017-04-02 23:14:45