-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolymorphism.cpp
More file actions
49 lines (46 loc) · 1.02 KB
/
Copy pathpolymorphism.cpp
File metadata and controls
49 lines (46 loc) · 1.02 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
/* Polymorphism
(1)Complile Time (2)Run Time
(1)Function (2)Operaton (1)Virtual Funtions
Overloading overloading
*/
//function overloading
#include <iostream>
using namespace std;
class MathematicalOp{
private:
int n1,n2,n4;
double n3;
public:
void calculate(int x,int y){
n1=x;
n2=y;
int sum=0;
sum=n1+n2;
cout<<"Sum:"<<sum<<endl;
}
void calculate(int x, int y ,double z){
n1=x;
n2=y;
n3=z;
double multiplication;
multiplication=n1*n2*n3;
cout<<"multiplication:"<<multiplication<<endl;
}
void calculate(int x,int y,double z,int d){
n1=x;
n2=d;
int subtraction;
subtraction=n1-d;
cout<<"subtraction:"<<subtraction;
}
};
int main() {
MathematicalOp obj;
int n1,n2,n4;
double n3;
cout<<"Enter four numbers:\n";
cin>>n1>>n2>>n3>>n4;
obj.calculate(n1,n2);
obj.calculate(n1,n2,n3);
obj.calculate(n1,n2,n3,n4);
}