Question

Hello! I know this has been answered before but I would love a new solution for it. This would be in C++ Create a class...

Hello! I know this has been answered before but I would love a new solution for it. This would be in C++

Create a class named Building with one public pure virtual function computerEnergyConsumption() that returns a double value of the instance variable which stores the energy consumed by the building. Create the two classes SolarBuilding and WindMill that both publicly inherit from Building. SolarBuilding has an instance variable that stores the energy generated by the solar panels. WindMill has an instance variable that stores the energy generated by the windmill. All member variables from classes must have getter and setter functions. Both classes should have the member variable(s) passed in and set in the constructor. Both classes must overridethe computerEnergyConsumption() function of the base class and use the instance variables in their computation. Use appropriate access modifiers in each class to enforce information hiding.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <iomanip>
using namespace std;

class Building
{
private:
    double energyConsumed;
public:
    virtual double computeEnergyConsumption() = 0;
    double getEnergyConsumed() { return this->energyConsumed; }
};

class SolarBuilding : public Building
{
private:
    double energyGenerated;
public:
    SolarBuilding(double energyGenerated)
    {
        this->energyGenerated = energyGenerated;
    }
    double getEnergyGenerated() { return this->energyGenerated; }
    void setEnergyGenerated(double energy) { this->energyGenerated = energy; }
    double computeEnergyConsumption() { return getEnergyGenerated(); }
};

class WindMill : public Building
{
private:
    double energyGenerated;
public:
    WindMill(double energyGenerated)
    {
        this->energyGenerated = energyGenerated;
    }
    double getEnergyGenerated() { return this->energyGenerated; }
    void setEnergyGenerated(double energy) { this->energyGenerated = energy; }
    double computeEnergyConsumption() { return getEnergyGenerated(); }
};

int main()
{
    SolarBuilding solarBuilding(3560.44);
    WindMill windMill(2500.00);

    cout << setprecision(2) << fixed;
    cout << endl << "Solar Panel [Energy consumed: " << solarBuilding.computeEnergyConsumption() << " units]";
    cout << endl << "Wind Mill [Energy consumed: " << windMill.computeEnergyConsumption() << " units]" << endl;
    return 0;
}

********************************************************************* SCREENSHOT ******************************************************

Solar Panel [Energy consumed: 3560.44 units] -Wind Mill Energy consumed: 2500.00 units] Process finished with exit code 0

Add a comment
Know the answer?
Add Answer to:
Hello! I know this has been answered before but I would love a new solution for it. This would be in C++ Create a class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Help with this coding assignment for C++! Add any comments for better understanding. Create a class...

    Help with this coding assignment for C++! Add any comments for better understanding. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The constructor will initial all member variable to a default value 0. • One public pure virtual function showingredients() that returns void....

  • Please submit a .cpp file or upload zip if you have more than one file before...

    Please submit a .cpp file or upload zip if you have more than one file before the time up. No library function is allowed. ***The code must contain your name and has proper format. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The...

  • write C++ program Create a class named Bicycle with one public pure virtual function showFeatures(). Create...

    write C++ program Create a class named Bicycle with one public pure virtual function showFeatures(). Create the two classes MountainBike and BeachCruiser that both publicly inherit from Bicycle. Please add necessary member variables and functions to each class. The showFeatures() function shows the details about a bicycle. should have main.cpp Bicycle.h Bicycle.cpp  MountainBike .h  MountainBike.cpp  BeachCruiser.h  BeachCruiser.cpp

  • in C++: Create a class named Student that has three member variables: name - string that...

    in C++: Create a class named Student that has three member variables: name - string that stores the name of the student numClasses - integer that tracks how many courses the student is currently enrolled in, this number must be between 1 and 100. classList - an array of strings of size 100 used to store the names of the classes that the student is enrolled in Write the appropriate constructor(s), mutator and accessor functions for the class along with...

  • About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which...

    About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...

  • MasterMind in Java Activity MasterMind project Create a new Java Application project named MasterMind allowing Netbeans...

    MasterMind in Java Activity MasterMind project Create a new Java Application project named MasterMind allowing Netbeans IDE to create the main class called MasterMind.java MasterMind class Method main() should: Call static method System.out.println() and result in displaying “Welcome to MasterMind!” Call static method JOptionPane.showMessageDialog(arg1, arg2) and result in displaying a message dialog displaying “Let’s Play MasterMind!” Instantiate an instance of class Game() constants Create package Constants class Create class Constants Create constants by declaring them as “public static final”: public...

  • Create a class named Date in C++ Class has 3 private data items (name the data...

    Create a class named Date in C++ Class has 3 private data items (name the data items month, day, year) int month int day int year Member functions ‘getters’   a getter for each data item Use ‘get’ and the data items name The data item name must be capitalized Return the data item Example: int getMonth()        {return month;} ‘setters’   a setter for each data item Use ‘set’ and the data items name The data item name must be capitalized Change...

  • C++ Please help. 1) Create an array to store 10 Point2D points (the Point2D class from...

    C++ Please help. 1) Create an array to store 10 Point2D points (the Point2D class from A6). Set the coordinates from 0,0 to 9,9. Move all the points left 5 units and up 10 units. Print their new location. 2) Make a new class Point3D which inherits from the Point2D class. The class has one more data member for the z coordinate. There are two constructors, a default one and one with 3 coordinates. Add the new member functions getZ,...

  • Java Create four classes: 1.      An Animal class that acts as a superclass for Dog and...

    Java Create four classes: 1.      An Animal class that acts as a superclass for Dog and Bird 2.      A Bird class that is a descendant of Animal 3.      A Dog class that is a descendant of Animal 4.      A “driver” class named driver that instantiates an Animal, a Dog, and a Bird object. The Animal class has: ·        one instance variable, a private String variable named   name ·        a single constructor that takes one argument, a String, used to set...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT