设计并测试一个椭圆类 代码参考
程序员文章站
2022-03-25 16:58:20
1 #include 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 p ......
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 }