#include <iostream>
using namespace std;
class Math
{
private:
int num1; // one of the private data numbers
int num2; // another one
int num3; // the third one
int num4;
int num5;
public:
Math (int first, int second, int third, int fourth, int fifth); // the class constructor
int Largest(); // member to return the largest number
int Smallest();
float Average();
int Total();
};
Math::Math (int first, int second, int third, int fourth, int fifth)
{
num1 = first; // save the first int
num2 = second; // save the second int
num3 = third; // save the third int
num4 = fourth; // save the fourth int
num5 = fifth; // save the fifth int
return;
}
int Math::Largest()
{
int answer = num1; // answer will be the largest we find
// assume the first is the largest
if (num2 > answer) // if the second number is larger
answer = num2; // then update the answer
if (num3 > answer) // now look at the third number
answer = num3; // update the answer if we found a greater one
if (num4 > answer)
answer = num4;
if (num5 > answer)
answer = num5;
return answer; // return the answer to the caller
}
int Math::Smallest()
{
int answer = num1; // answer will be the smallest we find
// assume the first is the smallest
if (num2 < answer) // if the second number is smaller
answer = num2; // then update the answer
if (num3 < answer) // now look at the third number
answer = num3; // update the answer if we found a lesser one
if (num4 < answer)
answer = num4;
if (num5 < answer)
answer = num5;
return answer; // return the answer to the caller
}
float Math::Average()
{
float answer = ((num1 + num2 + num3 + num4 + num5) / 5);
return answer;
}
int Math::Total()
{
int answer = num1 + num2 + num3 + num4 + num5;
return answer;
}
int main() {
Math Object1 (10, 20, 30, 40, 50); // The object type is Math, the object is called Object1
Math Object2 (5, 10, 6, 15, 14); // The object type is Math, the object is called Object2
// find the largest number in the first object (Object1) and print it out
// use the cout object to print the information
int large;
large = Object1.Largest();
int small = Object1.Smallest();
int average = Object1.Average();
int total = Object1.Total();
cout << "Largest is " << large << endl;
cout << "Smallest is " << small << endl;
cout << "Average is " << average << endl;
cout << "Total is " << total << endl;
// now do the same for the second object (Object2)
large = Object2.Largest();
small = Object2.Smallest();
average = Object2.Average();
total = Object2.Total();
cout << "Largest is " << large << endl;
cout << "Smallest is " << small << endl;
cout << "Average is " << average << endl;
cout << "Total is " << total << endl;
// all done, so return
return 0;
}