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

Please Write this code in C++ and please read ALL the instruction!! Please also

ID: 3890621 • Letter: P

Question

Please Write this code in C++ and please read ALL the instruction!!

Please also don't write too much code. Write enough for this code to work

Write a class declaration named Circle with a private member variable named radius. Write set and get functions to access the radius variable, and a function named getArea that returns the area of the circle. The area is calculated as 3.14159*radius*radius. Add a default constructor to the Circle class. The constructor should initialize the radius member to 0. Add an overloaded constructor to the Circle class. The constructor should accept an argument and assign its value to the radius member variable.

Explanation / Answer

#include <iostream>

using namespace std;
class Circle {
private:
double radius;
public:
Circle(){
radius = 0;
}
Circle(double r){
radius = r;
}
void setRadius(double r){
radius = r;
}
double getRadius() {
return radius;
}
double getArea() {
return 3.14159*radius*radius;
}
};
int main()
{
Circle c1;
c1.setRadius(2);
cout<<"Area: "<<c1.getArea()<<endl;
Circle c2(3);
cout<<"Area: "<<c2.getArea()<<endl;
  
  
return 0;
}

Output:

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