fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. //************************************************************
  6. // QUESTION 7
  7. //
  8. // (C++ Program) Extend the class so it contains 5 integers and
  9. // includes Largest, Smallest, Average, and Total.
  10. //
  11. // Notes:
  12. // - This class is only compiled when using a C++ compiler.
  13. // - The guard allows the rest of the file to compile as C.
  14. //************************************************************
  15.  
  16. #ifdef __cplusplus
  17.  
  18. class FiveNumbers
  19. {
  20. private:
  21. int a, b, c, d, e;
  22.  
  23. public:
  24. FiveNumbers(int n1, int n2, int n3, int n4, int n5)
  25. {
  26. a = n1;
  27. b = n2;
  28. c = n3;
  29. d = n4;
  30. e = n5;
  31. }
  32.  
  33. int Largest()
  34. {
  35. int max = a;
  36.  
  37. if (b > max) max = b;
  38. if (c > max) max = c;
  39. if (d > max) max = d;
  40. if (e > max) max = e;
  41.  
  42. return max;
  43. }
  44.  
  45. int Smallest()
  46. {
  47. int min = a;
  48.  
  49. if (b < min) min = b;
  50. if (c < min) min = c;
  51. if (d < min) min = d;
  52. if (e < min) min = e;
  53.  
  54. return min;
  55. }
  56.  
  57. int Total()
  58. {
  59. return (a + b + c + d + e);
  60. }
  61.  
  62. double Average()
  63. {
  64. return (a + b + c + d + e) / 5.0;
  65. }
  66. };
  67.  
  68. #endif /* __cplusplus */
  69.  
  70. return 0;
  71. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty