From 28d66eda436b21a37a5e5790dcd6290d41b9f579 Mon Sep 17 00:00:00 2001 From: jensenrrr <32421710+jensenrrr@users.noreply.github.com> Date: Tue, 10 Apr 2018 19:57:46 -0400 Subject: [PATCH 1/2] Node* vector and adjacency matrix Didn't see Asia's header file with getters and setters so I ended making my own, I can/will change out my header for hers later, though since I made a vector of pointers to Nodes I'll have to change some of the getDist method I think --- adj.txt | 3 ++ main.cpp | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.h | 37 +++++++------ map.txt | 3 ++ 4 files changed, 189 insertions(+), 16 deletions(-) create mode 100644 adj.txt create mode 100644 main.cpp create mode 100644 map.txt diff --git a/adj.txt b/adj.txt new file mode 100644 index 0000000..f7101bb --- /dev/null +++ b/adj.txt @@ -0,0 +1,3 @@ +0,1,1, +1,0,-1, +1,-1,0, diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..7c6a294 --- /dev/null +++ b/main.cpp @@ -0,0 +1,162 @@ +#include +#include +#include +#include +#include +#include +#include //needed for atof -> convert string to double +#include "main.h" +using namespace std; + +Node::Node(int x, int y, string name){ + this->x=x; + this->y=y; + this->name = name; +} + +string Node::getName(){ + return this->name; +} + +double Node::getX(){ + return this->x; +} + +double Node::getY(){ + return this->y; +} + + +vector createTokens(string s){ +// std::cout< lineVector; + string temp=""; + for (int i=0; i> jk; + lineVector.push_back(jk);*/ + temp = ""; + } + } + return lineVector; +} + + + +int main(){ + vector locations;//vector of node locations + vector temp; + vector token; + vector > adjMatrix; + int lines = 0; + string filename = "map.txt"; + + ifstream infile(filename); + // infile.open(filename); + string str; + while(getline(infile,str)){ + temp = createTokens(str); + lines++; + for(int i=0; igetX(); + cout<< locations[i]->getY(); + cout<< locations[i]->getName(); + }*/ + + string adjacencyFileName = "adj.txt"; + //clears token vector for reuse + token.clear(); + ifstream afile(adjacencyFileName); + while(getline(afile,str)){ + temp = createTokens(str); + for(int i=0; i nodeAdj; + iter = 0; + //iterates through the token list, knowing each line should have a number of 1s/0s/-1s equal to the locations.size() + //which is equal to the number of lines in map.txt + //pushes the 1D vector that corresponds to a node into the 2D vector that holds adjcacency for all nodes + for(int i = 1; i <= lines; i++){ + for(int j = 0; j +using namespace std; +class Node{ + +private: + double x; + double y; + string name; + +public: + string getName(); + double getX(); + double getY(); + Node(int x, int y, string name); +}; + + +/*void PrintMenu(*Node [] locations); +void addNodeLocation(string name, int x, int y); +string [] Dijkstra(*Node [] locations); +*/ \ No newline at end of file diff --git a/map.txt b/map.txt new file mode 100644 index 0000000..117ef80 --- /dev/null +++ b/map.txt @@ -0,0 +1,3 @@ +Marston,5,6, +Turlington,5,9, +Library-West,10,15, \ No newline at end of file From 78d43a90591bc855975a3f2e75de9e17517d8602 Mon Sep 17 00:00:00 2001 From: jensenrrr <32421710+jensenrrr@users.noreply.github.com> Date: Tue, 10 Apr 2018 21:11:44 -0400 Subject: [PATCH 2/2] Included Asia's getDist Makes the getDist function compatible with the locations Node* vector. --- main.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main.h b/main.h index 0334baa..25d0f5f 100644 --- a/main.h +++ b/main.h @@ -14,6 +14,17 @@ class Node{ Node(int x, int y, string name); }; +double getDist(Node* c,Node* d){ + double x1= c->getX(); + double x2=d->getX(); + double y1=c->getY(); + double y2=d->getY(); + + double xDiff = x1-x2; + double yDiff = y1-y2; + double dist= sqrt(pow(xDiff,2)+pow(yDiff,2)); + return dist; +} /*void PrintMenu(*Node [] locations); void addNodeLocation(string name, int x, int y);