Answer to Question #211990 in C++ for Hemambar

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.


1
Expert's answer
2021-07-01T04:00:17-0400
#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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS