当前位置: 移动技术网 > IT编程>开发语言>C/C++ > 从Point类继承的Circle类 代码参考

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

2020年04月22日  | 移动技术网IT编程  | 我要评论

心学四训,飞虎神鹰迅雷下载,诛仙天书奇谭之天仙子

 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 }

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网