include iostream using namespace std const float 14159265 class Figure

 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
using namespace std;
const float P = 3.14159265;
class Figure {
public:
virtual double area() = 0;
virtual double perim() = 0;
};
class Rectangle{
protected:
int w , h;
public:
void read(){
cin >> w >> h ;
}
virtual double area(){
return h*w;
}
virtual double perim(){
return 2*(h+w);
}
};
class Circle {
protected:
int r;
public:
void read(){
cin >> r;
}
virtual double area(){
return P*r*r;
}
virtual double perim(){
return 2*P*r;
}
};
int main(){
int a ;
cin >> a;
Figure** arr = new Figure*[a];
char name[10];
for(int i = 0; i<a ; i++){
cin >> name ;
if( name[0] == 'C'){
arr[i] = new Circle();
arr[i]->read();
}
}
x.read();
cout << x.area() <<" "<< x.perim();
return 0;
}