From 71c57cde42e99301aeb079be4ef368ff155f99c5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 25 May 2022 14:05:56 +0300 Subject: Added my prep work for exam2 --- .../Exam 2 Preparation/Truck.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Year 1/Object-oriented Programming/Exam 2 Preparation/Truck.cpp (limited to 'Year 1/Object-oriented Programming/Exam 2 Preparation/Truck.cpp') 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); +} -- cgit v1.3.1-23-gd82d