C++ function overloading programs


SUBMITTED BY: RavishBhatt

DATE: June 29, 2016, 8:55 a.m.

FORMAT: C++

SIZE: 677 Bytes

HITS: 543

  1. #include <iostream>
  2. using namespace std;
  3. /* Function arguments are of different data type */
  4. long add(long, long);
  5. float add(float, float);
  6. int main()
  7. {
  8. long a, b, x;
  9. float c, d, y;
  10. cout << "Enter two integers\n";
  11. cin >> a >> b;
  12. x = add(a, b);
  13. cout << "Sum of integers: " << x << endl;
  14. cout << "Enter two floating point numbers\n";
  15. cin >> c >> d;
  16. y = add(c, d);
  17. cout << "Sum of floats: " << y << endl;
  18. return 0;
  19. }
  20. long add(long x, long y)
  21. {
  22. long sum;
  23. sum = x + y;
  24. return sum;
  25. }
  26. float add(float x, float y)
  27. {
  28. float sum;
  29. sum = x + y;
  30. return sum;
  31. }

comments powered by Disqus