从Point类继承的Circle类 代码参考

2020-04-21 16:03:42来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

从Point类继承的Circle类 代码参考

 1 #include <iostream>
 2 #include <cstring>
 3 
 4 using namespace std;
 5 
 6 class Point
 7 {
 8     private:
 9         int x,y;
10     public:
11         Point(int,int);
12         void SetPoint(int,int);
13         int GetX(){return x;}
14         int GetY(){return y;}
15         void Print();
16 };
17 
18 class Circle:public Point
19 {
20     private:
21         double radius;
22     public:
23         Circle(int,int,double);
24         void SetRadius(double);
25         double GetRadius();
26         double Area();
27         void Print();
28 };
29 
30 void Point::SetPoint(int a, int b)
31 {
32     x=a;
33     y=b;
34 }
35 
36 Point::Point(int a, int b)
37 {
38     SetPoint(a,b);
39 }
40 
41 void Point::Print()
42 {
43     cout<<"["<<GetX()<<','<<GetY()<<"]"<<endl;
44     return;
45 }
46 
47 Circle::Circle(int a, int b, double r):Point(a,b)
48 {
49     radius=r;
50 }
51 
52 void Circle::SetRadius(double r)
53 {
54     radius=r;
55     return;
56 }
57 
58 double Circle::GetRadius()
59 {
60     return radius;
61 }
62 
63 double Circle::Area()
64 {
65     return 3.14*radius*radius;
66 }
67 
68 void Circle::Print()
69 {
70     cout<<"Circle c Center=";
71     Point::Print();
72     cout<<"Radius="<<radius<<endl;
73     cout<<"The centre of circle c ";
74     Point::Print();
75     cout<<"The area of circle c "<<Area()<<endl;
76     return;
77 }
78 
79 int main()
80 {
81     int x,y;
82     int a,b,r;
83     cin>>x>>y>>a>>b>>r;
84     Point one(x,y);
85     cout<<"Point p ";
86     one.Print();
87     Circle two(a,b,r);
88     two.Print();
89     return 0;
90 }

 


原文链接:https://www.cnblogs.com/Conan-jine/p/12747559.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:引用传参与reference_wrapper

下一篇:C++ 默认参数