Answer to Question #212505 in Electrical Engineering for ali

Question #212505

Create three classes —House, Car and Mobile.

o House class should have attributes of area and location. 

o Car class should have attributes of color and registration number.

o Mobile class should have attribute of model. 

o Write an abstract class PollutionEffect with only a pure virtual getPollutionEffect method. 

o Each of the three classes should inherit from this abstract class and implement the 

getPollutionEffect method to print an appropriate pollution effect count for that class. 

o The getPollutionEffect of House class should print “one”, Car class should print “Two” and 

Mobile class should print “Three”.

o Write an application that creates objects of each of the three classes, places pointers to those 

objects in a array of PollutionEffect pointers, then iterates through the array, invoking each 

object’s getPollutionEffect method.


1
Expert's answer
2021-07-02T07:34:01-0400
#include <iostream>
#include <string>


using namespace std;


class PollutionEffect  
{
public:
	virtual void getPollutionEffect()=0;
	
};


class House:public PollutionEffect  
{
private:
	//House class should have attributes of area and location. 
	float area;
	string location;
public:
	void getPollutionEffect(){
		cout<<"One\n";
	}
	
};


class Car:public PollutionEffect  
{
private:
	// Car class should have attributes of color and registration number.
	string color;
	string registrationNumber;
public:
	void getPollutionEffect(){
		cout<<"Two\n";
	}
	
};


class Mobile:public PollutionEffect  
{
private:
	//Mobile class should have attribute of model. 
	string model;
public:
	void getPollutionEffect(){
		cout<<"Three\n";
	}
	
};




int main (){
	//array of PollutionEffect pointers
	PollutionEffect** pollutionEffects=new PollutionEffect*[3];
	pollutionEffects[0]=new House();
	pollutionEffects[1]=new Car();
	pollutionEffects[2]=new Mobile();
	for(int i=0;i<3;i++){
		pollutionEffects[i]->getPollutionEffect();
	}


	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS