Hello everyone,
I am trying to make a program which takes two integer parameters (HeightinInches,HeightinFeet) i.e. (7,30) and then displays the output by converting it into feet and inches. I am using three operators i.e. +,++, a constant integer number=27.
After compilation I got following major errors in which I stuck up and need your help :
106 D:\MCS Work\Assignment-6-NEW-C++\mc070401526.cpp `HeightinFeet' is not a type
106 D:\MCS Work\Assignment-6-NEW-C++\mc070401526.cpp request for member of non-aggregate type before '=' token
107 D:\MCS Work\Assignment-6-NEW-C++\mc070401526.cpp `HeightinInches' is not a type
107 D:\MCS Work\Assignment-6-NEW-C++\mc070401526.cpp request for member of non-aggregate type before '=' token
So, my question is how and where to describe my integer variables "heightinFeet" and "heightinInches". Note, I have described these two variables in "Private:" but it is not working.
Here is the code:
It's a time limit case guys, please response quicky. I will be waiting for your quick response.
#include<iostream.h>
using std::cout;
using std::cin;
using std::ios;
//Definition of Class
class Height
{
// Class interface
public:
// Methods & Constructors of Class
Height();
Height(int, int);
void h1(int);
void h2(int);
void h3(int, int);
void h4(int,int);
// Member Functions
int getFeet();
int getInches();
void display(int, int);
private:
int HeightinFeet;
int HeightinInches;
}; // End of class
// Constructors
Height::Height()
{
getFeet(HeightinFeet==0);
getInches(HeightinInches==0);
} // End of default constructor
void Height::h1(int HeightinInches1)
{
if (HeightinInches1 >= 12)
{
HeightinInches1=HeightinInches1-12;
HeightinInches=HeightinInches1;
HeightinFeet=HeightinFeet + 1;
}
else
{
HeightinInches = HeightinInches1;
} // end if
} // End of constructor h1
void Height::h2(int heightinFeet2, int heightinInches2)
{
if (heightinInches2 >= 12)
{
heightinInches2=heightinInches2-12;
HeightinInches=heightinInches2;
HeightinFeet=HeightinFeet + 1;
}
else
{
HeightinInches = heightinInches2;
} // end if
} // End of constructor h2
void Height::h3(int heightinFeet3, int heightinInches3)
{
if (heightinInches3 >= 12)
{
heightinInches3=heightinInches3-12;
HeightinInches=heightinInches3;
HeightinFeet=HeightinFeet + 1;
}
else
{
HeightinInches = heightinInches3;
} // end if
} // End of constructor h3
void Height::h4(int heightinFeet4, int heightinInches4)
{
if (heightinInches4 >= 12)
{
heightinInches4=heightinInches4-12;
HeightinInches=heightinInches4;
HeightinFeet=HeightinFeet + 1;
}
else
{
HeightinInches = heightinInches4;
} // end if
} // End of constructor h4
// Get member Functions
int Height::getFeet()
{
return HeightinFeet();
} // End function getFeet
int Height::getInches()
{
return HeightinInches();
} // End function getInches
// Function to display Height in Feet & Inches
void Height::display(int heightinFeet, int heightinInches)
{
cout<<"\n\n Height = "<<HeightinFeet<<" Feet "<<HeightinInches<<" Inches";
} // End display function
// HOW AND WHERE SHOULD I DELCARE THE HeightinInches & HeightinFeet;
// Declaration (prototype) of overloaded sum operator
int Height:: operator +(int h1)
{
int temp;
temp.HeightinFeet = HeightinFeet + h1.HeightinFeet;
temp.HeightinInches = HeightinInches + h1.HeightinInches;
return temp;
}
// HOW AND WHERE SHOULD I DELCARE THE HeightinInches & HeightinFeet;
// Declaration (prototype) of overloaded pre-increament operator ++ operator
int Height::operator++(int h4)
{
int temp1;
temp1.HeightinFeet = HeightinFeet++;
temp1.HeightinInches = HeightinInches++;
return temp1;
}
// HOW AND WHERE SHOULD I DELCARE THE HeightinInches & HeightinFeet;
// Declaration (prototype) of overloaded sum operator with constant number 27
int Height::operator+(int number, int h3)
{
int number = 27;
int temp2;
temp2.HeightinFeet = HeightinFeet + h3.HeightinFeet;
temp2.HeightinInches = number + h3.HeightinInches++;
return temp2;
}
// Main function starts
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.27+h3;
h4.display();
return 0;
}
Please feel free to enquire about any thing.
regards.