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 Details: public Home{
private:
string city;
string state;
public:
Details(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(){
Details d1(111,34450.5,"Phoenix","Arizona");
Details d2(343,78900.0,"Jacksonville","Florida");
Details d3(789,34560.0,"Atlanta","Georgia");
Details d4(221,89000.0,"Portland","Maine");
Details d5(123,68900.5,"Honolulu"," Hawaii");
d1.searchHomes();
d2.searchHomes();
d3.searchHomes();
d4.searchHomes();
d5.searchHomes();
return 0;
}
Comments
Leave a comment