fork download
  1. // Assignment Question 7 Final Exam
  2. //
  3. // Name: <Tasos Paloukos>
  4. //
  5. // Class: C Programming, <Fall 2024>
  6. //
  7. // Date: <December 11, 2024>
  8.  
  9. #include <iostream>
  10. #include <algorithm> // For std::max and std::min
  11.  
  12. class NumberSet {
  13. private:
  14. int values[6];
  15.  
  16. public:
  17. // Constructor to initialize the six values
  18. NumberSet(int v1, int v2, int v3, int v4, int v5, int v6) {
  19. values[0] = v1;
  20. values[1] = v2;
  21. values[2] = v3;
  22. values[3] = v4;
  23. values[4] = v5;
  24. values[5] = v6;
  25. }
  26.  
  27. // Member function to return the largest of the six values
  28. int Largest() {
  29. int largest = values[0];
  30. for (int i = 1; i < 6; ++i) {
  31. if (values[i] > largest) {
  32. largest = values[i];
  33. }
  34. }
  35. return largest;
  36. }
  37.  
  38. // Member function to return the smallest of the six values
  39. int Smallest() {
  40. int smallest = values[0];
  41. for (int i = 1; i < 6; ++i) {
  42. if (values[i] < smallest) {
  43. smallest = values[i];
  44. }
  45. }
  46. return smallest;
  47. }
  48. };
  49.  
  50. int main() {
  51. // Example usage
  52. NumberSet numbers(10, 20, 5, 30, 25, 15);
  53.  
  54. std::cout << "Largest value: " << numbers.Largest() << std::endl;
  55. std::cout << "Smallest value: " << numbers.Smallest() << std::endl;
  56.  
  57. return 0;
  58. }
  59.  
  60.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Largest value: 30
Smallest value: 5