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

Assume the existence of a Building class . Define a derived class , ApartmentBui

ID: 3541903 • Letter: A

Question

Assume  the existence of a Building class . Define a derived class , ApartmentBuilding that contains four (4) data members: an integer  named  numFloors, an integer  named  unitsPerFloor, a boolean  named  hasElevator, and a boolean  named  hasCentralAir. There is a constructor  containing parameters  for the initialization  of the above variables  (in the same order as they appear above). There are also two function: the first, getTotalUnits, accepts no parameters  and returns the total number of units in the building; the second, isLuxuryBuilding accepts no parameters  and returns true  if the building has central air, an elevator and 2 or less units per floor.

Explanation / Answer

#include<iostream>
using namespace std;
class Building
{
};
class ApartmentBuilding : public Building
{
private:
int numFloors;
int unitsPerFloor;
bool hasElevator;
bool hasCentralAir;
public:
ApartmentBuilding(int nf=0,int upf=0,bool he=false,bool hca=false)
{
numFloors = nf;
unitsPerFloor = upf;
hasElevator = he;
hasCentralAir = hca;
}
int getTotalUnits()
{
return numFloors*unitsPerFloor;
}
bool isLuxuryBuilding()
{
if(hasCentralAir && hasElevator && unitsPerFloor<=2) return true;
return false;
}
};

int main()
{
ApartmentBuilding AB(4,1,true,true);
cout << "is ApartmentBuilding AB is Luxury Building ? " << (AB.isLuxuryBuilding()?"yes":"no") << endl;
cout << "Total Number of units in ApartmentBuilding AB are " << AB.getTotalUnits() << endl;
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