-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlightPlan.cpp
88 lines (71 loc) · 1.92 KB
/
FlightPlan.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// Created by Sammy Timmins on 10/26/20.
//
#include <iomanip>
#include "FlightPlan.h"
FlightPlan::FlightPlan()
{
totalPrice = 0.00;
totalTime = 0;
}
FlightPlan::FlightPlan(const FlightPlan ©)
{
totalPrice = copy.totalPrice;
totalTime = copy.totalTime;
flights = copy.flights;
}
FlightPlan &FlightPlan::operator=(const FlightPlan ©)
{
totalPrice = copy.totalPrice;
totalTime = copy.totalTime;
flights = copy.flights;
return *this;
}
ostream &operator<<(ostream &os, FlightPlan &plan) {
os << plan.flights.at(0).getDest() << " -> ";
for(int i = 1; i < plan.flights.getSize() - 1; i++)
{
os << plan.flights.at(i).getDest() << " (" << plan.flights.at(i).getAirline()
<< ")" << " -> ";
}
os << fixed << setprecision(2) << plan.flights.at(plan.flights.getSize() - 1).getDest()
<< " (" << plan.flights.at(plan.flights.getSize() - 1).getAirline() << ")"
<< ". Time: " << plan.totalTime << " Cost: $" << plan.totalPrice << endl;
return os;
}
/**
* sets the flight plan
*/
void FlightPlan::addPlan(const DSLinkedList<Flight> plan)
{
for(int i = 0; i < plan.getSize(); i++)
{
flights.add(plan.at(i));
}
}
/**
* calculates the time and price of the flight plan including layovers
*/
void FlightPlan::calculateTimeAndPrice()
{
for(int i = 0; i < flights.getSize(); i++)
{
totalPrice += flights.at(i).getPrice();
totalTime += flights.at(i).getTime();
}
totalTime += (flights.getSize() - 2) * 43;
totalPrice += (flights.getSize() - 2) * 19.00;
}
/**
* returns if the this member's price is greater than the parameter's price
*/
bool FlightPlan::comparePrice(const FlightPlan &f2) {
return totalPrice > f2.totalPrice;
}
/**
* returns if the this member's time is greater than the parameter's time
*/
bool FlightPlan::compareTime(const FlightPlan &f2)
{
return totalTime > f2.totalTime;
}