Purchase Solution

C++ Sphere Objects

Not what you're looking for?

Ask Custom Question

Write a program that instantiates four sphere objects (assigning a radius to each instance) and adds them to a pointer-based linked list. Include a function to display the statistics of each sphere in the list.

// ***************************************************
// Header file for the class sphereClass.
// ***************************************************
const double PI = 3.14159;
class sphereClass
{
public:
sphereClass();
// Default constructor: Creates a sphere and
// initializes its radius to a default value.
// Precondition: None.
// Postcondition: A sphere of radius 1 exists.

sphereClass(double InitialRadius);
// Constructor: Creates a sphere and initializes
// its radius.
// Precondition: InitialRadius is the desired
// radius.
// Postcondition: A sphere of radius InitialRadius
// exists.

void SetRadius(double NewRadius);
// Sets (alters) the radius of an existing sphere.
// Precondition: NewRadius is the desired radius.
// Postcondition: The sphere's radius is NewRadius.

double Radius() const;
// Determines a sphere's radius.
// Precondition: None.
// Postcondition: Returns the radius.

double Diameter() const;
// Determines a sphere's diameter.
// Precondition: None.
// Postcondition: Returns the diameter.

double Circumference() const;
// Determines a sphere's circumference.
// Precondition: PI is a named constant.
// Postcondition: Returns the circumference.

double Area() const;
// Determines a sphere's surface area.
// Precondition: PI is a named constant.
// Postcondition: Returns the surface area.

double Volume() const;
// Determines a sphere's volume.
// Precondition: PI is a named constant.
// Postcondition: Returns the volume.

void DisplayStatistics() const;
// Displays statistics of a sphere.
// Precondition: None.
// Postcondition: Displays the radius, diameter,
// circumference, area, and volume.

private:
double TheRadius; // the sphere's radius
}; // end class
// End of header file.

Purchase this Solution

Solution Summary

The expert examines C++ sphere objects in linked lists.

Solution Preview

Dear Student,

Please find the solution, the Sphere Class as ...

Solution provided by:
Education
  • BSc (Hons), University of Colombo - Sri Lanka
  • MEngSc, University of Melbourne
  • Certificate IV in Training & Assessment , Australian Business Council
Recent Feedback
  • "Thank you!"
  • "Thank you."
  • "Thanks a lot for you help and support"
  • "Sorry about the late payment but the assignment was sufficient and appreciated. Good work"
  • "Great description! Thank you for your quick response."
Purchase this Solution


Free BrainMass Quizzes
Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Basic Networking Questions

This quiz consists of some basic networking questions.