diff --git a/project5 b/project5 index cf35b8d..e7437f6 100755 Binary files a/project5 and b/project5 differ diff --git a/project5.cc b/project5.cc index 4b8cacb..b29a904 100644 --- a/project5.cc +++ b/project5.cc @@ -1,27 +1,51 @@ -/** - * @file project5.cc - * @author Elijah Opoku-Nyarko and Jake Colbert - * @brief - * @version 0.1 - * @date 2022-04-14 - * - * @copyright Copyright (c) 2022 - * - * Project 5 main file - */ +/* +* @file: project5.cc +* +*@brief: +* Main program for CPS222 project 5 - test driver to read in a graph +* from standard input and test the read graph +* +* @Authors: Elijah Opoku-Nyarko & Jake Colbert +*/ #include #include -#include - -#include "province.h" +#include "./province.h" using namespace std; -int main() { - while(!cin.eof()) { - Province theProvince(cin); - theProvince.printAll(0, cout); - } +/* +* 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; + } } +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); + + std::cout << std::endl; + std::cout << "------------------------------------------------" << std::endl; + std::cout << "---------------- New DataSet: ------------------" << std::endl; + std::cout << "------------------------------------------------" << std::endl; + std::cout << std::endl; + + theProvince.printAll(0, cout); + + + } +} diff --git a/province.cc b/province.cc index 55f0948..44ab552 100644 --- a/province.cc +++ b/province.cc @@ -33,7 +33,7 @@ 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; + //cout << "This is the name: " << &_towns[i]._name << endl; townMap[_towns[i]._name] = i; } @@ -88,6 +88,35 @@ void Province::printAll(int start, std::ostream & output) { output << " "; output << _towns[current]._name << endl; + + // Enqueue current vertex's unscheduled neighbors + for (Town::RoadList::iterator neighbor = _towns[current]._roads.begin(); + neighbor != _towns[current]._roads.end(); neighbor++) { + std::string neighborName = _towns[neighbor->_head]._name; + + output << " "; + output << neighborName << " " << neighbor->_length << " mi"; + + // if the type is bridge, then add to output + if (neighbor ->_isBridge) { + output << " via bridge"; + } + + output << endl; + + int head = neighbor ->_head; + + // If neighbour is not scheduled, add neighbor to the queue + if (!scheduled[head]) { + toVisit.push(head); + scheduled[head] = true; + } + } } + output << endl << endl; + } + + + diff --git a/test-data/project4.out b/test-data/project4.out index 1673102..54ed61d 100644 --- a/test-data/project4.out +++ b/test-data/project4.out @@ -1,18 +1,39 @@ -This is the name: 0x600000610008 -This is the name: 0x600000610038 -This is the name: 0x600000610068 -This is the name: 0x600000610098 -This is the name: 0x6000006100c8 + +------------------------------------------------ +---------------- New DataSet: ------------------ +------------------------------------------------ + The input data is: Salem -This is the name: 0x600001110008 -This is the name: 0x600001110038 + 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 -This is the name: 0x600001110078 -This is the name: 0x6000011100a8 -The input data is: + Hamilton 1 mi + Hamilton + Wenham 1 mi + -