Skip to content

Commit

Permalink
Completed printAll function - Still needs more testing. Also modified…
Browse files Browse the repository at this point in the history
… the main function in project5.cc
  • Loading branch information
elijahbigk77 committed Apr 18, 2022
1 parent e8066d7 commit d3689fd
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 31 deletions.
Binary file modified project5
Binary file not shown.
62 changes: 43 additions & 19 deletions project5.cc
Original file line number Diff line number Diff line change
@@ -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 <iostream>
#include <string>
#include <fstream>

#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);


}
}
31 changes: 30 additions & 1 deletion province.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;

}



43 changes: 32 additions & 11 deletions test-data/project4.out
Original file line number Diff line number Diff line change
@@ -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



0 comments on commit d3689fd

Please sign in to comment.