Skip to content

Commit

Permalink
added public class to .h file
Browse files Browse the repository at this point in the history
  • Loading branch information
elijahbigk77 committed Apr 14, 2022
1 parent e986125 commit b78b2c7
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
33 changes: 33 additions & 0 deletions province.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Implentation of Province.h
* Authors: Elijah Opoku-Nyarko and Jake Colbert
*/

#include "./province.h"
#include <algorithm>
#include <stack>
#include <cfloat>

/*
* 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;

_towns = new Town[_numberOfTowns];
std::map<std::string, int> nameMap;

// Read town names
for (int i = 0; i < _numberOfTowns; i++) {
source >> _towns[i]._name;
nameMap[_towns[i]._name] = i;
}
43 changes: 42 additions & 1 deletion province.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,47 @@ class Province
std::vector<int> bfs(int start) const;
void dfsAux(int current, std::vector<int> & dfsTowns, bool visited []) const;

/**
* Road
* Contains index of originating town, whether or not is bridge,
* and length
*/
class Road
{
public:

/*
* Constructor
* @param head Index in vertex array of originating town
* @param isBridge Whether or not the road is a bridge
* @param length Length of the road in miles
*/
Road(int head, int tail, bool isBridge, double length)
: _head(head), _tail(tail), _isBridge(isBridge), _length(length)
{}

int _head; // Index of originating town in vertex array
int _tail;
bool _isBridge;
double _length;

bool operator < (Road road2) const;
};

/**
* Town
* Contains name and a list of roads that connect to it
*/
class Town
{
public:
std::string _name;
typedef std::list <Road> RoadList;
RoadList _roads;
};


int _numberOfTowns;
int _numberOfRoads;
Town *_towns;
std::vector<Road> _roads;
};

0 comments on commit b78b2c7

Please sign in to comment.