fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Math
  5. {
  6. private:
  7. int num1, num2, num3, num4, num5;
  8.  
  9. public:
  10. Math(int first, int second, int third, int fourth, int fifth);
  11.  
  12. int Largest(); // Return the largest number
  13. int Smallest(); // Return the smallest number
  14. double Average(); // Return the average of the numbers
  15. int Total(); // Return the total of the numbers
  16. };
  17.  
  18. //**************************************************************
  19. // Function: Math
  20. //
  21. // Purpose:
  22. //
  23. // initialize the data in the class to those values provided by whoever calls it.
  24. //
  25. // Parameters:
  26. //
  27. // num1- first number
  28. // num2- second number
  29. // num3- third number
  30. // num4- fourth number
  31. // num5- fifth number
  32. //
  33. // Returns:
  34. //
  35. // passes the numbers
  36. //
  37. //**************************************************************
  38. Math::Math(int first, int second, int third, int fourth, int fifth)
  39. {
  40. num1 = first;
  41. num2 = second;
  42. num3 = third;
  43. num4 = fourth;
  44. num5 = fifth;
  45. }
  46.  
  47. //**************************************************************
  48. // Function: Largest
  49. //
  50. // Purpose:
  51. //
  52. // Determines the largest number
  53. //
  54. // Parameters:
  55. //
  56. // num1- first number
  57. // num2- second number
  58. // num3- third number
  59. // num4- fourth number
  60. // num5- fifth number
  61. //
  62. // Returns:
  63. //
  64. // the largest number
  65. //
  66. //**************************************************************
  67. int Math::Largest()
  68. {
  69. int answer = num1;
  70.  
  71. if (num2 > answer) answer = num2;
  72. if (num3 > answer) answer = num3;
  73. if (num4 > answer) answer = num4;
  74. if (num5 > answer) answer = num5;
  75.  
  76. return answer;
  77. }
  78.  
  79. //**************************************************************
  80. // Function: Smallest
  81. //
  82. // Purpose:
  83. //
  84. // Determines the smallest number
  85. //
  86. // Parameters:
  87. //
  88. // num1- first number
  89. // num2- second number
  90. // num3- third number
  91. // num4- fourth number
  92. // num5- fifth number
  93. //
  94. // Returns:
  95. //
  96. // the smallest number
  97. //
  98. //**************************************************************
  99. int Math::Smallest()
  100. {
  101. int answer = num1;
  102.  
  103. if (num2 < answer) answer = num2;
  104. if (num3 < answer) answer = num3;
  105. if (num4 < answer) answer = num4;
  106. if (num5 < answer) answer = num5;
  107.  
  108. return answer;
  109. }
  110.  
  111. int Math::Total()
  112. {
  113. return num1 + num2 + num3 + num4 + num5;
  114. }
  115.  
  116. double Math::Average()
  117. {
  118. return Total() / 5.0;
  119. }
  120.  
  121. // Test main
  122. int main()
  123. {
  124. Math Object1(10, 20, 30, 25, 15);
  125. Math Object2(5, 10, 6, 2, 8);
  126.  
  127. cout << "Object1 - Largest: " << Object1.Largest() << endl;
  128. cout << "Object1 - Smallest: " << Object1.Smallest() << endl;
  129. cout << "Object1 - Total: " << Object1.Total() << endl;
  130. cout << "Object1 - Average: " << Object1.Average() << endl;
  131.  
  132. cout << "Object2 - Largest: " << Object2.Largest() << endl;
  133. cout << "Object2 - Smallest: " << Object2.Smallest() << endl;
  134. cout << "Object2 - Total: " << Object2.Total() << endl;
  135. cout << "Object2 - Average: " << Object2.Average() << endl;
  136.  
  137. return 0;
  138. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Object1 - Largest: 30
Object1 - Smallest: 10
Object1 - Total: 100
Object1 - Average: 20
Object2 - Largest: 10
Object2 - Smallest: 2
Object2 - Total: 31
Object2 - Average: 6.2