blob: 88322a2a263cf4d175c710364a4f64bd3eeddd3b (
plain) (
blame)
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
|
#ifndef _TRAIN
#define _TRAIN
class Train {
unsigned carriages;
unsigned seatsAvailable;
unsigned passengersOnBoard;
unsigned passedStops;
unsigned upcomingStops;
double ticketPrice;
double earnings;
// Излишно, но е добре да следваме "шаблона"
void free() {}
void copyFrom(const Train& other) {
carriages = other.carriages;
seatsAvailable = other.seatsAvailable;
passengersOnBoard = other.passengersOnBoard;
passedStops = other.passedStops;
upcomingStops = other.upcomingStops;
ticketPrice = other.ticketPrice;
earnings = other.earnings;
}
public:
// "Шаблон" за голямата четворка
Train() {
carriages = seatsAvailable = passengersOnBoard = passedStops = upcomingStops = ticketPrice = earnings = 0;
}
~Train() {
free();
}
Train(const Train& other) {
copyFrom(other);
}
Train& operator=(const Train& other) {
if (this != &other) {
free();
copyFrom(other);
}
return *this;
}
Train(unsigned carriages, unsigned seatsAvailable, unsigned upcomingStops, double ticketPrice) {
this->carriages = carriages;
this->seatsAvailable = seatsAvailable;
this->passengersOnBoard = 0;
this->passedStops = 0.0;
this->upcomingStops = upcomingStops;
this->ticketPrice = ticketPrice;
this->earnings = 0.0;
}
void ArriveAtStation(unsigned passengersGettingOff, unsigned passengersGettingOn);
void Print();
unsigned GetCarriages() {
return carriages;
}
void SetCarriages(unsigned carriages) {
this->carriages = carriages;
}
unsigned GetSeatsAvailable() {
return seatsAvailable;
}
void SetSeatsAvailable(unsigned seatsAvailable) {
this->seatsAvailable = seatsAvailable;
}
unsigned GetPassengersOnBoard() {
return passengersOnBoard;
}
void SetPassengersOnBoard(unsigned passengersOnBoard) {
this->passengersOnBoard = passengersOnBoard;
}
unsigned GetPassedStops() {
return passedStops;
}
void SetPassedStops(unsigned passedStops) {
this->passedStops = passedStops;
}
unsigned GetUpcomingStops() {
return upcomingStops;
}
void SetUpcomingStops(unsigned upcomingStops) {
this->upcomingStops = upcomingStops;
}
double GetTicketPrice() {
return ticketPrice;
}
void SetTicketPrice(double ticketPrice) {
this->ticketPrice = ticketPrice;
}
double GetEarnings() {
return earnings;
}
void SetEarnings(double earnings) {
this->earnings = earnings;
}
};
#endif /* _TRAIN */
|