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

Consider the following C++ class definition class Sphere { public: Sphere(); Sph

ID: 3915266 • Letter: C

Question

Consider the following C++ class definition class Sphere { public: Sphere(); Sphere(const float R); void SetRadius(const float R); void GetRadius(float &R); float CalculateVolume(); void Scale(float &S); void Print();
private: float radius; bool IsNotZero() const;
Assume the following C++ variables are declared in the main function and the method calls below are after the declarations. Which method calls are syntactically correct and use the return values properly
Sphere UnitSphere(1); Sphere Ball; Sphere Several[5]; float Radius; float Volume;

Explanation / Answer

If you have any doubts, please give me comment...

if(Ball.IsNotZero()) Ball.Print(); //wrong bcz IsNotZero is private member it can't access in main function, it's only access in Sphere class

Scale(UnitSphere, 2.5); //wrong bcz Scale is member of Sphere class

Ball.GetRadius(Radius); //correct

cout<<Ball.CalculateVolume(); //correct

UnitSphere.CalculateVolume(Volume); //Wrong CalculateVolume doesn't have accept any parameters

Radius = Several[3].GetRadius() //Wrong it must have one parameter and it doesn't have any return value;

Several[2].SetRadius(3); //Correct

Ball = UnitSphere.Scale(0.5); //Wrong must pass a variable and it doesn't have any return value

Several[4] = Several[1]; //Correct

Ball.radius = UnitSphere.radius; // Wrong radius is private property it can't access outside of class

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