Question #211990

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.


Expert's answer

#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);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS