欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-04-04 10:59:31
1 #include 2 #include 3 4 using namespace std; 5 6 class Point 7 { 8 private: 9 int x,y; 10 public: 11 Point(int,int); 12 void Se ......
 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 }