Skip to content

Commit

Permalink
Peer programmed progress for Lab 12 - Jake and Elijah
Browse files Browse the repository at this point in the history
  • Loading branch information
jakedcolbert committed Apr 14, 2022
1 parent b78b2c7 commit a834494
Show file tree
Hide file tree
Showing 20 changed files with 574 additions and 15 deletions.
92 changes: 91 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,95 @@
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.excludeSearch": [],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false
"C_Cpp_Runner.warningsAsError": false,
"files.associations": {
"iostream": "cpp",
"map": "cpp",
"__string": "cpp",
"ios": "cpp",
"__bit_reference": "cpp",
"__bits": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__nullptr": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__tuple": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ostream": "cpp",
"queue": "cpp",
"random": "cpp",
"ratio": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"variant": "cpp",
"vector": "cpp",
"__functional_base": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"utility": "cpp",
"*.tcc": "cpp",
"memory_resource": "cpp",
"stop_token": "cpp"
}
}
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Author: Elijah Opoku-Nyarko and Jake Colbert

# default target
all: project4

# compile the code into an executable called 'project1' using C++ 2011
project4: project4.cc
g++ -std=c++11 -o project4 project4.cc

# test the code against an expected output file
# this test should grow into a spaceship and end with blinkers
test-nowhere:
./project4 < test-files/t01-nowhere.in > tests/project4.out
diff test-files/project4.out test-files/t01-nowhere.out > test.diff
wc -l test.diff
27 changes: 27 additions & 0 deletions project5.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @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
*/

#include <iostream>
#include <string>
#include <fstream>

#include "province.h"

using namespace std;


int main() {
while(!cin.eof()) {
Province province(cin);
}
}

42 changes: 33 additions & 9 deletions province.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

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

using namespace std;

/*
* Constructor
* @param source File containing province:
Expand All @@ -19,15 +22,36 @@
* 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;
// Read first line of input
source >> _numberOfTowns >> _numberOfRoads;
std::map<std::string, int> townMap; // maps town names to their indexes in _towns

// Read town names
for (int i = 0; i < _numberOfTowns; i++) {
source >> _towns.push_back(Town()); // This needs to be converted to vector, im not sure how exactly
townMap[_towns[i]._name] = i;
}

for (int i = 0; i < _numberOfRoads; i++) {
string head, tail;
char bridge;
float distance;
source >> head >> tail >> bridge >> distance;
// add a road to the _roads array that belongs to the town at the index map.at(head) returns
_towns[townMap.at(head)]._roads.push_back(Road(townMap.at(head), townMap.at(tail), bridge, distance));
}
}

void Province::printAll(int start, std::ostream & output) const{
output << "The input data is:" << endl << endl;

_towns = new Town[_numberOfTowns];
std::map<std::string, int> nameMap;
for (Town town : _towns) {
output << _towns[i]._name << endl;
for (Road road : _towns[i]._roads) {
output << "\t" << endl; // needs to be finished too
}

// Read town names
for (int i = 0; i < _numberOfTowns; i++) {
source >> _towns[i]._name;
nameMap[_towns[i]._name] = i;
}
}
}
14 changes: 9 additions & 5 deletions province.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <map>
#include <queue>


// re-evaluate security of these classes


/**
* towns connected by roads
*/
Expand Down Expand Up @@ -47,7 +51,7 @@ class Province
/**
* Destructor
*/
~Province() { delete [] _towns; }
~Province() {}

private:

Expand All @@ -70,13 +74,13 @@ class Province
* @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)
Road(int head, int tail, char isBridge, double length)
: _head(head), _tail(tail), _isBridge(isBridge), _length(length)
{}

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

bool operator < (Road road2) const;
Expand All @@ -88,14 +92,14 @@ class Province
*/
class Town
{
public:
public: // consider making some of these private (RoadList)
std::string _name;
typedef std::list <Road> RoadList;
RoadList _roads;
};

int _numberOfTowns;
int _numberOfRoads;
Town *_towns;
std::vector<Town> _towns;
std::vector<Road> _roads;
};
9 changes: 9 additions & 0 deletions test-data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Mac files
.DS_Store

# Mac + Google Drive files
Icon?

# Emacs backup and temp files
*~
\#*\#
10 changes: 10 additions & 0 deletions test-data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# cps222p5-test-data

This repo provides sample input and output files for testing your
Project 5 code. Much more test data is needed to ensure your
code works. Remember: **if you haven't tested it, it doesn't work.**

* .in: sample input
* .out: expected output for matching input. Please match the format of each line exactly, by comparing your output to this with the "diff" command. Try to make the output line order match, too. But if you are confident your code is producing correct output in a different valid order, that is acceptable.

There is also a .jpg image of a diagram of some input.
2 changes: 2 additions & 0 deletions test-data/t01-nowhere.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 0
NOWHERESVILLE
20 changes: 20 additions & 0 deletions test-data/t01-nowhere.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The input data is:

NOWHERESVILLE

The shortest paths from NOWHERESVILLE are:


The road upgrading goal can be achieved at minimal cost by upgrading:

Connected components in event of a major storm are:
If all bridges fail, the following towns would form an isolated group:
NOWHERESVILLE

Destruction of any of the following would result in the province becoming
disconnected:
(None)


------------------------------------------------------------------

4 changes: 4 additions & 0 deletions test-data/t02-one-road.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
2 1
Wenham
Hamilton
Wenham Hamilton N 1
28 changes: 28 additions & 0 deletions test-data/t02-one-road.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
The input data is:

Wenham
Hamilton 1 mi
Hamilton
Wenham 1 mi

The shortest paths from Wenham are:

The shortest path from Wenham to Hamilton is 1 mi:
Wenham
Hamilton

The road upgrading goal can be achieved at minimal cost by upgrading:
Hamilton to Wenham

Connected components in event of a major storm are:
If all bridges fail, the following towns would form an isolated group:
Wenham
Hamilton

Destruction of any of the following would result in the province becoming
disconnected:
(None)


------------------------------------------------------------------

6 changes: 6 additions & 0 deletions test-data/t03-simple.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
3 2
A
B
C
A B B 1
B C B 1
41 changes: 41 additions & 0 deletions test-data/t03-simple.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
The input data is:

A
B 1 mi via bridge
B
A 1 mi via bridge
C 1 mi via bridge
C
B 1 mi via bridge

The shortest paths from A are:

The shortest path from A to B is 1 mi:
A
B
The shortest path from A to C is 2 mi:
A
B
C

The road upgrading goal can be achieved at minimal cost by upgrading:
B to A
C to B

Connected components in event of a major storm are:
If all bridges fail, the following towns would form an isolated group:
A

If all bridges fail, the following towns would form an isolated group:
B

If all bridges fail, the following towns would form an isolated group:
C

Destruction of any of the following would result in the province becoming
disconnected:
B


------------------------------------------------------------------

12 changes: 12 additions & 0 deletions test-data/t05-local.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
5 6
Salem
Wenham
Beverly
Danvers
Lynn
Beverly Danvers N 2.9
Beverly Salem B 2.4
Beverly Wenham N 5.2
Danvers Wenham N 4.2
Danvers Salem B 3.7
Lynn Salem N 4.9
Loading

0 comments on commit a834494

Please sign in to comment.