定义一个圆类Circle,要求:(1)分别用成员函数和友元函数计算圆的面积和周长:(2)用拷贝函数初始化

2022-03-22 社会 111阅读

circle.h

#ifndef CIRCLE_H
#define CIRCLE_H

class Circle
{
    double r;

public:
    Circle(double r);
    Circle(const Circle &cricle);
    ~Circle();

    double count_area() const;
    friend double count_girth(const Circle &circle);
    double count_area_sum(const Circle &circle) const;
};

#endif 


circle.cpp

#include "circle.h"

static const double pi = 3.14;

Circle::Circle(double r)
{
    this->r = r;
}

Circle::~Circle()
{

}

Circle::Circle(const Circle &cricle)
{
    this->r = cricle.r;
}

double Circle::count_area() const
{
    return pi * r * r;
}

double Circle::count_area_sum(const Circle &circle) const
{
    double sum = 0.0;
    sum = this->count_area() + circle.count_area();
    return sum;
}

double count_girth(const Circle &circle)
{
    return 2 * pi * circle.r;
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com