Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Points have the form (x, y) . Use double variables to represent the private data

ID: 3621413 • Letter: P

Question

Points have the form (x, y)
.Use double variables to represent the private data of the class.
.Provide a constructor that enables an object to be initialized when it is declared and has default values of 0.0.
.Provide a public member function "add" to add two points together. Add both of the x values and both of the y values and return a new Point.
.Provide a public member function "subtract" to subtract two points together. Subtract both of the x values and both of the y values and return a new Point.
.Provide a public member function "printPoint" to print the coordinate in the form "(x, y)".
Provide a public member function "setPoint" to set the values of both x and y values of the Point.
The output should look as follows:
(1,7) + (9,8) = (10,15)
(10,1) - (11,3) = (-1,-2)
Notes
To compile use the command g++ *.cpp -o pa8 to compile and link Point.h, Point.cpp, and pa8.cpp in to the executable pa8.

Test your class with this program.


Explanation / Answer

please rate - thanks

sorry-I don't do multiple files

// Class to test Point.h and Point.cpp classes
#include <iostream>
using namespace std;
class Point
{public:
Point();
Point(double,double);
void setPoint(double newX,double newY);
Point add (Point otherPoint) const;
Point subtract (Point otherPoint) const;
Point printPoint();
private:
double x,y;
};
Point::Point()
{x=0.0;
y=0.0;
}
Point::Point(double newX,double newY)
{x=newX;
y=newY;
}
void Point::setPoint(double newX,double newY)
{x=newX;
y=newY;
}
Point Point::add (Point p) const
{Point z;
z.x=x+p.x;
z.y=y+p.y;
return z;
}
Point Point::subtract (Point p) const
{Point z;
z.x=x-p.x;
z.y=y-p.y;
return z;
}
Point Point::printPoint()
{cout<<"("<<x<<","<<y<<")";
}


int main()
{
    Point a( 1, 7 ), b( 9, 8 ), c;

    a.printPoint();
    cout << " + ";
    b.printPoint();
    cout << " = ";
    c = a.add( b );
    c.printPoint();
   
    cout << ' ';
    a.setPoint( 10, 1 );
    b.setPoint( 11, 3 );
    a.printPoint();
    cout << " - ";
    b.printPoint();
    cout << " = ";
    c = a.subtract( b );
    c.printPoint();
    cout << endl;
}