1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream>
#include <string>
using std::string;
using std::ostream;
using std::cout;
using std::endl;
class House
{
public:
House
(//Constructor Argument List
const string& street,
int streetNumber,
int amountOfApartments,
int floors,
int entrances,
int amountOnAFloor,
const string& dateStart,
const string& dateEnd,
const string& constructionCompanyName
//Initializer List
) : m_street(street),
m_streetNumber(streetNumber),
m_amountOfApartments(amountOfApartments),
m_floors(floors),
m_entrances(entrances),
m_amountOnAFloor(amountOnAFloor),
m_dateStart(dateStart),
m_dateEnd(dateEnd),
m_constructionCompanyName(constructionCompanyName)
{}
//the << operator does not know what to do with a house object since
//it is a custom type, so we tell it
//what we want it to do using the operator keyword
//This way we can simply cout FamilyHome object instead of creating
//tons of getters and typing out all the data for each house object
friend ostream& operator<<(ostream& os, House& house)
{
os << "Street: " << house.m_street << endl;
os << "Street #: " << house.m_streetNumber << endl;
os << "Number of Apartments: " << house.m_amountOfApartments << endl;
os << "Floors: " << house.m_floors << endl;
os << "Entrances: " << house.m_entrances << endl;
os << "Amount on a floor: " << house.m_amountOnAFloor << endl;
os << "Construction Date Start: " << house.m_dateStart << endl;
os << "Construction Date End: " << house.m_dateEnd << endl;
os << "Construction Company Name: " << house.m_constructionCompanyName << endl;
return os;
}
private:
//Create variables and initialize them to a default value
string m_street{ "Street Name" };
int m_streetNumber{ 123 };
int m_amountOfApartments{ 1 };
int m_floors{ 3 };
int m_entrances{ 2 };
int m_amountOnAFloor{ 4 };
string m_dateStart{ "2/12/2021" };
string m_dateEnd{ "4/15/2021" };
string m_constructionCompanyName{ "Company Name" };
};
int main()
{
House FamilyHome("Elm", 123, 4, 3, 2, 3, "2/13/2021", "4/20/2021", "Freddy's Dream Builds");
cout << FamilyHome << endl;
return 0;
}
|