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{
int feet;
int inches;
int height;
int objs[10];
public:
void READ(){
cout<<"\nEnter height: ";
for(int i=0;i<10;i++){
cin>>height;
objs[i]=height;
}
}
void MIN(){
int min=objs[0];
for(int i=0;i<10;i++){
if (objs[i]<min)
min=objs[i];
}
cout<<"\nMIN:"<<min;
}
void MAX(){
int max=objs[0];
for(int i=0;i<10;i++){
if (objs[i]>max)
max=objs[i];
}
cout<<"\nMAX:"<<max;
}
void AVG(){
int sum=0;
for(int i=0;i<10;i++){
sum=sum+objs[i];
}
cout<<"\nAVG:"<<sum/10;
}
};
int main()
{
HEIGHT h;
h.READ();
h.MIN();
h.MAX();
h.AVG();
return 0;
}
Comments
Leave a comment