Okay so I've changed my code around a bit, but now I get errors saying the x and y in x=c and y=d don't name types. What should I do?
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&);
double c;
double d;
x=c;
y=d;
};
Cartesian::Cartesian(double a, double b)
{
x=a;
y=b;
}
istream& operator>>( istream& in, Cartesian& num)
{
in >> num.x;
in >> num.y;
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 x-coordinate: ";
cin >> coord1.c;
cout << "Please enter the first y-coordinate: ";
cin >> coord1.d;
cout << "Please enter the second x-coordinate: ";
cin >> coord2.c;
cout << "Please enter the second y-coordinate: ";
cin >> coord2.d;
cout << coord1;
cout << coord2;
return 0;
}