圆的程序怎么编程?

圆的程序怎么编程?,第1张

C++编程

#includeusingnamespacestd;#definePI3.141592635classCircle{public:Circle():_r(0.f){}Circle(doubler):_r(r){}Circle(constCircle&circle){this->_r=circle._r;}voidsetRadius(doubler){this->_r=r;}doubleArea(){returnPI*this->_r*this->_r;}doubleCircumference(){return2*PI*this->_r;}private:double_r;};intmain(){Circlec1;doublex;cin>>x;c1.setRadius(x);cout<<"c1面积:"旅指<<c1.Area()<<endl;cout<<"c1周长:"<<c1.Circumference()<<endl;Circlec2(2*x);cout<<"c2面前镇源积:"<<c2.Area()<<endl;cout<<"c2周长:"<<c2.Circumference()<<endl;Circlec3(c1);cout<<"c3面积:"<<c3.Area()<<endl;cout<<"慧态c3周长:"<<c3.Circumference()<<endl;return0;}

#include <iostream>

using namespace std

   

#define PI 3.141592635

  

class Circle

{

public:

    Circle() : _r(0.f){}

    Circle(double r) : _r(r){}

    Circle(const Circle& circle)

    {

        this->_r = circle._r

    }

    void setRadius(double r)

    {

        this->_r = r 

    }  

    double Area()

    {

        return PI * this->_r * this->_r 

    }   

    double Circumference()

    {    

       冲桥 老雹return 2 * PI * this->_r 

    }     

   

private:

    double _r      

}  

int main()

{

    Circle c1

    double x

    cin >> x

    c1.setRadius(x)

    cout << "c1面积:" 侍判帆<< c1.Area() << endl

    cout << "c1周长:" << c1.Circumference() << endl

    Circle c2(2 * x) 

    cout << "c2面积:" << c2.Area() << endl

    cout << "c2周长:" << c2.Circumference() << endl 

    Circle c3(c1)  

    cout << "c3面积:" << c3.Area() << endl

    cout << "c3周长:" << c3.Circumference() << endl  

       

    return 0 

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12368910.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存