From b78b2c749c9799c2e13becb0d544ff7e1673a49e Mon Sep 17 00:00:00 2001 From: Elijah Opoku-Nyarko Date: Thu, 14 Apr 2022 13:08:41 -0400 Subject: [PATCH] added public class to .h file --- province.cc | 33 +++++++++++++++++++++++++++++++++ province.h | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 province.cc diff --git a/province.cc b/province.cc new file mode 100644 index 0000000..2308b5c --- /dev/null +++ b/province.cc @@ -0,0 +1,33 @@ +/* +* Implentation of Province.h +* Authors: Elijah Opoku-Nyarko and Jake Colbert +*/ + +#include "./province.h" +#include +#include +#include + +/* +* 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 nameMap; + + // Read town names + for (int i = 0; i < _numberOfTowns; i++) { + source >> _towns[i]._name; + nameMap[_towns[i]._name] = i; + } \ No newline at end of file diff --git a/province.h b/province.h index 22b0670..e43ec97 100644 --- a/province.h +++ b/province.h @@ -55,6 +55,47 @@ class Province std::vector bfs(int start) const; void dfsAux(int current, std::vector & 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 RoadList; + RoadList _roads; + }; - \ No newline at end of file + int _numberOfTowns; + int _numberOfRoads; + Town *_towns; + std::vector _roads; +};