1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <iostream>
using namespace std;
class TWO
{
private: int age[5];
public:
//read data into array
void ReadData(int age[], int n);
//member to return the average of data in array age of object p
friend int FindAverage(TWO p);
//member to find and return the max and min age
void FindMaxMin(int &maxAge, int& minAge, int age[], int n);
//display ages > age average
void DisplayAboveAverage(int ageAve, int age[], int n);
//display the max and min ages
void DisplayMaxMinAge(int maxAge, int minAge, int age[], int n);
//release all memory used by objects
~TWO() {}
};
int main()
{
int a[]; int n;
int maxAge;
int minAge;
int ageAve;
TWO x;
x.ReadData(a[],n);
FindAverage(x);
x.FindMaxMin(maxAge,minAge);
x.DisplayAboveAverage(ageAve);
x.DisplayMaxMinAge(maxAge, minAge);
return 0;
}
// class functions
void TWO :: ReadData(int x[], int n)
{
for(int i = 0; i < 5; ++i)
{ cout << "Enter 5 ages: ";
cin >> x[i];
}
}
void FindAverage(TWO p, int x[], int n)
{ int total = 0;
for(int i = 0; i < 5; ++i)
{
total += x[i];
}
}
void TWO :: FindMaxMin(int &maxAge, int& minAge, int x[], int n)
{
int maxAge = x[0];
for(int i = 0; i < 5; ++i)
if(maxAge < x[i])
maxAge = x[1];
int minAge = x[0];
for(int i = 0; i < 5; ++i)
if(minAge > x[i])
minAge = x[3];
}
void TWO :: DisplayAboveAverage(int ageAve, int x[], int n)
{
int total = 0;
for(int i = 0; i < 5; ++i)
{
total += x[i];
if(ageAve > total)
cout <<
}
}
void TWO :: DisplayMaxMinAge(int maxAge, int minAge, int x[], int n)
{
int maxAge = x[0];
for(int i = 0; i < 5; ++i)
if(maxAge < x[i])
cout << "Maximum age is " << x[1];
int minAge = x[0];
for(int i = 0; i < 5; ++i)
if(minAge > x[i])
cout << x[3];
}
|