-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path39Inheritance_Exercise.cpp
More file actions
67 lines (55 loc) · 1.12 KB
/
Copy path39Inheritance_Exercise.cpp
File metadata and controls
67 lines (55 loc) · 1.12 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
#include <iostream>
#include <iomanip>
#include<cmath>
using namespace std;
class SimpleCalculator{
protected:
int num1, num2, num3,num4;
public:
int set_number(int a, int b){
num1 = a;
num2 = b;
cout<<"num1 is "<<num1<<endl;
cout<<"num2 is "<<num2<<endl;
}
int sum(){
num3 = num1 + num2;
cout<<num3<<endl;
}
void diff(){
num4 = num1 - num2;
cout<<num4<<endl;
}
};
class ScientificCalculator{
protected:
int n1, n2, n3;
float n4;
public:
int Set_number(int a, int b){
n1 = a;
n2 = b;
cout<<" the numbers are "<<n1<<", "<<n2<<endl;
}
int multiply(){
n3 = n1*n2;
cout<<n3<<endl;
}
float divide(){
n4 = float(n1)/n2;
cout<<n4<<endl;
}
};
class HybridCalculator : public SimpleCalculator, public ScientificCalculator{
};
int main(){
SimpleCalculator S;
S.set_number(3, 5);
S.sum();
S.diff();
ScientificCalculator S1;
S1.Set_number( 8, 7);
S1.multiply();
S1.divide();
return 0;
}