设计并测试一个椭圆类 代码参考

0
6
 1 #include <iostream>
 2 
 3 using namespace std;
 4 const double PI=3.14;
 5 
 6 class Ellipse
 7 {
 8     private:
 9         int x,y;
10         double a,b;
11         double area;
12     public:
13         Ellipse(int,int,double,double);
14         double Area();
15 };
16 
17 Ellipse::Ellipse(int x, int y, double a, double b)
18 {
19     this->x=x;
20     this->y=y;
21     this->a=a;
22     this->b=b;
23 }
24 
25 double Ellipse::Area()
26 {
27     return PI*a*b;
28 }
29 
30 int main()
31 {
32     int x,y;
33     double a,b;
34     cin>>x>>y>>a>>b;
35     Ellipse one(x,y,a,b);
36     cout<<one.Area()<<endl;
37     return 0;
38 }

<

发布回复

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