Question

Hello! I need help with this problem! I noticed it's been answered before but I need...

Hello! I need help with this problem! I noticed it's been answered before but I need a different version!

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 override the 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

Below are the classes I have defined based on the requirements from your question. I did not understand what do in main, so I have just used main function to test the classes declared and all are working fine. I am including the classes here, define your main function for whatever use you need. Thank you!

CODE:

#####################################


class Building
{
protected:
double energy_consumed;
public:
Building(){}
Building(double e) {
energy_consumed = e;
}
void set_energy_consumed(double e) {
energy_consumed = e;
}
double get_energy_consumed() {
return energy_consumed;
}
virtual double computerEnergyConsumption() {
return energy_consumed;
}
};

class SolarBuilding: public Building
{
private:
double solar_power;
public:
SolarBuilding(){}
SolarBuilding(double e) {
solar_power = e;
}
void set_solar_power(double e) {
solar_power = e;
}
double get_solar_power() {
return solar_power;
}
double computerEnergyConsumption() {
return solar_power;
}
};

class WindMill: public Building
{
private:
double wind_power;
public:
WindMill(){}
WindMill(double e) {
wind_power = e;
}
void set_wind_power(double e) {
wind_power = e;
}
double get_wind_power() {
return wind_power;
}
double computerEnergyConsumption() {
return wind_power;
}
};

######################################

Add a comment
Know the answer?
Add Answer to:
Hello! I need help with this problem! I noticed it's been answered before but I need...
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
  • 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...

  • 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 an abstract class “Student” and three concrete classes, “UnderGrad” and “Graduate” both inherit from Student...

    Write an abstract class “Student” and three concrete classes, “UnderGrad” and “Graduate” both inherit from Student and “PostGraduate” that inherits form “Graduate”. Write the class definition for the abstract class “Student”. The class definition should include private instance variables of type String to hold the student’s first name, a string for his/her major and an int to hold the number of units taken. Getter and setter methods for each of the variables should be included in the class definition. Also...

  • Hi I need help doing this problem *The program must re-prompt as long as invalid input...

    Hi I need help doing this problem *The program must re-prompt as long as invalid input is inserted Implement a program that manages shapes. Implement a class named Shape with a virtual function area()which returns the double value. Implement three derived classes named Diamond, Oval, and Pentagon. Declare necessary properties in each including getter and setter function and a constructor that sets the values of these properties. Override the area() function in each by calculating the area using the defined...

  • Hello I need help with this questions about C++ programming - If a function is called...

    Hello I need help with this questions about C++ programming - If a function is called and passed a pointer variable as a parameter, how must that pointer variable be passed if the function is to modify its contents? - When must a class provide a getter for a member variable? - An inline function saves processing time, but at what expense?

  • This is in Java, thanks! d Define two subclasses as below: 1) “Advanced Java” with an...

    This is in Java, thanks! d Define two subclasses as below: 1) “Advanced Java” with an additional field called “grades_in_class” 2) “Web Technology” with an additional field called “grades_Quizzes”. Define the required constructors and getter methods in both classes. e Override the computeGrade() in both classes as below: 1. In Advanced Java, Fgrade= 40%* avg_exams+ 40%* avg_Assignments + 20* grades_in_class 2. In Web Technology, Fgrade= 30%* avg_exams+ 50%* avg_Assignments + 20*grades_Quizzes Note: Fgrade is a local variable in the computeGrade()...

  • Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named...

    Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...

  • JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class...

    JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare (); } The prepare method will...

  • JAVA Problem:  Coffee do not use ArrayList or Case Design and implement a program that manages coffees....

    JAVA Problem:  Coffee do not use ArrayList or Case Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare ();...

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