I am trying to make a program with a Cartesian class that allows the user to enter 2 coordinates and displays these coordinates. When I try to compile it, I get a message saying the x and y in x=c and y=d don't name a type. How can I fix this? Also, how would I go about inserting an assignment function that assigns the values of coord1 to coord2?
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; }




Reply With Quote
