Skip to content

Commit

Permalink
Merge branch 'main' into ShortestPath_Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
elijahbigk77 authored Apr 23, 2022
2 parents dcc033d + 2860e2e commit fa7dca4
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 84 deletions.
47 changes: 47 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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

3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
47 changes: 23 additions & 24 deletions project5.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,33 @@ 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);


}
}
}
48 changes: 8 additions & 40 deletions province.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
}

Expand Down
58 changes: 39 additions & 19 deletions test-data/requirement1.out
Original file line number Diff line number Diff line change
@@ -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


0 comments on commit fa7dca4

Please sign in to comment.