+1 (315) 557-6473 

C++ Program to Create Circle Construction Assignment Solution.


Instructions

Objective
Write a C++ assignment to create a program for circle construction. The task involves implementing a program in C++ that allows the user to construct circles. The program should prompt the user to input the radius and then calculate the area and circumference of the circle. It should display these values to the user. Utilize appropriate C++ concepts such as classes and functions to structure your code effectively. This assignment aims to test your understanding of object-oriented programming and your ability to apply mathematical formulas in C++. Ensure that your code is well-documented and follows best coding practices.

Requirements and Specifications

program to create circle construction in c++

Source Code

#include

// Define the value of PI

#define PI 3.14159265358979323846

class Circle {

private:

double radius;

public:

// Constructor with no arguments

Circle() {

// Initializes the radius to 2.0

radius = 2.0;

}

// Constrcutor that accepts the radius as argument

Circle(double r) {

radius = r;

}

// Getter and Setter for radius

double getRadius() {

return radius;

}

void setRadius(double r) {

radius = r;

}

// method to calculate area

double getArea() {

// returns pi*radius^2

return PI*getRadius()*getRadius();

}

// method to print the area

void printArea() {

// Calculate area

double area = getArea();

std::cout << "The area of the Circle with radius " << getRadius() << " (u) is: " << getArea() << " (u^2)" << std::endl;

}

};