Question: In c++ Define the class Point3D that represents an ordered triplet (x, y, z) in a 3 dimensional coordinate system. a. Class Point3D inherits from

In c++

Define the class Point3D that represents an ordered triplet (x, y, z) in a 3 dimensional coordinate system.

a. Class Point3D inherits from class Point2D and has an additional private data member z(double).

b. Define a default constructor as well as a constructor with parameter for the Point3D class.

c. Include a get/set functions for the private data member z.

d. Redefine the function distance() in Point3D that uses the formula sqrt (x^2 + y^2 + z^2) to compute the distance of the point from the origin.

e. Test the class Point3D by writing a main function in which you create a Point2D object as well as a Point3D object using the constructor with parameters. Next display their distances from the origin.

f. Demonstrate polymorphic behavior by declaring a Point2D pointer type variable and separately assigning a Point2D object and then a Point3D object to the pointer and calling the distance function using the pointer. Which distance function will be called? What does your code show?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!