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

I need help creating a sphere class in c++ with the following specifications. I

ID: 3605874 • Letter: I

Question

I need help creating a sphere class in c++ with the following specifications. I don't know too much about classes so any help is appreciated.

Sphere Class edikl Using a h and.cpp fe, implement a Sphere class with the following data flelds and methods. Constant Use the lolowing value for Pl- 3.14159 Dete radius: doube s color: string Methods ·Sphere()-default constructor . should set th radius to one and color to green . Sphero(doubler) _ custom constructor -sets the radius toand color to green Sphere double r string c) custom conistructor sets the radius to r and color to c a void setRadius doubla) ·mutator method used to change the radius a double getRadius) const constant function that return the radius void setColorlstring) mutaior method to sel the color of the Sphere string gelCokr) const constant accessor method that retum the color of the Sphere adouble area) const constent function that returns the surface area of the Sphere surface area = 42 . double volume()const constent function that returns the volume of the Sphere . volume=- a bool isEqusl(const Sphere other) const constant boolean function that return TRUE is two Spheres have the same radius and color, FALSE otherwise Deliverables edirl Sphere.h Sphere.cpp

Explanation / Answer

ANSWER :

Sphere.cpp

#include<iostream>

#include<string>

#define PI 3.14159 //define value of PI

using namespace std;

class Sphere //Sphere class

{

private:

double radius; //radius variable

string color; //color variable

public:

Sphere() //default constructor

{

setRadius(1);

setColor("green");

}

Sphere(double r) //custom constructor 1

{

setRadius(r);

setColor("green");

}

Sphere(double r,string c) //custom constructor 1

{

setRadius(r);

setColor(c);

}

void setRadius(double r) //setRadius() function

{

radius = r;

}

double getRadius()const //getRadius() function

{

return radius;

}

void setColor(string c) //setColor() function

{

color = c;

}

string getColor()const //getColor() function

{

return color;

}

double area()const //area() function to calculate area of sphere

{

return 4*PI*radius*radius;

}

double volume()const //volume function to calculate volume of sphere

{

return (4*PI*radius*radius*radius)/3;

}

bool isEqual(Sphere&av,Sphere&bv)const //isEqual() function to check if two sphere are identical

{

return ((av.radius == bv.radius)&&(av.color==bv.color));

};

};

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