Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ need help: Create a C++ class named Circle, which you should store in a file

ID: 3795966 • Letter: C

Question

C++ need help:

Create a C++ class named Circle, which you should store in a file called Circle.h. Your class should have three private variables, namely x, y, and r, all of type double. The variables x and y will store the Cartesian position of the center of the circle and the variable r should store the radius.

You should also add a public variable, area, which will store the area of the circle. There should be two constructors, one that takes no arguments and instantiates a unit circle centered at the origin. The second constructor should take in three arguments, namely x, y and r, and instantiate a circle of radius r, centered at (x, y).

There should be getters and setters for all the private variables. Your code will be tested with the circles.cpp file.

Do not modify the below code, is for testing:

Explanation / Answer

#include<iostream.h>
#include<conio.h>
#define pi 3.14

class Circle{

private:
double x,y,r;
public:
double area;

//default constructor
Circle(){
x=0.0;
y=0.0;
r=1.0;

area=pi*r*r; //area calculation

}

//parameterised constructor
Circle(double a,double b,double rad){
x=a;
y=b;
r=rad;
area=pi*r*r; //area calculation
}

//setter methods
void setX(double x){
this.x=x;
}
void setY(double y){
this.y=y;
}

void setR(double r){
this.r=r;
}

//getter methods
double getX(){
return x;
}
double getY(){
return y;
}
double getR(){
return r;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote