Write a program to create a class HEIGHT with feet and inches as members. Write member
functions to READ, find the maximum height (MAX), find the minimum height (MIN) and
average height (AVG) for arrays of object.
#include<iostream>
using namespace std;
class HEIGHT
{
float inch,feet;
public:
void READ()
{
cout<<"Enter height in foot : ";
cin>>feet;
cout<<"Enter height in inches : ";
cin>>inch;
}
void MAX(HEIGHT a[])
{
int l=3,i;
float height_total[l],maxx,minn;
for( i=0;i<l;i++)
{
height_total[i]=a[i].inch+a[i].feet*12;
}
maxx = height_total[0];
for (i = 0; i < 3; i++)
{
if (maxx < height_total[i])
maxx = height_total[i];
}
minn = height_total[0];
for (i = 0; i < 3; i++)
{
if (minn > height_total[i])
minn = height_total[i];
}
cout << "Largest element : " << maxx;
}
void MIN(HEIGHT a[])
{
int l=3,i;
float height_total[l],maxx,minn;
for( i=0;i<l;i++)
{
height_total[i]=a[i].inch+a[i].feet*12;
}
maxx = height_total[0];
for (i = 0; i < 3; i++)
{
if (maxx < height_total[i])
maxx = height_total[i];
}
minn = height_total[0];
for (i = 0; i < 3; i++)
{
if (minn > height_total[i])
minn = height_total[i];
}
cout << "Smallest element : " << minn;
}
};
int main()
{
HEIGHT a[3];
for(int i=0;i<3;i++)
{
a[i].READ();
}
for(int i=0;i<3;i++)
{
a[i].MAX(a);
}
for(int i=0;i<3;i++)
{
a[i].MIN(a);
}
}
Comments
Leave a comment