Sun Nov 10 2019
Function Overloading
C++ Programming2212 views
File Name: function-overloading.cpp
#include<iostream>
using namespace std;
/* First function with the name "perimeter" and return 'long' */
long perimeter(int r) {
return 2*(22/7)*r;
}
/* Second function with the name "perimeter" and return 'double' */
double perimeter(int l , int w) {
return 2*(l+w);
}
/* Third function with the name "perimeter" and return 'int' */
int perimeter(int a, int b, int c) {
return a+b+c;
}
int main() {
cout << "Perimeter of Circle: " << perimeter(5) << endl;
cout << "Perimeter of Rectangle: " << perimeter(10,20) << endl;
cout << "Perimeter of Triangle: " << perimeter(5,10,15) << endl;
return 0;
}
/* Output */
Perimeter of Circle: 30
Perimeter of Rectangle: 60
Perimeter of Triangle: 30
Reference:
Author:Geekboots