zoukankan      html  css  js  c++  java
  • 椭圆类——1(类的设计)

    【问题描述】
    设计并测试一个名为Ellipse的椭圆类:
    (1)其私有数据成员为外切矩形的左上角与右下角两个点的坐标(4个int型x1,y1,x2,y2)
    (2)声明4个公有的成员函数分别访问椭圆的外切矩形的顶点坐标
    (3)设计1个构造函数Ellipse(int,int,int,int)对椭圆的外切矩形的顶点坐标赋值
    (4)设计1个公有成员函数Area()计算椭圆的面积。

    【输入形式】
    在主函数里输入顶点坐标,并声明一个Ellipse类的对象。

    【输出形式】
    在主函数里调用该对象的成员函数输出外切矩形的顶点坐标,计算并输出椭圆的面积。

    【样例输入】
    -3 1 3 -1

    【样例输出】
    -3 1 3 -1
    9.4245

    #include <iostream>
    #include <math.h>
    #include <iomanip>
    using namespace std;
    
    class Ellipse
    {
    private:
        int x1,y1,x2,y2;
    public:
        //构造函数
        Ellipse(int xx1,int yy1,int xx2,int yy2);
        //功能函数
        double Area();//计算椭圆面积
        int GetX1(){return x1;}
        int GetY1(){return y1;}
        int GetX2(){return x2;}
        int GetY2(){return y2;}
    };
    
    Ellipse::Ellipse(int xx1,int yy1,int xx2,int yy2)
    {
        x1 = xx1; y1 = yy1; x2 = xx2; y2 = yy2;
    }
    
    double Ellipse::Area()
    {
        return (double)( 3.1415 * fabs(x2-x1) * fabs(y2-y1) / 4 );
    }
    
    int main()
    {
        int x1,y1,x2,y2;
        cin >> x1 >> y1 >> x2 >> y2;
        Ellipse e(x1,y1,x2,y2);
        cout << e.GetX1() << " " << e.GetY1() << " " << e.GetX2() << " " << e.GetY2() << endl;
        cout << fixed << setprecision(4) << e.Area() << endl;
        return 0;
    }
    
  • 相关阅读:
    python cx_Oracle install
    import uno 错误
    webkit report
    window bzr launchpad 安装配置
    如何让同一个字段在不同的view中显示不同的内容
    Trigger model Trigger expr_id in WorkFolow
    how to use a xml_id in field domain
    action 关联
    activity清除的所有方法
    listview加载性能优化ViewHolder
  • 原文地址:https://www.cnblogs.com/yuzilan/p/10626157.html
Copyright © 2011-2022 走看看