-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAircraftClass.cpp
More file actions
135 lines (114 loc) · 4.6 KB
/
AircraftClass.cpp
File metadata and controls
135 lines (114 loc) · 4.6 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "AircraftClass.h"
#include <stdexcept>
AircraftClass::AircraftClass()
: manufacturer("Неизвестен"), model("Неизвестен"), seats(0), minRunwayLength(0),
fuelConsumptionPerKMPerSeat(0), fuelTankCapacity(0), averageSpeed(0) {}
AircraftClass::AircraftClass(std::string manufacturer, std::string model, int seats, double minRunwayLength,
double fuelConsumptionPerKMPerSeat, double fuelTankCapacity, double averageSpeed)
{
setManufacturer(manufacturer);
setModel(model);
setSeats(seats);
setMinRunwayLength(minRunwayLength);
setFuelConsumptionPerKMPerSeat(fuelConsumptionPerKMPerSeat);
setFuelTankCapacity(fuelTankCapacity);
setAverageSpeed(averageSpeed);
autoDetermineType();
}
void AircraftClass::autoDetermineType() {
if (seats < 100 && minRunwayLength < 2000) {
type = Type::A; // Малък самолет
} else if (seats >= 100 && seats < 200 &&
minRunwayLength >= 2000 && minRunwayLength < 3000) {
type = Type::B; // Среден самолет
} else if (seats >= 200 && seats <= 300 && minRunwayLength >= 3000) {
type = Type::C; // Голям самолет
}else throw std::invalid_argument("Несъвместим с никой клас");
}
Type AircraftClass::getType() const {
return type;
}
std::string AircraftClass::getManufacturer() const {
return manufacturer;
}
void AircraftClass::setManufacturer(const std::string& manufacturer) {
if (manufacturer.empty()) {
throw std::invalid_argument("Производителя не може да бъде празен.");
}
this->manufacturer = manufacturer;
}
std::string AircraftClass::getModel() const {
return model;
}
void AircraftClass::setModel(const std::string& model) {
if (model.empty()) {
throw std::invalid_argument("Модела не може да бъде празен.");
}
this->model = model;
}
int AircraftClass::getSeats() const {
return seats;
}
void AircraftClass::setSeats(int seats) {
if (seats <= 0) {
throw std::invalid_argument("Седалките трябва да са позитивно число");
}
this->seats = seats;
}
double AircraftClass::getMinRunwayLength() const {
return minRunwayLength;
}
void AircraftClass::setMinRunwayLength(double minRunwayLength) {
if (minRunwayLength <= 0) {
throw std::invalid_argument("Пистата трябва да е положително число");
}
this->minRunwayLength = minRunwayLength;
}
double AircraftClass::getFuelConsumptionPerKMPerSeat() const {
return fuelConsumptionPerKMPerSeat;
}
void AircraftClass::setFuelConsumptionPerKMPerSeat(double fuelConsumptionPerKMPerSeat) {
if (fuelConsumptionPerKMPerSeat <= 0) {
throw std::invalid_argument("Положително число");
}
this->fuelConsumptionPerKMPerSeat = fuelConsumptionPerKMPerSeat;
}
double AircraftClass::getFuelTankCapacity() const {
return fuelTankCapacity;
}
void AircraftClass::setFuelTankCapacity(double fuelTankCapacity) {
if (fuelTankCapacity <= 0) {
throw std::invalid_argument("Капацитета на горивото трябва да е положително число");
}
this->fuelTankCapacity = fuelTankCapacity;
}
double AircraftClass::getAverageSpeed() const {
return averageSpeed;
}
void AircraftClass::setAverageSpeed(double averageSpeed) {
if (averageSpeed <= 0) {
throw std::invalid_argument("Средната скорост трябва да е положително число");
}
this->averageSpeed = averageSpeed;
}
double AircraftClass::calculateMaxFlightDistance() const {
return fuelTankCapacity / fuelConsumptionPerKMPerSeat;
}
std::ostream& operator<<(std::ostream& os, const Type& type) {
switch (type) {
case Type::A: os << "A"; break;
case Type::B: os << "B"; break;
case Type::C: os << "C"; break;
}
return os;
}
std::ostream& operator<<(std::ostream& os, const AircraftClass& aircraftClass) {
os << "Клас на самолета\n"
<< "Клас: " << aircraftClass.type << "\n"
<< "Прозиводител: " << aircraftClass.manufacturer << "\n"
<< "Модел: " << aircraftClass.model << "\n"
<< "Седалки: " << aircraftClass.seats << "\n"
<< "Максимално разстояние: " << aircraftClass.calculateMaxFlightDistance() << " км \n"
<< "Минимална дължина на пистата: " << aircraftClass.minRunwayLength << " метра\n";
return os;
}