-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlight.cpp
More file actions
113 lines (92 loc) · 3.88 KB
/
Flight.cpp
File metadata and controls
113 lines (92 loc) · 3.88 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "Flight.h"
#include <cmath>
#include <iomanip>
Flight::Flight()
: flightId("Неизвестен"), departure("Неизвестен"), destination("Неизвестен"), distance(0), flightDuration(0) {}
Flight::Flight(const std::string& flightId, const std::string& departure, const std::string& destination,
double distance, const Aircraft& aircraft,int passengers)
: flightId(flightId), departure(departure), destination(destination), distance(distance), aircraft(aircraft), passengers(passengers)
{
calculateFlightDuration();
}
std::string Flight::getFlightId() const {
return flightId;
}
void Flight::setFlightId(const std::string& flightId) {
if (flightId.empty()) {
throw std::invalid_argument("ID на полета не може да бъде празен.");
}
this->flightId = flightId;
}
std::string Flight::getDeparture() const {
return departure;
}
void Flight::setDeparture(const std::string& departure) {
if (departure.empty()) {
throw std::invalid_argument("Мястото на заминаване не може да бъде празно.");
}
this->departure = departure;
}
std::string Flight::getDestination() const {
return destination;
}
void Flight::setDestination(const std::string& destination) {
if (destination.empty()) {
throw std::invalid_argument("Дестинацията не може да бъде празна.");
}
this->destination = destination;
}
double Flight::getDistance() const {
return distance;
}
void Flight::setDistance(double distance) {
if (distance <= 0) {
throw std::invalid_argument("Разстоянието трябва да бъде положително.");
}
this->distance = distance;
}
double Flight::calculateFlightDuration() {
flightDuration = distance / aircraft.getAircraftClass().getAverageSpeed();
flightDuration = std::round(flightDuration * 100) / 100;
return flightDuration;
}
double Flight::calculateFlightCost() const {
return aircraft.calculateFlightCost(distance, aircraft.getAircraftClass().getSeats());
}
void Flight::setAircraft(const Aircraft& aircraft) {
this->aircraft = aircraft;
}
Aircraft Flight::getAircraft() const {
return aircraft;
}
int Flight::getPassengers() const {
return passengers;
}
void Flight::setPassengers(int passengers) {
if (passengers <= 0) {
throw std::invalid_argument("Броя на пасажерите трябва да бъде положителен.");
}
this->passengers = passengers;
}
void Flight::checkPassengersCompatibility() const {
if (passengers > aircraft.getAircraftClass().getSeats()) {
throw std::invalid_argument("Броя на пасажерите e прекалено голямо за този самолет, самолета не е съвместим");
}
}
void Flight::checkAircraftCompatibility() const {
if (distance > aircraft.getAircraftClass().calculateMaxFlightDistance()) {
throw std::invalid_argument("Разстоянието e прекалено голямо за този самолет, самолета не е съвместим");
}
}
std::ostream& operator<<(std::ostream& os, const Flight& flight) {
os << "Информация за полета:\n"
<< "ID на полета: " << flight.flightId << "\n"
<< "От: " << flight.departure << "\n"
<< "До: " << flight.destination << "\n"
<< "Разстояние: " << flight.distance << " км\n"
<< "Продължителност на полета: " << flight.flightDuration << " часа\n"
<< "Извъшва се с самолет : " << flight.getAircraft().getAircraftId()<< " \n"
<< "Брой пътници : " << flight.getPassengers()<< " \n"
<< "Цена на полета: " << std::fixed << std::setprecision(0) << flight.calculateFlightCost() << " $\n";
return os;
}