Circle Sample SolutionΒΆ

#include "cmpt_error.h"
#include <iostream>

using namespace std;

class Circle {
private:
    double radius;
public:
    Circle(double r)
    : radius(r)
    { }

    Circle(const Circle& other)
    : radius(other.radius)
    { }

    double get_radius() const { return radius; }

    double get_area() const { return 3.1415926 * radius * radius; }

    double get_circumference() const { return 2 * 3.1415926 * radius; }
};

int main() {
    Circle c{5.3};  // 5.3 is the radius of the circle
                    // if a radius of 0, or less, is passed,
                    // then throw an error

    cout << "        Radius = " << c.get_radius() << "\n"
         << "          Area = " << c.get_area() << "\n"
         << " Circumference = " << c.get_circumference()
         << "\n";

    Circle d{c};

    cout << "        Radius = " << d.get_radius() << "\n"
         << "          Area = " << d.get_area() << "\n"
         << " Circumference = " << d.get_circumference()
         << "\n";
} // main