Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Object-oriented Programming / Exam 2 Preparation / Truck.cpp
diff options
context:
space:
mode:
1 files changed, 18 insertions, 0 deletions
-rw-r--r--Year 1/Object-oriented Programming/Exam 2 Preparation/Truck.cpp18
diff --git a/Year 1/Object-oriented Programming/Exam 2 Preparation/Truck.cpp b/Year 1/Object-oriented Programming/Exam 2 Preparation/Truck.cpp
new file mode 100644
index 0000000..a023979
--- /dev/null
+++ b/Year 1/Object-oriented Programming/Exam 2 Preparation/Truck.cpp
@@ -0,0 +1,18 @@
+#include "Truck.h"
+#include "Vehicle.h"
+
+Truck::Truck(String brand, unsigned maxSpeed) : Vehicle(brand, (maxSpeed >= 80 && maxSpeed <= 140) ? maxSpeed : 80)
+{}
+
+unsigned Truck::getSpeedOnRoad(Road road) const {
+ switch (road) {
+ case Speedy: return Vehicle::getMaxSpeed() / 4;
+ case ThirdClass: return 10;
+ case Highway: return Vehicle::getMaxSpeed() / 2;
+ }
+ return Vehicle::getMaxSpeed();
+}
+
+Truck* Truck::clone() const {
+ return new Truck(*this);
+}