-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13_FuncOverloading.cpp
More file actions
52 lines (44 loc) · 1.18 KB
/
Copy path13_FuncOverloading.cpp
File metadata and controls
52 lines (44 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
using namespace std;
// Function Overloading
// Sum Function
int sum(int a, int b)
{
int c;
c = a + b;
return c;
}
int sum(int a, int b, int c)
{
return a + b + c;
}
// Volume Function
int volume(int a)
{
return (a*a*a);
}
int volume(int a, int b, int c)
{
return (a*b*c);
}
int volume(double r, int h)
{
return (3.14 * r * r * h);
}
int main()
{
cout << "Function Overloading:\n";
/* If we want to make functions with same name but different types/numbers of args compiler automatically
detects for every call by given types/number of args. If func call args doesn't match any defined function
args' types or number, then only function throws error.
*/
cout << "First Sum Function with two args as input:\n";
cout << "The sum of 7, 8 is " << sum(7, 8) << "\n";
cout << "Second Sum Function with three args as input:\n";
cout << "The sum of 7, 8, 9 is " << sum(7, 8, 9) << "\n";
cout << "Volume Function Overloaded:\n";
cout << "Volume of cube of side 3 is: " << volume(3) << endl;
cout << "Volume of cuboid of 3, 4, 5 is: " << volume(3, 4, 5) << endl;
cout << "Volume of cylinder of radius 3, height 5 is: " << volume(3, 5) << "\n";
return 0;
}