Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class named RealEstate that has data members to hold the price of a hou

ID: 3556039 • Letter: C

Question

Create a class named RealEstate that has data members to hold the price of a house, the number of bedrooms, and the number of baths. Member functions include overloaded insertion and extraction operations. Write a main() function that instantiates a RealEstate object, allows the user to enter data, and displays the data members entered. The main() function should display an appropriate thrown error message if the non-numeric or negative values are entered for any of the data members. Save as RealEstate.cpp

Explanation / Answer

// Save as RealEstate.cpp
#include<iostream>
using namespace std;
// Create a class named RealEstate that has data members to hold the price of a house, the number of bedrooms, and the number of baths.
class RealEstate
{
//Member functions include overloaded insertion and extraction operations.
friend istream& operator>>(istream& in,RealEstate& R);
friend ostream& operator<<(ostream& out,RealEstate R);
private:
double price_of_house;
int number_of_bedrooms;
int number_of_bathrooms;
};
istream& operator>>(istream& in,RealEstate& R)
{
    in >> R.price_of_house >> R.number_of_bedrooms >> R.number_of_bathrooms;
   return in;
}
ostream& operator<<(ostream& out,RealEstate R)
{  
   out << "Price of House is " << R.price_of_house <<" and number of bedrooms is " << R.number_of_bedrooms << " number of bath rooms " <<
   R.number_of_bathrooms << endl;
   return out;
}
//Write a main() function that instantiates a RealEstate object, allows the user to enter data, and displays the data members entered.
int main()
{
//The main() function should display an appropriate thrown error message if the non-numeric or negative values are entered for any of the data members.
RealEstate new_R;
cout << "Enter price, number of bed rooms and number of bathrooms :";
cin >> new_R;
cout <<endl;
cout << new_R;
//system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote