- Begin by defining the data type Point that hastwo coordinate members x and y. Specifically,Point will be implemented as a structure; defineoperators as needed to satisfy problem requirements.
b, prompt the user to input several (x,y) pairs. As the data isentered, store it in a vector of Points calledorginal_points. Input is terminated with the EOF character (differsby OS type). To be clear, I am asking you to define an inputstream operator to read the point format: (x,y). As anexample, the input of (5,6) is the correct input format for apoint. While the I/O format includes the ‘(‘, ‘,’, and ‘)’characters, the internal storage contains only the x and y values.Please Note -- I am expecting a robust, user-friendlyway to ensure Points are entered correctly and in a valid format. Asimple termination of the program is not acceptable here -- If I’veentered a number of valid points, don’t discard them -- recoverfrom the error so that input can continue (if possible) and ifinput cannot continue, ensure that the program proceeds to save thepoints I have entered. Also important -- this input streamoperator needs to work with standard input (cin) and formatted(text) file input streams.
- Print the data in original_points to the screen so we can seewhat it looks like. Create an output stream operator for this thatworks with both cout and output file streams.
- Open an ofstream and write each Point to afile named mydata.txt, using the operator you created in #3 above.Be sure to include the Points in the correctformat, one Point per line. Explicitly close thefile. Next, inspect the file. It should have the same contents aswhat you printed on the screen. Does it?
- Open the file and, using the same input logic that you createdin b, read in the Point data and print the results to the screen.(This is to demonstrate that your input operator is flexible to beused with multiple stream types. Since the data in the file shouldconform perfectly to the required format, your input checkingshould run smoothly here…) it's c++ language and Input errorhandling -- Points data structure
#include #include #include using namespace std;struct Point{ int x, y; bool operator==(const Point& p2) { return this->x == p2.x and this->y == p2.y; } bool operator!=(const Point& p2) { return this->x != p2.x or this->y != p2.y; } friend ostream &operator<<( ostream &out, const Point &P ) { out << \"(\" << P.x << \", \" << P.y << \")\"; return out; } friend istream &operator>>( istream &in, Point &P ) { char d1, d2, d3; // input format: (1, 2) in >> d1 >> P.x >> d2 >> P.y >> d3; return in; }};int main(){ vector original_points; cout << \"Enter points :\n\"; Point P; while( cin >> P ) { original_points.push_back(P); } ofstream out(\"mydata.txt\"); cout << \"You entered the points:\n\"; for(Point p: original_points) { cout << p << '\n'; out << p << '\n'; } out.close(); //pause cin.get(); char ch; cout << \"Press enter to continue: \"; getchar(); ifstream in(\"mydata.txt\"); vector processed_points; while( in >> P ) { processed_points.push_back(P); } int n = original_points.size(); for(int i=0; i