diff --git a/Makefile b/Makefile index 843e64a..da853a5 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,15 @@ # Author: Elijah Opoku-Nyarko and Jake Colbert # default target -all: project4 +all: project5 # compile the code into an executable called 'project1' using C++ 2011 -project4: project4.cc - g++ -std=c++11 -o project4 project4.cc +project5: project5.cc province.h + g++ -std=c++11 -o project5 project5.cc # test the code against an expected output file # this test should grow into a spaceship and end with blinkers test-nowhere: - ./project4 < test-files/t01-nowhere.in > tests/project4.out + ./project5 < test-files/t01-nowhere.in > tests/project4.out diff test-files/project4.out test-files/t01-nowhere.out > test.diff wc -l test.diff diff --git a/project5 b/project5 new file mode 100755 index 0000000..1662a54 Binary files /dev/null and b/project5 differ diff --git a/project5.cc b/project5.cc index 42e8448..47f8777 100644 --- a/project5.cc +++ b/project5.cc @@ -18,10 +18,12 @@ using namespace std; - int main() { while(!cin.eof()) { - Province province(cin); + cout << "its not actually running" << endl; + // the following lines produce 'undefined symbols for architecture' errors + // Province theProvince = * new Province(cin); + // theProvince.printAll(cout); } } diff --git a/province.cc b/province.cc index 023aa7d..6f89d3b 100644 --- a/province.cc +++ b/province.cc @@ -23,14 +23,15 @@ using namespace std; * Danvers, not a bridge, 2.9 miles long) */ -Province::Province(std::istream &source) { +Province::Province(std::istream & source) { // Read first line of input source >> _numberOfTowns >> _numberOfRoads; + _towns = new Town[_numberOfTowns]; std::map townMap; // maps town names to their indexes in _towns // Read town names for (int i = 0; i < _numberOfTowns; i++) { - source >> _towns.push_back(Town()); // This needs to be converted to vector, im not sure how exactly + source >> _towns[i]._name; // This needs to be converted to vector, im not sure how exactly townMap[_towns[i]._name] = i; } @@ -44,14 +45,17 @@ Province::Province(std::istream &source) { } } -void Province::printAll(int start, std::ostream & output) const{ +void Province::printAll(std::ostream & output) { output << "The input data is:" << endl << endl; - - for (Town town : _towns) { + for (int i = 0; i < sizeof(_towns)/sizeof(_towns[0]); i++) { output << _towns[i]._name << endl; for (Road road : _towns[i]._roads) { - output << "\t" << endl; // needs to be finished too + output << "\t" << road._tail << " " << road._length << " mi"; + if (road._isBridge == 'B' || 'b') { + output << " via bridge" << endl; + } else { + output << endl; + } } - } } \ No newline at end of file diff --git a/province.h b/province.h index 1c114a2..be8a6d7 100644 --- a/province.h +++ b/province.h @@ -28,11 +28,9 @@ class Province /** * Print towns and roads in province in breadth-first search order - * @param start Index to start traversal at * @param output Stream to print data to */ - void printAll(int start, std::ostream & output) const; - + void printAll(std::ostream & output); void printShortestPath(std::ostream & output) const; /** @@ -100,6 +98,6 @@ class Province int _numberOfTowns; int _numberOfRoads; - std::vector _towns; + Town *_towns; std::vector _roads; };