-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtualbaseclass.cpp
More file actions
70 lines (62 loc) · 1.05 KB
/
virtualbaseclass.cpp
File metadata and controls
70 lines (62 loc) · 1.05 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<iostream>
using namespace std;
class num
{
protected:
int op;
public:
void input()
{
cout << "Choose Operation ->\n" << "1. Addition\n" << "2. Subtraction\n" << "3. Multiplication\n" << "4. Division\n" << endl;
cout << "Operation of numbers : ";
cin >> op;
}
};
class num1:virtual public num
{
protected:
int a;
public:
void get1()
{
cout << "a = ";
cin >> a;
}
};
class num2:virtual public num
{
protected:
int b;
public:
void get2()
{
cout << "b = ";
cin >> b;
}
};
class calc:public num1,public num2
{
public:
void showdata()
{
if(op==1)
cout << "Sum = " << a+b << endl;
else if(op==2 && b>=a)
cout << "Subtraction = " << b-a << endl;
else if(op==3)
cout << "Multiplication = " << a*b << endl;
else if(op==4 && b!=0)
cout << "Division = " << a/b << endl;
else
cout << "Try Again!!" << endl;
}
};
int main()
{
calc obj;
obj.input();
obj.get1();
obj.get2();
obj.showdata();
return 0;
}