blob: 247512612473c549b06a0e4dc2496f8d01ce860a (
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
|
#include "Locomotive.h"
#include <cstring>
unsigned Locomotive::GetID() const {
return ID;
}
void Locomotive::SetID(unsigned ID) {
this->ID = ID;
}
const char* Locomotive::GetManufacturer() const {
return manufacturer;
}
void Locomotive::SetManufacturer(const char manufacturer[MAX_LEN]) {
strncpy(this->manufacturer, manufacturer, MAX_LEN);
}
const char* Locomotive::GetModel() const {
return model;
}
void Locomotive::SetModel(const char model[MAX_LEN]) {
strncpy(this->model, model, MAX_LEN);
}
int Locomotive::GetYearOfManufacture() const {
return yearOfManufacture;
}
void Locomotive::SetYearOfManufacture(int yearOfManufacture) {
this->yearOfManufacture = yearOfManufacture;
}
double Locomotive::GetLength() const {
return length;
}
void Locomotive::SetLength(double length) {
this->length = length;
}
unsigned short Locomotive::GetCyllinders() const {
return cyllinders;
}
void Locomotive::SetCyllinders(unsigned short cyllinders) {
this->cyllinders = cyllinders;
}
bool Locomotive::GetSupportsMultipleWorking() const {
return supportsMultipleWorking;
}
void Locomotive::SetSupportsMultipleWorking(bool supportsMultipleWorking) {
this->supportsMultipleWorking = supportsMultipleWorking;
}
// Тази функция не е нужно да бъде приятелска, можеше просто да използваме
// константните селектори.
std::ofstream& operator<<(std::ofstream& ostr, const Locomotive& loc) {
ostr << "Train #" << loc.ID << std::endl
<< "+ Model: " << loc.model << std::endl
<< "+ Manufacturer: " << loc.manufacturer << std::endl
<< "+ Year of manufacture: " << loc.yearOfManufacture << std::endl
<< "- Length: " << loc.length << std::endl
<< "- Engine cyllinders: " << loc.cyllinders << std::endl
<< "- Multiple working: " << (loc.supportsMultipleWorking ? "Yes" : "No") << std::endl;
return ostr;
}
// Тазу функция не е нужно да бъде приятелска, можеше просто да използваме
// мутаторите.
std::ifstream& operator>>(std::ifstream& istr, Locomotive& loc) {
istr >> loc.ID;
istr.getline(loc.model, MAX_LEN);
istr.getline(loc.manufacturer, MAX_LEN);
istr >> loc.yearOfManufacture >> loc.length >> loc.cyllinders >> loc.supportsMultipleWorking;
return istr;
}
|