Question: WRITE IT IN C + + please Now consider the class Point 2 D with the function getDistance that returns the distance of a 2
WRITE IT IN C please
Now consider the class Point with the function getDistance that returns the distance of a point from the origin :
Note: Accessors and mutators of the member variables are removed in this exercise.
Rewrite the definition of the class PointD from the previous task to redefine the function getDistance. The function should return the distance of a point from the origin according to the following formula:
dis
The following program defines a main function that can be used to test the PointD class.
The following is a snapshot of the above program's output.
Using object name, the distance of p is:
Using object name, the distance of p is:
Using parent pointer, the distance of p is:
Using child pointer, the distance of is:
Note: Even though both pointers are pointing to the same object p the results of the getDistance calls are different because of the static binding.
In the next task, the classes will be using dynamic binding.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
