Website Summary Files Commits Branches @commit @diff @stats
path: root / Week09 / Exercise01 / Locomotive.cpp
diff options
context:
space:
mode:
Commitb38346eebca9a007971af02fb3bb9472c5e16d0c (patch)
Author
 Syndamia <kamen@syndamia.com>
2026-04-26 21:43:31 +0300
Committer
 Syndamia <kamen@syndamia.com>
2026-04-26 21:43:31 +0300
Files575a64089a17be271aec84683f426252d8f5d1f9 /Week09/Exercise01/Locomotive.cpp
oop-2025-solutions-b38346eebca9a007971af02fb3bb9472c5e16d0c.tar
oop-2025-solutions-b38346eebca9a007971af02fb3bb9472c5e16d0c.tar.gz
oop-2025-solutions-b38346eebca9a007971af02fb3bb9472c5e16d0c.zip
Parent7d98b664c9e459a08f2e6e6fa5b636686dfed554 (diff)
feat(Week09): Add solutions
1 files changed, 81 insertions, 0 deletions
-rw-r--r--Week09/Exercise01/Locomotive.cpp81
diff --git a/Week09/Exercise01/Locomotive.cpp b/Week09/Exercise01/Locomotive.cpp
new file mode 100644
index 0000000..2475126
--- /dev/null
+++ b/Week09/Exercise01/Locomotive.cpp
@@ -0,0 +1,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;
+}