Create a class home with following data members, area (int), and cost as protected data
member. Create a class (with data members as city, state) derived from this bass class home.
Enter the detail for 5 objects (derived) and search with state to display all the homes available.
#include <iostream>
using namespace std;
class Home{
protected:
int area;
double cost;
};
class MyHome: public Home{
private:
string city;
string state;
public:
MyHome(int a, double co, string c, string s){
area=a;
cost=co;
city=c;
state=s;
}
void displayDetails(){
cout<<"Area: "<<area;
cout<<"Cost: "<<cost;
cout<<"City: "<<city;
}
void searchHomes(){
string st;
cout<<"Enter state: ";
cin>>st;
if (state==st){
displayDetails();
}
}
};
int main(){
MyHome d1(23,34450.5,"Phoenix","Arizona");
MyHome d2(11,78900.0,"Jacksonville","Florida");
MyHome d3(18,34560.0,"Atlanta","Georgia");
MyHome d4(21,89000.0,"Portland","Maine");
MyHome d5(23,68900.5,"Honolulu"," Hawaii");
d1.searchHomes();
d2.searchHomes();
d3.searchHomes();
d4.searchHomes();
d5.searchHomes();
return 0;
}
Comments
Leave a comment