-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path167.cpp
41 lines (41 loc) · 841 Bytes
/
167.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
using namespace std;
class Shape{
public:
Shape(){}
~Shape(){}
virtual double GetArea()=0;
virtual double GetPerimeter()=0;
static Shape* createRectangle(double length,double width);
static Shape* createCircle(double radius);
};
class Rectangle:public Shape{
public:
Rectangle(double ll,double ww){
l=ll,w=ww;
}
double GetArea(){
return l*w;
}
double GetPerimeter(){
return (l+w)*2.0;
}
private:
double l,w;
};
class Circle:public Shape{
public:
Circle(double ll){
r=ll;
}
double GetArea(){
return 3.14*r*r;
}
double GetPerimeter(){
return 6.28*r;
}
private:
double r;
};
Shape * Shape::createRectangle(double l,double w){return new Rectangle(l,w);}
Shape * Shape::createCircle(double r){return new Circle(r);}