Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions