Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Define the class Point 3 D that is derived from Point 2 D as defined in the following UML Point 3 D - z: double
Define the class Point D that is derived from PointD as defined in the following UML
Point D
z: double
PointD
PointDx: double, y: double, z: double
distanceToOrigin: double
distanceToPointp: const PointD& : double
friend operator P: const PointD& P: const PointD&: Point D
friend operator os: ostream& P: const PointD& : ostream&
friend operator is: istream& P: const PointD& : istream&
Write a testing program to use both classes
here is the point class
#include
#include For mathematical operations
class PointD
public:
Default constructor: Initializes x and y to
PointD : x y
Constructor with parameters: Initializes x and y with provided values
PointDdouble x double y : xx yy
Copy constructor: Creates a deep copy of another PointD object
PointDconst PointD& P : xPx yPy
Setters: Allow modification of x and y coordinates
void setXdouble x x x;
void setYdouble y y y;
Getters: Provide access to x and y coordinates const ensures no modification
double getX const return x;
double getY const return y;
Calculates the distance from the origin
double getDistanceToOrigin const
return sqrtstd::powx std::powy;
Calculates the angle in radians from the positive xaxis
double getAngle const
return atany x; Use atan for correct quadrant handling
Shifts the point by a specified amount dx and dy
void shiftdouble dx double dy
x dx;
y dy;
Calculates the distance between two PointD objects
double distanceToPointconst PointD& P const
double dx x Px;
double dy y Py;
return sqrtstd::powdx std::powdy;
Overloaded addition operator : Adds two PointD objects and returns a new PointD
friend PointD operatorconst PointD& P const PointD& P
return PointDPx Px Py Py;
Overloaded insertion operator : Prints the PointD coordinates to an ostream like cout
friend ostream& operatorostream& os const PointD& P
os Px Py ;
return os;
Overloaded extraction operator : Reads PointD coordinates from an istream like cin
friend istream& operatoristream& is PointD& P
is Px Py;
return is;
private:
double x; xcoordinate
double y; ycoordinate
;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started