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 // #include "Vehicle.cpp" using namespace std;

class Vehicle { public: virtual ~Vehicle() { cout float calculateRange() { return

Code from previous lab:

#include // #include "Vehicle.cpp" using namespace std;

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 T testVehiclet pVehicle, const char *vehicleName) { cout calculateRange() drive(150); //drive 150 km cout percentEnergyRemaining() calculateRange() (50,7.1), "Corolla"); 1/42 L of gas, 4.3 L/100km, 8.8kWh, 22 kWh/100km delete testVehicle new HybridVehicle(42, 4.3, 8.8, 22.0), "Prius" ); 1/75 kWh, 16 kWh/100km delete testVehicle( new Electricvehicle(75, 16), "Tesla 3"); cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!