Question: C++ Can you help me make an overloaded >> operator for my polygon class to help my findParcelName function work?: string GIS::findParcelName(Point point){ ifstream file(fileName);

C++ Can you help me make an overloaded >> operator for my polygon class to help my findParcelName function work?:

string GIS::findParcelName(Point point){ ifstream file(fileName); // open the file specified in the parameter Polygon poly; // create a Polygon object while (file >> poly) { // NEED OVERLOADED >> OPERATOR if (poly.contains(point)) { // check if the point is inside the polygon file.close(); return poly.GetName(); // return the name of the polygon if found } } file.close(); return "Not Found"; // return "Not Found" if the point is not inside any polygon }

Polygon class:

class Polygon: public Point { public: Polygon();

Polygon(string n, Point points1[10], int vertexs);

Polygon(const Polygon &p1){ name = p1.name; vertexCount = p1.vertexCount; for(int i = 0; i < vertexCount; i++){ points[i] = p1.points[i]; } }

~Polygon(){ cout<<"Memory released"<

Polygon& operator=(const Polygon &other); string GetName(); int getVertexCount(); Point* getVertex(int vertex); bool contains(Point point);

private: string name; int vertexCount; Point points[10];

};

Polygon::Polygon(){ name = ""; vertexCount = 0; points[10] = {}; }

Polygon::Polygon(string n, Point points1[], int vertexs){ name = n; vertexCount = vertexs; for(int i = 0; i < vertexCount; i++){ points[i] = points1[i]; } }

string Polygon::GetName(){ return name; }

Point* Polygon::getVertex(int vertex){ //return specific point from array using vertex as position return &points[vertex]; }

int Polygon::getVertexCount(){ return vertexCount; }

Polygon& Polygon::operator=(const Polygon &other){ name = other.name; vertexCount = other.vertexCount; for(int i = 0; i < vertexCount; i++){ points[i] = other.points[i]; } return *this; }

//ADD OVERLOADED >> OPERATOR FOR POLYGON CLASS

bool Polygon::contains(Point point){ int i; int j; bool x = false; for (i = 0, j = vertexCount-1; i < vertexCount; j = i++){ if (points[i].getX() == point.getX() && points[i].getY() == point.getY()) { return true; } if (((points[i].getY()>point.getY()) != (points[j].getY()>point.getY())) && (point.getX() < (points[j].getX()-points[i].getX()) * (point.getY()-points[i].getY()) / (points[j].getY()-points[i].getY()) + points[i].getX())) { x = !x; } } return x; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!