Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Create a class called Sphere with private data member radius. Include the following public functions/methods: Default constructor that sets the radius to 1 Parameterized constructor that lets the...

1 answer below »

Create a class called Sphere with private data member radius. Include the following public functions/methods:

Default constructor that sets the radius to 1

Parameterized constructor that lets the client set the radius

getRadius – return the radius

setRadius – allow the client to specify the radius

calcVolume – calculate the volume of the sphere

display – display the radius and volume


Next, create a Ball class that is derived publicly from Sphere. The Ball class adds a private data member, representing the name of the ball, e.g., soccer ball. In addition, provide the following public functions:

Default constructor – initialize the Sphere class and call the function setName with the null string

Parameterized Constructor – the user passes in the radius and the name of the ball

getName – sends back the ball’s name

setName – allows the client to set the name

reset – allows the client to specify a new radius and name

display – displays the name and then calls the sphere class display function


Also, create a Balloon class that is derived from Ball. The Balloon class adds a private data member, representing the name of the balloon, e.g., hydrogen balloon. In addition, provide the following public functions/methods:

Default constructor – initialize the Sphere class and call the function setName with the null string

Parameterized Constructor – the user passes in the radius and the name of the balloon

getName – sends back the balloon’s name

setName – allows the client to set the name

reset – allows the client to specify a new radius and name

display – displays the name and then calls the sphere class display function


Create a class that will handle polymorphism through the base class Sphere and include all of these classes in a program. Write a separate program with a main that the functions of inheritance and polymorphism.

IMPORTANT: Pack all of your classes in a Namespace header file named, “SphereNameSpace.h”

Answered Same Day Jul 04, 2021

Solution

Arun Shankar answered on Jul 07 2021
134 Votes
SphereNameSpace.h
#ifndef SPHERE_H
#define SPHERE_H
class Sphere
{
private:
double radius;

public:
/* Default Constructo
that sets the radius to 1 *
Sphere()
{
radius = 1;
}
/*Parameterized constructor that
lets the client set the radius *
Sphere(double r)
{
radius = r;
}
double getRadius()
return the radius
{
return radius;
}
void setRadius(double r)
allow the client to specify the radius
{
radius = r;
}
double calcVolume()
calculate the volume of the sphere
{
return 3.1415*radius*radius*radius*4.0/3.0;
}
void display()
{
cout
"Radius = "
adius
endl;
cout
"Volume = "
calcVolume()
endl;
}
};
* Create a Ball class that is derived
publicly from Sphere. *
class Ball: public Sphere
{
private:
string name;
public:
/* Default constructor – initialize the Sphere class...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here