Question: Need .cpp and .h This is a simple Point class interface file whose objects represent points in the cartesian plane #include using namespace std; class
Need .cpp and .h
This is a simple Point class interface file whose objects represent points in the cartesian plane
#include
using namespace std;
class Point
{
public:
Point(); // default constructor
Point(double x, double y); // another constructor
double x() const; // get function, return _x
double y() const; // get function, return _y
private:
double _x, _y;
};
Here is a test driver file for the Point class (do not modify the driver file):
#include "Point.h" // defines Point class
#include
using namespace std;
int main()
{
Point p0; // invokes default constructor
Point p1(5, -2); // invokes constructor
Point p2 = p1;
p0 = p1; // invokes assignment operator
cout << "p0.x() = " << p0.x() << " ";
cout << "p0.y() = " << p0.y() << " ";
}
- Write the implementation file of Point class.
- Add the following member functions to the point class, implement them, and test them in the driver:
- Returns polar coordinate r = x2+y2
double magnitude() const;
- Move the point dx in x direc and dy in y direction
void move(double dx, double dy);
- Print the point in the format (x, y) to ostream out
void print(ostream & out) const;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
