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: 3621723 • 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 friend function << for cout
. Provide a friend function >> for cin
. Provide an overloaded operator + for this class
. Provide an overloaded operator - for this class
. Provide an overloaded operator * for this class
. Provide an overloaded operator = for this class
. Provide an overloaded operator == for this class
. Provide an overloaded operator != for this class
 

 

The output should look as follows:

Enter a graphical point in the form: (x, y)
? (3, 4)

a = b + c:
(7, 9) = (4, 8) + (3, 1)

a = b - c:
(1, 7) = (4, 8) - (3, 1)

a = b * c:
(12, 8) = (4, 8) * (3, 1)

(12, 8) != (3, 4)

(3, 4) == (3, 4)
Notes
To compile use the command g++ *.cpp -o pa9 to compile and link Complex.h, Complex.cpp, and PA9.cpp in to the executable pa9.

Test your class with this program.

 

 

 

Explanation / Answer

please rate - thanks

// Class to test Point.h and Point.cpp classes
#include <iostream>
using namespace std;
class Point
{friend ostream &operator<<( ostream &, const Point &otherPoint );
friend istream &operator>>( istream &, Point &otherPoint );
public:
Point();
Point(double,double);
void setPoint(double newX,double newY);
Point operator+(Point p) ;
Point operator-(Point p) ;
Point operator*(Point p) ;
Point operator/(Point p) ;
bool operator!=(Point p) ;
bool operator==(Point p) ;
Point operator=(Point p) ;
double getx();
double gety();  
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;
}

bool Point::operator == (Point p)
{if(x==p.x&&y==p.y)
     return true;
return false;
}
bool Point::operator != (Point p)
{if(x==p.x&&y==p.y)
     return false;
return true;
}
Point Point::operator * (Point p)
{Point z;
z.x=x*p.x;
z.y=y*p.y;
return z;
}
Point Point::operator = (Point p)
{Point z;
z.x=p.x;
z.y=p.y;
return z;
}
Point Point::operator / (Point p)
{Point z;
z.x=x/p.x;
z.y=y/p.y;

return z;
}
Point Point::operator + (Point p)
{Point z;
z.x=x+p.x;
z.y=y+p.y;

return z;
}
Point Point::operator - (Point p)
{Point z;
z.x=x-p.x;
z.y=y-p.y;
return z;
}
double Point:: getx()
{return x;
}
double Point:: gety()
{return y;
}
ostream& operator<<( ostream &output, const Point& p )
{output<<"("<<p.x<<","<<p.y<<")";
return output;

}
istream& operator>>( istream &input, Point& p )
{string in;
cin>>in;
p.x=in[1]-'0';
p.y=in[4]-'0';
return input;

}

int main()
{
Point a, b( 4, 8 ), c( 3, 1 ), k;

cout << "Enter a graphical point in the form: (x, y) ? ";
cin >> k;

a = b + c;
cout << " a = b + c: " << a << " = " << b << " + " << c << ' ';

a = b - c;
cout << " a = b - c: " << a << " = " << b << " - " << c << ' ';

a = b * c;
cout << " a = b * c: " << a << " = " << b << " * " << c << " ";

if ( a != k )
{
cout << a << " != " << k << ' ';
}

cout << ' ';
a = k;

if ( a == k )
{
cout << a << " == " << k << ' ';
}
system("pause");
return 0;
}