Create a class in C++ name Height with the following Data members
Feet
Inches
The Height class presents Height in Feet and Inches. For instance, Height (4, 3) means 4 feet and 3 inches. The Height class you will design should have the following features.
Constructors
Class must have
1. Default constructor, which must set Feet and Inches to zero.
2. Parameterized constructor that receives one parameter of type int (that will be height in form of inches) converts the arguments into feet and inches and initializes its private data: feet and inches with them.
3. Parameterized constructor that receives two parameter of type int initializes its private data: feet and inches with them. Note that if inches are 12 or greater than 12 then also convert it in feet.
Member functions
Provide the following member functions:
getFeet
returns the feet data member.
getInches
returns the inches data member.
display
display the height of object in terms of feet and inches
Math operators
The class must overload the following operators
Plus (+)
Post increment (++)
Equal (==)
Greater than (>)
Plus (+)
There should be two overloaded + operators
1) Add two objects and return Height object. Note that inches should not exceed 12.
2) Add first number into second objects and return Height object. Note that inches should not exceed 12.
Post increment (++)
It must increase the value contained in inches variable by one. In addition, when the inches value crosses 12, it must revert to zero after increasing the Feet by one.
Equal (==)
Check that either two Height objects are equal or not. If both are equal then return true otherwise false
Greater than (>)
Check first Height object is greater than second or not and return true or false accordingly.
The following should be the main() function of your Height class as it will be used for grading your assignment .
int main()
{
Height h1;
Height h2(25);
Height h3(2,35);
Height h4(2,25);
cout<<"************h1************"<<endl;
h1.display();
cout<<"************h2************"<<endl;
h2.display();
cout<<"************h3************"<<endl;
h3.display();
cout<<"************h4************"<<endl;
h4.display();
cout<<"**************************"<<endl;
if(h2==h3)
cout<<"h2 is equal to h1"<<endl;
else if(h2>h3)
cout<<"h2 is greater than h3"<<endl;
else
cout<<"h2 is less then h3"<<endl;
cout<<"********h1=h2+h3***********"<<endl;
h1=h2+h3;
h1.display();
cout<<"********h4++***********"<<endl;
h4++;
h4.display();
cout<<"********h4=27+h3***********"<<endl;
h4=27+h3;
h4.display();
return 0;
}
And sample output will be
************h1************
Height = 0 Feet , 0 Inches
************h2************
Height = 2 Feet , 1 Inches
************h3************
Height = 4 Feet , 11 Inches
************h4************
Height = 4 Feet , 1 Inches
**************************
h2 is less then h3
********h1=h2+h3**********
Height = 7 Feet , 0 Inches
**********h4++*************
Height = 4 Feet , 2 Inches
********h4=27+h3***********
Height = 7 Feet , 2 Inches