fork download
  1. #include <iostream>
  2. #include <algorithm> // For std::max and std::min
  3.  
  4. class FiveNumbers {
  5. private:
  6. int a, b, c, d, e;
  7.  
  8. public:
  9. // Constructor to initialize the 5 numbers
  10. FiveNumbers(int w, int x, int y, int z, int v) : a(w), b(x), c(y), d(z), e(v) {}
  11.  
  12. // Returns the largest of the 5 numbers
  13. int Largest() const {
  14. return std::max({a, b, c, d, e});
  15. }
  16.  
  17. // Returns the smallest of the 5 numbers
  18. int Smallest() const {
  19. return std::min({a, b, c, d, e});
  20. }
  21.  
  22. // Returns the average of the 5 numbers
  23. double Average() const {
  24. return static_cast<double>(Total()) / 5;
  25. }
  26.  
  27. // Returns the sum of the 5 numbers
  28. int Total() const {
  29. return a + b + c + d + e;
  30. }
  31. };
  32.  
  33. int main() {
  34. int w, x, y, z, v;
  35. // Read 5 integers from input
  36. std::cin >> w >> x >> y >> z >> v;
  37.  
  38. FiveNumbers nums(w, x, y, z, v);
  39.  
  40. std::cout << "Largest: " << nums.Largest() << std::endl;
  41. std::cout << "Smallest: " << nums.Smallest() << std::endl;
  42. std::cout << "Average: " << nums.Average() << std::endl;
  43. std::cout << "Total: " << nums.Total() << std::endl;
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 5316KB
stdin
100 200 300 400 500
stdout
Largest: 500
Smallest: 100
Average: 300
Total: 1500