8000 Function Eary & Late Binding · DhirajGadekar/Cpp_programming@a233691 · GitHub
[go: up one dir, main page]

Skip to content

Commit a233691

Browse files
committed
Function Eary & Late Binding
1 parent 72ef51b commit a233691

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include<iostream>
2+
3+
void add(int x , int y) {
4+
5+
std::cout << x + y << std::endl;
6+
}
7+
8+
void sub(int x, int y) {
9+
10+
std::cout << x - y << std::endl;
11+
}
12+
13+
void mul(int x, int y) {
14+
15+
std::cout << x * y << std::endl;
16+
}
17+
int main() {
18+
19+
std::cout << "1.Add" << std::endl;
20+
std::cout << "2.Sub" << std::endl;
21+
std::cout << "3.Mul" << std::endl;
22+
23+
int choice;
24+
std::cout << "Enter Yiur Choice : " << std::endl;
25+
std::cin >> choice;
26+
27+
switch(choice) {
28+
29+
case 1:
30+
add(10, 20);
31+
break;
32+
case 2:
33+
sub(30, 20);
34+
break;
35+
36+
case 3:
37+
mul(10, 20);
38+
break;
39+
}
40+
return 0;
41+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include<iostream>
2+
3+
void add(int x , int y) {
4+
5+
std::cout << x + y << std::endl;
6+
}
7+
8+
void sub(int x, int y) {
9+
10+
std::cout << x - y << std::endl;
11+
}
12+
13+
void mul(int x, int y) {
14+
15+
std::cout << x * y << std::endl;
16+
}
17+
int main() {
18+
19+
std::cout << "1.Add" << std::endl;
20+
std::cout << "2.Sub" << std::endl;
21+
std::cout << "3.Mul" << std::endl;
22+
23+
int choice;
24+
std::cout << "Enter Yiur Choice : " << std::endl;
25+
std::cin >> choice;
26+
27+
void (*fun)(int , int) = NULL;
28+
switch(choice) {
29+
30+
case 1:
31+
fun = add;
32+
break;
33+
case 2:
34+
fun = sub;
35+
break;
36+
37+
case 3:
38+
fun = mul;
39+
break;
40+
}
41+
fun(30, 40);
42+
return 0;
43+
}

0 commit comments

Comments
 (0)
0