fork download
  1. /*write an overloaded findMAX function that:
  2. returns the maximum two integers
  3. returns the maximum of float point integers
  4. returns the maximum of three integers*/
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. class MaxFinder {
  9. public:
  10. // Method to find max of two integers
  11. int findMAX(int a, int b) {
  12. return (a > b) ? a : b;
  13. }
  14.  
  15. // Method to find max of two floats
  16. float findMAX(float a, float b) {
  17. return (a > b) ? a : b;
  18. }
  19.  
  20. // Method to find max of three integers
  21. int findMAX(int a, int b, int c) {
  22. int max = (a > b) ? a : b;
  23. return (max > c) ? max : c;
  24. }
  25. };
  26.  
  27. int main() {
  28. MaxFinder maxFinder;
  29. int choice;
  30.  
  31. cout << "Choose an option:\n";
  32. cout << "1. Max of two integers\n";
  33. cout << "2. Max of two floats\n";
  34. cout << "3. Max of three integers\n";
  35. cout << "Enter your choice (1-3): ";
  36. cin >> choice;
  37.  
  38. switch (choice) {
  39. case 1: {
  40. int a, b;
  41. cout << "Enter two integers: ";
  42. cin >> a >> b;
  43. cout << "Maximum is: " << maxFinder.findMAX(a, b) << endl;
  44. break;
  45. }
  46. case 2: {
  47. float a, b;
  48. cout << "Enter two float numbers: ";
  49. cin >> a >> b;
  50. cout << "Maximum is: " << maxFinder.findMAX(a, b) << endl;
  51. break;
  52. }
  53. case 3: {
  54. int a, b, c;
  55. cout << "Enter three integers: ";
  56. cin >> a >> b >> c;
  57. cout << "Maximum is: " << maxFinder.findMAX(a, b, c) << endl;
  58. break;
  59. }
  60. default:
  61. cout << "Invalid choice!" << endl;
  62. }
  63.  
  64. return 0;
  65. }
  66.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Choose an option:
1. Max of two integers
2. Max of two floats
3. Max of three integers
Enter your choice (1-3): Invalid choice!