Code:
#include <iostream>
#include <istream>
#include <ostream>
using namespace std;
class Cartesian
{
private:
double x;
double y;
public:
Cartesian( double= 0, double= 0);
friend istream& operator>>(istream&, Cartesian&);
friend ostream& operator<<(ostream&, const Cartesian&);
};
Cartesian::Cartesian(double a, double b)
{
x=a;
y=b;
}
istream& operator>>( istream& in, Cartesian& num)
{
double a, b;
num.x= a;
num.y= b;
in >> a >> b;
return in;
}
ostream& operator<<( ostream& out, const Cartesian& num)
{
cout << "(" << num.x << ", " << num.y << ")" << endl;
return out;
}
int main()
{
Cartesian coord1, coord2;
cout << "Please enter the first coordinates: ";
cin >> coord1;
cout << "Please enter the second coordinates: ";
cin>> coord2;
cout << coord1;
cout << coord2;
return 0;
}
Also, I want to add a memberwise assignment function to assign the values of coord1 to coord2. How would I go about doing so?