Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Must be in C++ (CarbonFootprint Abstract Class: Polymorphism) using an abstract

ID: 3662477 • Letter: M

Question

Must be in C++

(CarbonFootprint Abstract Class: Polymorphism) using an abstract class with only pure virtual functions, you can specify similar behaviors for possibly disparate classes. Governments and companies worldwide are becoming increasingly concerned with carbon footprints (annual releases of carbon dioxide into the atmosphere) from buildings burning various types of fuels for heat, vehicles burning fuels for power, and the like. Many scientists blame these greenhouse gases for the phenomenon called global warming. 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 (check out a few websites that explain how to calculate carbon footprint). Write an application that creates objects of the three classes, places pointers to those objects in a vector of CarbonFootprint pointers, then iterates through the vector, polymorphically invoking each object's getCarbonFootprint method. For each object, print some identifying information and the object's carbon footprint.

I need:

CarbonFootprint.h

CarbonFootprint .cpp

Building.h

Building.cpp

Car.h

Car.cpp

Bicycle.h

Bicycle.cpp

main.cpp

Thank you.

Explanation / Answer

#include <iostream>
#include <vector>
using namespace std;

int main()
{

vector< CarbonFootprint* > list;

// add elements to list
list.push_back( new Bicycle() );
list.push_back( new Building( 2500 ) );
list.push_back( new Car( 10 ) );

// display carbon footprint of each object
for ( size_t i = 0; i < list.size(); ++i ){
//TODO: polymorphically invoking each object¡¯s getCarbonFootprint method

}

// release elements of list
for ( size_t i = 0; i < list.size(); ++i ){
//TODO: release elements in the list
CarbonFootprint* ptr;
delete ptr;
}

} // end main

class Building
{};

class Car
{};

class Bicycle
{};

class CarbonFootprint
{
protected:

public:

virtual void getCarbonFootprint() = 0;

void getCarbonFootprint()
{

}
};