Create a program that will overload a function four (4) times. The function takes a single parameter but each parameter is different in each function.
#include <iostream>
using namespace std;
int sum(int a, int b);
int sum(int a);
double sum(int a, double b);
double sum(double a, double b);
int main()
{
cout << sum(4, 5) << endl;
cout << sum(5) << endl;
cout << sum(5, 7.65) << endl;
cout << sum(8.85, 9.61) << endl;
return 0;
}
int sum(int a, int b)
{
return a + b;
}
int sum(int a)
{
return a + a;
}
double sum(int a, double b)
{
return a + b;
}
double sum(double a, double b)
{
return a + b;
}
Comments
Leave a comment