diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f7f6f5f --- /dev/null +++ b/.gitignore @@ -0,0 +1,47 @@ +# From a github template for removing unneccessary C++ files + +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.app + +# The project1 executable and related files +project5 + +# Files returned by tests +*.diff +test-data/project5.out + +# Mac setup files +*.DS_Store + +# VS Code setup files +*.vscode + diff --git a/Makefile b/Makefile index c6aa265..447fd61 100644 --- a/Makefile +++ b/Makefile @@ -11,4 +11,5 @@ project5: project5.cc province.cc province.h # this test should grow into a spaceship and end with blinkers test-requirement1: project5 ./project5 < test-data/requirement1.in > test-data/project5.out - diff test-data/project5.out test-data/requirement1.out + diff test-data/project5.out test-data/requirement1.out > test.diff + wc -l test.diff \ No newline at end of file diff --git a/project5.cc b/project5.cc index b29a904..1c9e992 100644 --- a/project5.cc +++ b/project5.cc @@ -18,34 +18,34 @@ using namespace std; * check if we are at the end of the file */ bool eof() { - char c; - std::cin >> c; - // if the fie is ended, return true - if (std::cin.eof()) { - return true; - } else { - // if the file contains more data, return the previously gotten - // data to cin - std::cin.unget(); - return false; - } + char c; + cin >> c; + // if the fie is ended, return true + if (cin.eof()) { + return true; + } else { + // if the file contains more data, return the previously gotten + // data to cin + cin.unget(); + return false; + } } int main(int argc, char *argv[]) { - // Repeatedly read input from standard input - while (!eof()) { - // create a new graph for each loop, which will read all of the - // corresponding data per graph - Province theProvince(cin); + // Repeatedly read input from standard input + while (!eof()) { + // create a new graph for each loop, which will read all of the + // corresponding data per graph + Province theProvince(cin); - std::cout << std::endl; - std::cout << "------------------------------------------------" << std::endl; - std::cout << "---------------- New DataSet: ------------------" << std::endl; - std::cout << "------------------------------------------------" << std::endl; - std::cout << std::endl; + cout << endl; + cout << "------------------------------------------------" << endl; + cout << "---------------- New DataSet: ------------------" << endl; + cout << "------------------------------------------------" << endl; + cout << endl; - theProvince.printAll(0, cout); + theProvince.printAll(0, cout); - - } + + } } diff --git a/province.cc b/province.cc index 7b1025b..5e0ecfe 100644 --- a/province.cc +++ b/province.cc @@ -12,18 +12,6 @@ using namespace std; -/*f -* Constructor -* @param source File containing province: -* 1. One line: number of towns (n), number of roads (p) -* as integers -* 2. n lines: names of towns, all uppercase -* 3. p lines: roads, defined as names of towns they -* connect, bridge/not bridge, and length in miles -* ex: BEVERLY DANVERS N 2.9 (connects Beverly and -* Danvers, not a bridge, 2.9 miles long) -*/ - Province::Province(std::istream & source) { // Read first line of input source >> _numberOfTowns >> _numberOfRoads; @@ -32,39 +20,19 @@ Province::Province(std::istream & source) { // Read town names for (int i = 0; i < _numberOfTowns; i++) { - source >> _towns[i]._name; // This needs to be converted to vector, im not sure how exactly - //cout << "This is the name: " << &_towns[i]._name << endl; + source >> _towns[i]._name; townMap[_towns[i]._name] = i; } // Read roads for (int i = 0; i < _numberOfRoads; i++) { - std::string tail, head; - source >> tail >> head; - int tailIndex = townMap[tail]; // index of the first town - int headIndex = townMap[head]; // index of the second town - - // Get the type of road ("B" If Bridge, "N" if normal road) - char type; - source >> type; - bool isBridge = (type == 'B'); - // Not sure how to Get the type if it is a normal road (ie. Not a Bridge) - - // Length of road - double length; - source >> length; - - // Add a road to the road list - Road newRoad(headIndex, tailIndex, isBridge, length); - _roads.push_back(newRoad); - - // Add a road to two connecting towns - _towns[tailIndex]._roads.push_back(Road(headIndex, tailIndex, - isBridge, length)); - _towns[headIndex]._roads.push_back(Road(tailIndex, headIndex, - isBridge, length)); - - + string tail, head; + char bridgeFlag; + double length; + source >> tail >> head >> bridgeFlag >> length; + bool isBridge = (bridgeFlag == 'B'); + _towns[townMap.at(tail)]._roads.push_back(Road(townMap.at(head), townMap.at(tail), isBridge, length)); + _towns[townMap.at(head)]._roads.push_back(Road(townMap.at(tail), townMap.at(head), isBridge, length)); } } diff --git a/test-data/requirement1.out b/test-data/requirement1.out index 0dce589..d5d431a 100644 --- a/test-data/requirement1.out +++ b/test-data/requirement1.out @@ -1,19 +1,39 @@ -The input data is: - -Salem - Beverly 2.4 mi via bridge - Danvers 3.7 mi via bridge - Lynn 4.9 mi -Beverly - Danvers 2.9 mi - Salem 2.4 mi via bridge - Wenham 5.2 mi -Danvers - Beverly 2.9 mi - Wenham 4.2 mi - Salem 3.7 mi via bridge -Lynn - Salem 4.9 mi -Wenham - Beverly 5.2 mi - Danvers 4.2 mi + +------------------------------------------------ +---------------- New DataSet: ------------------ +------------------------------------------------ + +The input data is : + + Salem + Beverly 2.4 mi via bridge + Danvers 3.7 mi via bridge + Lynn 4.9 mi + Beverly + Danvers 2.9 mi + Salem 2.4 mi via bridge + Wenham 5.2 mi + Danvers + Beverly 2.9 mi + Wenham 4.2 mi + Salem 3.7 mi via bridge + Lynn + Salem 4.9 mi + Wenham + Beverly 5.2 mi + Danvers 4.2 mi + + + +------------------------------------------------ +---------------- New DataSet: ------------------ +------------------------------------------------ + +The input data is : + + Wenham + Hamilton 1 mi + Hamilton + Wenham 1 mi + +