c++
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.
Define another derived class, a single family house that could be initialized with a constructor as a single story house which is a single cube and two story house which one cube on top of another. Create two objects, one object is a single story house, another object is a two story house.
SourceCode::
#include<bits/stdc++.h>
using namespace std;
//base class
class house
{
string type;
public:
house()
{
}
};
//derived class ApartmentBuilding
class ApartmentBuilding : public house
{
//members
int numFloors,unitsPerFloor;
bool hasElevator,hasCentralAir;
public:
//Constructor
ApartmentBuilding(int nF,int
uF,bool hE,bool hC)
{
numFloors=nF;
unitsPerFloor=uF;
hasElevator=hE;
hasCentralAir=hC;
}
//member functions
int getTotalUnits()
{
return
numFloors*unitsPerFloor;
}
bool isLuxuryBuilding()
{
bool
temp=hasElevator&&hasCentralAir&&(numFloors<=2);
return
temp;
}
};
//another derived class
class singlefamilyhouse:public house
{
int cubes;
public:
singlefamilyhouse(int temp)
{
cubes=temp;
}
void show()
{
if(cubes==1)
cout<<"Single story house\n";
else
if(cubes==2)
cout<<"Two
story house\n";
}
};
int main()
{
ApartmentBuilding
AB1(2,2,true,true),AB2(3,3,true,false);
//printing statements
cout<<"Total ubits in AB1 buildings are:
"<<AB1.getTotalUnits()<<endl;
if(AB1.isLuxuryBuilding())
cout<<"AB1 is luxury building\n";
else
cout<<"AB1 is not luxury building\n";
cout<<"Total ubits in AB2 buildings are:
"<<AB2.getTotalUnits()<<endl;
if(AB2.isLuxuryBuilding())
cout<<"AB2 is luxury building\n";
else
cout<<"AB2 is not luxury building\n";
singlefamilyhouse sfh1(1),sfh2(2);
sfh1.show();
sfh2.show();
return 0;
}
Output::

//if you got your answer then pleease like the question
c++ Define a derived class, ApartmentBuilding that contains four (4) data members: an integer named numFloors,...
C++ In the code cell below, define a class named Student with an integer id and a string name. This class should have a constructor that takes two arguments: one for the id and the other for the name. Then Create another class named CollegeStudent that publicly inherits from Student. This class should have a protected member named major. It should also have a constructor that takes three arguments: id, name, and major. This constructor should delegate initializing the id...
Code the following Program in C++ Define a class named Payment that contains a member variable of type float that stores the amount of the payment and appropriate accessor and mutator methods. Also create a member function named paymentDetails that outputs an English sentence that describes the amount of the payment. Next define a class named CashPayment that is derived from Payment. This class should redefine the paymentDetails function to indicate that the payment is in cash. Include appropriate constructor(s)....
Design a class named NumDays, to store a value that represents a number of hours and convert it to a number of days. For example, 24 hours would be converted to 1 day, 36 hours would be converted to 1.5 days, and 54 hours would be converted to 2.25 days. This class has two private member variables with data type double: one is named as hours; another is named as days. This class has a constructor that accepts a value...
Define a class named COMPLEX for complex numbers, which has two private data members of type double (named real and imaginary) and the following public methods: 1- A default constructor which initializes the data members real and imaginary to zeros. 2- A constructor which takes two parameters of type double for initializing the data members real and imaginary. 3- A function "set" which takes two parameters of type double for changing the values of the data members real and imaginary....
Hello! This is C++. Q3. Write a program Define a Super class named Point containing: An instance variable named x of type int. An instance variable named y of type int. Declare a method named toString() Returns a string representation of the point. Constructor that accepts values of all data members as arguments. Define a Sub class named Circle. A Circle object stores a radius (double) and inherit the (x, y) coordinates of its center from its super class Point....
Construct a class named Fractions containing two integer data members named num and denom, used to store the numerator and denominator of a fraction having the form num/denom. Your class should include a default constructor that initializes num and denom to 1 if there's no user initialization, and it must prohibit a 0 denominator value. In addition, create member functions for displaying an object's data values and overloaded operator functions for adding, subtracting, multiplying, and dividing two Fraction objects, as...
1. Define a class Rectangle with two attributes: (This is for C++) -length, an integer (default value 1) -width, an integer (default value 1) Provide the following member functions: -default constructor -constructor that takes parameters used to initialize the data -get/set function for each attribute -a function perimeter that returns the perimeter of the rectangle -a function area that returns the area of the rectangle b. Write a program that uses the class Rectangle to create two rectangle objects with...
C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...
IN C++ PLEASE Write a class LuckyNumberChecker. Include a constructor that accepts an integer named luckyDivisor Add a virtual method named checkNumber that accept an integer named number and returns a string If the number argument is evenly divisible by the luckyDivisor, return "This number is lucky" otherwise, if the number is odd, return "This number might be lucky" otherwise, return "this number is not lucky" Write a class DoublyLuckyNumberChekcer that extends LuckyNumberChecker Add a constructor that accepts two integers,...
this is a c++ program Define a class Money with two integer data members, dollars and cents. Member functions: Overload arithmetic operators (+ and -), and return new Money objects; Non-member functions: Overload comparison operators (<, >, !=, and ==), and return boolean values; Write a main function to test your code.