#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; // the fourth one
int num5; // the fifth one
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 ();
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;
}
//
// The second member function is Largest. It examines the data held by the
// class and returns the largest of the three data values.
//
int Math::Largest ()
{
int answer; // answer will be the largest we find
answer = num1; // 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; // answer will be the smallest we find
answer = num1; // 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::Total () {
int answer; // answer will be the smallest we find
answer = num1 + num2 + num3 + num4 + num5; // assume the first is the largest
return answer;
}
#include <iostream>
using namespace std;
int main ()
{
Math Object1 (10, 20, 30, 90, 150); // The object type is Math, the object is
// called Object1
Math Object2 (5, 10, 6, 3, 6); // The object type is Math, the object is
// called Object2
int solution;
solution = Object1.Largest();
cout << "Largest is " << solution << endl;
// now do the same for the second object (Object2)
solution = Object2.Largest();
cout << "Largest is " << solution << endl;
solution = Object1.Smallest();
cout << "Smallest is " << solution << endl;
// now do the same for the second object (Object2)
solution = Object2.Smallest();
cout << "Smallest is " << solution << endl;
solution = Object1.Total();
cout << "Total is " << solution << endl;
// now do the same for the second object (Object2)
solution = Object2.Total();
cout << "Total is " << solution << endl;
return 0;
}