Answer to Question #187502 in C++ for Saket Singh

Question #187502

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.


1
Expert's answer
2021-04-30T16:55:06-0400
#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;
}

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
New on Blog
APPROVED BY CLIENTS