Write a program to compare two integer numbers and two single character using function overloading.
Sep 2, 2019Source code:
//function overloading program to compare
// two integer and two single characters
#include <iostream>
using namespace std;
//function prototypes
int find_greatest(int, int);
char find_greatest(char, char);
int main(){
int x1 = 10, y1 = 50;
char a1 = 'A', b1 = 'B';
cout<<"greatest among integers = "<<find_greatest(x1, y1)<<endl;
cout<<"greatest among characters = "<<find_greatest(a1, b1)<<endl;
return 0;
}
//function definations
int find_greatest(int x, int y){
if(x > y){
return x;
}else{
return y;
}
}
char find_greatest(char a, char b){
if(a > b){
return a;
}else{
return b;
}
}
Sample Run:
greatest among integers = 50 greatest among characters = B