Question: Code from previous lab: #include // #include Vehicle.cpp using namespace std; class Vehicle { public: virtual ~Vehicle() { cout float calculateRange() { return currentCharge *


Code from previous lab:
#include
class Vehicle { public: virtual ~Vehicle() { cout
float calculateRange() { return currentCharge * 100 / engineEfficiency; } float percentEnergyRemaining() { return (currentCharge / maximumCharge) * 100.0f; } void drive(float km) { if (currentCharge
class GasolineVehicle :virtual public Vehicle { public: int currentGasoline; int maximumGasoline; float engineEfficiency; GasolineVehicle(int maxEnergy, int rating) { engineEfficiency = rating; maximumGasoline = maxEnergy; currentGasoline = maxEnergy; } ~GasolineVehicle() { cout
} };
class HybridVehicle :public ElectricVehicle, public GasolineVehicle { public: // hybridvehicle constructor is calling its parent class constructors; HybridVehicle(int maxGasoline, float gasefficiency, int maxcharge, float electricefficiency) :GasolineVehicle(maxGasoline, gasefficiency), ElectricVehicle(maxcharge, electricefficiency) {} ~HybridVehicle() { cout 0) { currentCharge -= (km / 100) * ElectricVehicle::engineEfficiency; } else { currentGasoline -= (km / 100) * GasolineVehicle::engineEfficiency; }
} };
Vehicle* testVehicle(Vehicle* pvehicle, const char* vehicleName) { cout calculateRange() drive(150); cout percentEnergyRemaining() calculateRange()
return pvehicle; }
int main(int argc, char const* argv[]) { delete testVehicle(new GasolineVehicle(50, 7.1), "Corolla"); delete testVehicle(new HybridVehicle(42, 4.3, 8.8, 22.0), "Prius"); delete testVehicle(new ElectricVehicle(75, 16), "Tesla 3"); return 0; }
CST8219-C++ Programming Lab 7 Introduction: The goal of this lab is to practice templates, and using the standard template library Reference: Week 7 Powerpoint materials on Brightspace. There are many reference websites at the end of the powerpoint slides. Steps: 1. Take your classes from Lab 6 (HybridVehicle, Electric Vehicle, Gasoline Vehicle, Vehicle) and make them templated so that the variables engineEfficiency, currentCharge, maxCharge, currentGasoline, and maxGasoline can be whatever data type that passed in. 2. Take your testVehicle function from lab 6 and replace it with this templated function: template
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
