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

0
15
 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 }

<

发布回复

请输入评论!
请输入你的名字