-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultimophism.cpp
More file actions
105 lines (99 loc) · 2.26 KB
/
multimophism.cpp
File metadata and controls
105 lines (99 loc) · 2.26 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <bits/stdc++.h>
using namespace std;
class Point
{
public:
Point(float a=0,float b=0):x(a),y(b){}
void setPoint(float,float);
float getX() const{return x;}
float getY() const{return y;}
friend ostream & operator <<(ostream &,const Point &);
protected:
float x;
float y;
};
void Point::setPoint(float a,float b)
{
x=a;y=b;
}
ostream & operator <<(ostream &output,const Point &p)
{
output<<"["<<p.x<<","<<p.y<<"]"<<endl;
return output;
}
class Circle:public Point
{
public:
Circle(float a=0,float b=0,float r=0):Point(a,b),radius(r){};
void setRadius(float);
float getRadius() const;
float area() const;
friend ostream &operator<<(ostream &,const Circle &);
protected:
float radius;
};
void Circle::setRadius(float r)
{
radius=r;
}
float Circle::getRadius() const
{
return radius;
}
float Circle::area() const
{
return 3.14159*radius*radius;
}
ostream &operator<<(ostream &output,const Circle &c)
{
output<<"Center=["<<c.x<<","<<c.y<<"]"<<"Radius="<<c.radius<<" area="<<c.area()<<endl;
return output;
}
class Cylinder:public Circle
{
public:
Cylinder(float a=0,float b=0,float r=0,float h=0):Circle(a,b,r),height(h){}
void setHeight(float);
float getHeight() const;
float area() const;
float volume() const;
friend ostream & operator <<(ostream&,const Cylinder&);
protected:
float height;
};
void Cylinder::setHeight(float h)
{
height=h;
}
float Cylinder::getHeight() const
{
return height;
}
float Cylinder::area() const
{
return 2*Circle::area()+2*3.14159*radius*height;
}
float Cylinder::volume() const
{
return Circle::area()*height;
}
ostream &operator <<(ostream &output,Cylinder &c)
{
output<<"Center=["<<c.getX()<<","<<c.getY()<<"],r="<<c.getRadius()<<",h="<<c.getHeight()<<endl<<"area="<<c.area()<<",volume="<<c.volume()<<endl;
return output;
}
int main()
{
Cylinder c(3.5,6.4,5.2,10);
cout<<"The orginal Cylinder:\n"<<c<<endl;
c.setHeight(15);
c.setRadius(7.5);
c.setPoint(5,5);
cout<<"New Cylinder:"<<endl;
cout<<c;
Point pRef=c;
cout<<"pRef:"<<pRef<<endl;
Circle cRef=c;
cout<<"cRef:"<<cRef<<endl;
return 0;
}