Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 71 additions & 38 deletions Port.cpp
Original file line number Diff line number Diff line change
@@ -1,53 +1,86 @@
#include "Port.h"

Port::Port()
{
this->name=" ";
this->departure_time="00/00/00";
this->arrival_time="00/00/00";
using namespace std;

Port::Port() {
// Default Constructor
// Input - N/A
// Prints - N/A
// Returns - Constructed Port {this}
this->name = " ";
this->departure_time = "00/00/00";
this->arrival_time = "00/00/00";
}

Port::Port(const std::string& name,const std::string& arrival_time,const std::string& departure_time)
{
this->name=name;
this->arrival_time=arrival_time;
this->departure_time=departure_time;
Port::Port(const string &name, const string &arrival_time, const string &departure_time) {
// Value Constructor
// Input -
// string &name = The name of the Port
// string &arrival_time = Arrival time at Port, in "DD/MM hh:mm" format.
// string &departure_time = Departure time from Port, in "DD/MM hh:mm" format.
// Prints - N/A
// Returns - Constructed Port {this}
this->name = name;
this->arrival_time = arrival_time;
this->departure_time = departure_time;
}

Port::Port(const Port& source)
{
this->name=source.name;
this->arrival_time=source.arrival_time;
this->departure_time=source.departure_time;
this->outbound=source.outbound;

Port::Port(const Port &source) {
// Copy Constructor
// Input - const Port &source = Reference of Port to copy.
// Prints - N/A
// Returns - Constructed Port {this}
this->name = source.name;
this->arrival_time = source.arrival_time;
this->departure_time = source.departure_time;
this->outbound = source.outbound;
operator=(source);
}

Port& Port::operator=(const Port& source)
{
if(this!=&source)
{
this->name=source.name;
this->arrival_time=source.arrival_time;
this->departure_time=source.departure_time;
this->outbound=source.outbound;
}
return *this;
Port &Port::operator=(const Port &source) {
// Assignment Operator
// Input - const Port &source = Reference of Port to copy.
// Prints - N/A
// Returns - Newly copied Port& {this}
// TODO: Same function as Copy Constructor. Could it be used instead?
if (this != &source) {
this->name = source.name;
this->arrival_time = source.arrival_time;
this->departure_time = source.departure_time;
this->outbound = source.outbound;
}
return *this;
}

bool Port:: operator==(const Port& source){return (this->name==source.name);}
bool Port::operator!=(const Port& source){return!(this->name==source.name);}







Port &Port::operator=(const Port &&source) {
// Move Constructor
// Input - const Port &&source = Reference of Port to move.
// Prints - N/A
// Returns - Newly moved Port& {this}
// TODO: Apply move semantics.
}

bool Port::operator==(const Port &source) {
// Equals Operator
// Input - const Port &source = Port to compare this to.
// Prints - bool = Are they equal? (Do they have the same name?)
// Returns - N/A
return (this->name == source.name);
}

bool Port::operator!=(const Port &source) {
// Unequals Operator
// Input - const Port &source = Port to compare this to.
// Prints - bool = Are they unequal? (Do they have different names?)
// Returns - N/A
return !(this->name == source.name);
}

Port::~Port()
{

Port::~Port() {
// Destructor
// Input - N/A
// Prints - N/A
// Returns - N/A
// TODO: Is vector correctly removed from memory using smart pointers?
}
46 changes: 26 additions & 20 deletions Port.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,42 @@
#include <iterator>
#include <memory>

using namespace std;

class Port
{
private:
std::string name;
std::vector<std::shared_ptr<Port>>outbound;
std::string arrival_time;
std::string departure_time;
class Port {
private:
string name; // Name of Port
vector<shared_ptr<Port>> outbound; // Vector of Outbound connections to Port
string arrival_time; // Arrival time at Port ("DD/MM hh:mm" format)
string departure_time; // Departure time at Port ("DD/MM hh:mm" format)

public:
Port();
Port(const std::string& name,const std::string& arrival_time,const std::string& departure_time);
Port(const Port& source);
Port(Port&& source);
public:
Port(); //Default Constructor

std::string get_name(){return this->name;}
std::string get_arrival_time(){return this->arrival_time;}
std::string get_departure_time(){return this->departure_time;}
Port(const string &name, const string &arrival_time, const string &departure_time); // Value Constructor

Port& operator=(const Port& source);
Port& operator=(const Port&& source);
Port(const Port &source); // Copy Constructor

bool operator==(const Port& source);
bool operator!=(const Port& source);
Port(const Port &&source); // Move Constructor

string getName() { return this->name; } // {name} getter

string getArrivalTime() { return this->arrival_time; } // {arrival_time} getter

string getDepartureTime() { return this->departure_time; } // {departure_time} getter

~Port();
Port &operator=(const Port &source); // Assignment Operator

Port &operator=(const Port &&source); // Move Operator

bool operator==(const Port &source); // Equals Operator

bool operator!=(const Port &source); // Unequals Operator


~Port(); // Destructor


};

#endif
26 changes: 18 additions & 8 deletions Route.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#include "Route.h"

Route::Route(const Port& src,const Port& des,int weight)
{
this->src=src;
this->des=des;
this->weight=weight;
using namespace std;

Route::Route(const Port &src, const Port &des, int weight) {
// Value Constructor
// Input -
// const Port &src = Reference of source Port to set.
// const Port &des = Reference of destination Port to set.
// int weight = Weight of route (avg. # of minutes to cross)
// Prints - N/A
// Returns - Constructed Route
this->src = src;
this->des = des;
this->weight = weight;
}

void Route::printRoute()
{
std::cout<<this->src.get_name()<<"------->"<<this->des.get_name()<<" "<<this->get_weihgt()<<std::endl;
void Route::printRoute() {
// Prints function
// Input - N/A
// Prints - Route data ("{src.name} ----> {des.name} {weight}" format.)
std::cout << this->src.get_name() << "------->" << this->des.get_name() << " " << this->get_weight() << endl;
}
22 changes: 11 additions & 11 deletions Route.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include "Port.h"

class Route
{
private:
Port src; //source port
Port des; //destination port
int weight;
class Route {
private:
Port src; // Source Port
Port des; // Destination Port
int weight; //Route Weight

public:
Route(const Port& src,const Port& des,int weight);
public:
Route(const Port &src, const Port &des, int weight); // Value Constructor

int get_weihgt(){return this->weight;}
int getWeight() { return this->weight; } // {weight} getter.

int updateWeight(int newWeight);
void printRoute();
int setWeight(int newWeight); // {weight} setter.

void printRoute(); // Prints function.

};
26 changes: 21 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
#include "my_utility.h"
#include "Route.h"

int main(int argc, char *argv[])
{
checkInput(argc,argv);
//printMenu();
//|-> "Port.h"
// |--> <iostream>
// |--> <algorithm>
// |--> <vector>
// |--> <iterator>
// |--> <memory>

int main(int argc, char *argv[]) {
//checkInput(argc, argv);
cout << "Enter Word #1" << endl;
string nextLine;
string nextWord;
getline(cin, nextLine);
nextWord = getNextWord(nextLine, nextLine);

cout << "Word #1 = " << nextWord << endl;
//cout << "Enter Word #2" << endl;
cout << "Rest of Line = " << nextLine << endl;
cout << "Press Enter to terminate." << endl;
getline(cin, nextWord);
//printMenu();
}


Expand Down
Loading