Website Summary Files Commits Branches @commit @diff @stats
path: root / Week10 / Exercise02 / Vehicle.cpp
diff options
context:
space:
mode:
Commit7546f0d0da487e16f0a8671c09a46e1cee2bc03a (patch)
Author
 Syndamia <kamen@syndamia.com>
2026-05-02 14:57:36 +0300
Committer
 Syndamia <kamen@syndamia.com>
2026-05-02 14:57:36 +0300
Files6462868cebe114a87ca38252af9a49bce6603286 /Week10/Exercise02/Vehicle.cpp
oop-2025-solutions-7546f0d0da487e16f0a8671c09a46e1cee2bc03a.tar
oop-2025-solutions-7546f0d0da487e16f0a8671c09a46e1cee2bc03a.tar.gz
oop-2025-solutions-7546f0d0da487e16f0a8671c09a46e1cee2bc03a.zip
Parentc98c633b7087e3c52f4b05236f3509a9ec5f2bba (diff)
feat(Week10): Add solutions
1 files changed, 74 insertions, 0 deletions
-rw-r--r--Week10/Exercise02/Vehicle.cpp74
diff --git a/Week10/Exercise02/Vehicle.cpp b/Week10/Exercise02/Vehicle.cpp
new file mode 100644
index 0000000..bbc6bf0
--- /dev/null
+++ b/Week10/Exercise02/Vehicle.cpp
@@ -0,0 +1,74 @@
+#include "Vehicle.h"
+#include <cstring>
+
+Vehicle::Vehicle() : model(), yearOfManufacture(), mileage(), ecoCategory(), weight(), horsePower() {
+ type = 0;
+}
+
+const char* Vehicle::GetModel() const {
+ return model;
+}
+
+void Vehicle::SetModel(char model[MODEL_LENGTH]) {
+ strcpy(this->model, model);
+}
+
+unsigned Vehicle::GetYearOfManufacture() const {
+ return yearOfManufacture;
+}
+
+void Vehicle::SetYearOfManufacture(unsigned yearOfManufacture) {
+ this->yearOfManufacture = yearOfManufacture;
+}
+
+double Vehicle::GetMileage() const {
+return mileage;
+}
+
+void Vehicle::SetMileage(double mileage) {
+ this->mileage = mileage;
+}
+
+unsigned short Vehicle::GetEcoCategory() const {
+ return ecoCategory;
+}
+
+void Vehicle::SetEcoCategory(unsigned short ecoCategory) {
+ this->ecoCategory = ecoCategory;
+}
+
+double Vehicle::GetWeight() const {
+ return weight;
+}
+
+void Vehicle::SetWeight(double weight) {
+ this->weight = weight;
+}
+
+double Vehicle::GetHorsePower() const {
+ return horsePower;
+}
+
+void Vehicle::SetHorsePower(double horsePower) {
+ this->horsePower = horsePower;
+}
+
+std::ostream& operator<<(std::ostream& ostr, const Vehicle& vehicle) {
+ ostr << vehicle.model << std::endl
+ << "Manufactured: " << vehicle.yearOfManufacture << std::endl
+ << "Mileage: " << vehicle.mileage << std::endl
+ << "Eco category: " << vehicle.ecoCategory << std::endl
+ << "Weight: " << vehicle.weight << std::endl
+ << "Horse power: " << vehicle.horsePower << std::endl;
+ return ostr;
+}
+
+std::istream& operator>>(std::istream& istr, Vehicle& vehicle) {
+ istr.getline(vehicle.model, MODEL_LENGTH);
+ istr >> vehicle.yearOfManufacture
+ >> vehicle.mileage
+ >> vehicle.ecoCategory
+ >> vehicle.weight
+ >> vehicle.horsePower;
+ return istr;
+}