Create three small classes unrelated by inheritance classes Building, Car and Bicycle. Give each class some unique appropriate attributes and behaviors that it does not have in common with other classes. Write an abstract class CarbonFootprint with only a pure virtual getCarbonFootprint method. Have each of your classes inherit from that abstract class and implement the getCarbonFootprint method to calculate an appropriate carbon footprint for that class. Write an application that creates objects of each of the three classes, places pointers to those objects in an array of CarbonFootprint pointers, then iterates through the array. For each object, print some identifying information and the object’s carbon footprint. Residential. On average, electricity sources emit 1.004 lbs CO2 per kWh (0.0004554 metric tons CO2 per kWh). Vehicles. Unleaded gasoline emits 19.64 lbs of CO2 per gallon. https://carbonfund.org/how-we-calculate/ (Links to an external site.) Bicycle. emits 0.440925 lbs a mile https://www.theguardian.com/environment/2010/jun/08/carbon-footprint-cycling (Links to an external site.) Design: Code: Output:
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Create three small classes unrelated by inheritance classes Building, Car and Bicycle. Give each class some unique appropriate attributes and behaviors that it does not have in common with other classes. Write an abstract class CarbonFootprint with only a pure virtual getCarbonFootprint method. Have each of your classes inherit from that abstract class and implement the getCarbonFootprint method to calculate an appropriate carbon footprint for that class. Write an application that creates objects of each of the three classes, places pointers to those objects in an array of CarbonFootprint pointers, then iterates through the array. For each object, print some identifying information and the object’s carbon footprint.
Residential. On average, electricity sources emit 1.004 lbs CO2 per kWh (0.0004554 metric tons CO2 per kWh).
Vehicles. Unleaded gasoline emits 19.64 lbs of CO2 per gallon.
https://carbonfund.org/how-we-calculate/ (Links to an external site.)
Bicycle. emits 0.440925 lbs a mile
https://www.theguardian.com/environment/2010/jun/08/carbon-footprint-cycling (Links to an external site.)
Design:
Code:
Output:
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images