BTW: This is not a Middle School Question, it is college.

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 functions: 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.

The solution I have tried is:
class ApartmentBuilding: public Building
{
private:
int numFloors;
int unitsPerFloor;
bool hasElevator;
bool hasCentralAir;
public:
ApartmentBuilding(int x,int y, bool b, bool c){
numFloors=x;
unitsPerFloor=y;
hasElevator=b;
hasCentralAir=c;
};
int getTotalUnits();
bool isLuxuryBuilding();
};

int ApartmentBuilding::getTotalUnits(){
return numFloors*unitsPerFloor;
}
bool ApartmentBuilding:: isLuxuryBuilding(){
if(hasCentralAir==true && hasElevator == true && unitsPerFloor<=2)
return true;
else
return false;
}


This, however, does not work! I get an error stating: "In file included from CTest.cpp:32:0:
c.h:1:108: error: declaration of ‘ApartmentBuilding::ApartmentBuilding(int, int, bool, bool)’ outside of class is not definition [-fpermissive]
ApartmentBuilding::ApartmentBuilding(int numFloors, int unitsPerFloor, bool hasElevator, bool hasCentralAir);"

I don't understand this... Question is from MyProgrammingLab.

Respuesta :

Answer:

class ApartmentBuilding: public Building

{

private:

int numFloors;

int unitsPerFloor;

bool hasElevator;

bool hasCentralAir;

public:

ApartmentBuilding(int x,int y, bool b, bool c){numFloors=x; unitsPerFloor=y; hasElevator=b; hasCentralAir=c;};

int getTotalUnits();

bool isLuxuryBuilding();

};

int ApartmentBuilding::getTotalUnits()

{ return numFloors*unitsPerFloor; }

bool ApartmentBuilding:: isLuxuryBuilding()

{

if(hasCentralAir==true && hasElevator == true && unitsPerFloor<=2)

return true;

else

return false;

}

Explanation:

In programming, it is essential to use the right form of command and avoid the use of unnecessary punctuation marks such as comma or space. In your code, most of the instructions are joined together and that is the reason why you are receiving an error message. The correct form of codes and arrangement is provided in the answer section.

ACCESS MORE