Question
C++ I believe my GIS findParcelName function is not reading the next line of simply-polygon.txt provided below. If you look at the output it appears
C++ I believe my GIS findParcelName function is not reading the next line of simply-polygon.txt provided below. If you look at the output it appears to be checking the first polygon but it reads a 0 for the second one so I think it is not reading the next line in the sample-polygon.txt file.
Photo of error output:
simple-polygons.txt:
squareParcel 0 0 0 2 2 2 2 0 //READS squareParcel wideRectangleParcel 0 2 0 4 6 4 6 2 //DOES NOT READ wideRectangleParcel
Test case:
TEST_CASE("Testing container (GIS) operations") { GIS taxMap; SECTION("Check file availability") { REQUIRE(!taxMap.readFile("zzzzz.zzzz")); //WORKS REQUIRE(taxMap.readFile("simple-polygons.txt")); //WORKS } SECTION("Check point that isn't inside any of the polygons") { taxMap.readFile("simple-polygons.txt"); //WORKS CHECK("Not Found" == taxMap.findParcelName(Point(-1, -1))); //WORKS } SECTION("Check for point inside polygon") { //NEED HELP WITH THIS SECTION taxMap.readFile("simple-polygons.txt"); CHECK("squareParcel" == taxMap.findParcelName(Point(1, 1))); //DOES NOT WORK CHECK("wideRectangleParcel" == taxMap.findParcelName(Point(5, 4))); //DOES NOT WORK } } GIS class:
class GIS{ public: GIS(){ } ~GIS(){ cout
private: string fileName; };
bool GIS::readFile(string fileName){ ifstream file; file.open(fileName); //checks if file exist if(file){ this->fileName = fileName; file.close(); return true; } return false; }
string GIS::findParcelName(Point point){ ifstream file(fileName); // open the file specified in the parameter Polygon poly; while (file >> poly){ cout Polygon class: This has the contain function
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
~Polygon(){ //delete [] points; cout
Polygon& operator=(const Polygon &other); friend istream& operator>>(istream& in, Polygon& p); 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; for (int i = 0; i
Polygon::Polygon(string n, Point points1[], int vertexs){ name = n; vertexCount = vertexs; for(int i = 0; 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
istream& operator>>(istream& in, Polygon& p){ string name; int vertexCount; in >> name >> vertexCount; p.name = name; p.vertexCount = vertexCount; for(int i = 0; i > p.points[i]; } return in; }
bool Polygon::contains(Point point){ int i; int j; bool x = false; for (i = 0, j = vertexCount-1; i point.getY()) != (points[j].getY()>point.getY())) && (point.getX() test/test-4-gis. cpp:18: FAILED: CHECK ( "squareParcel" == taxMap.findParcelName(Point (1,1)) ) with expansion: "squareParcel" == "Not Found" Checking polygon: squareParcel Checking polygon: 0 test/test-4-gis. cpp:19: FAILED: CHECK( "wideRectangleParcel" == taxMap.findParcelName(Point (5, 4)) ) with expansion: "wideRectangleParcel" == "Not Found" ======================================================================- test cases: 1 | 1 failed assertions: 5 | 3 passed 2 failed
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started