Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please change point 2 d class and point 3 d class ( point 3 d inherits from point 2 d ) so that we can
Please change point d class and point d class point d inherits from point d so that we can use templates. Please implement a test program. using C
this is the following code for point d class
#include iostream
#include cmath 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
;
heres code for point d
#include
using namespace std;
base class
class pointD
data members
protected:
double xy;
public:
constructor
pointddouble x double y
thisxx;
thisyy;
setters
void setxdouble XxX;
void setYdouble YyY
;
inherit pointD
class pointD:public pointD
data members
protected:
double z;
public:
constructor call base class constructor
pointddouble xdouble ydouble z:pointdxy
thiszZ;
setters and getters
void setZdouble ZzZ;
double getZreturn z;
;
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