-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtut41.cpp
73 lines (70 loc) · 1.29 KB
/
tut41.cpp
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
71
72
73
#include<iostream>
using namespace std;
void name(){
cout<<'Author: Varun Gupta'<<endl;
}
/* The syntax for multiple inheritance:
class derived :{Visibility-mode}- class base1 , Visibility-mode class base2
{
class body of class "deived ";
};
*/
class Base1
{
protected:
int a ;
public :
void display1(int a1 )
{
a=a1;
}
void showa()
{
cout<<"The value of a is "<<a<<endl;
}
};
class Base2
{
protected:
int b;
public :
void display2(int a2)
{
b=a2;
}
void showb()
{
cout<<"The value of b is "<<b<<endl;
}
};
class Derived: public Base1, public Base2
{
public :
int sum;
void add()
{
// void showa();
// void showb();
cout<<"The value of a is "<<a<<" and the value of b is "<<b<<endl;
sum=a+b;
cout<<"The sum of a and b is :"<<sum<<endl;
}
};
int main(){
name();
/*
The inherited derived class will look something like this:
Data members:
a--> protected
--> protected
Member functions:
en()--> public
out()--> public
add() --> public
*/
Derived d1;
d1.display1(4);
d1.display2(5);
d1.add();
return 0;
}