-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultilevel_inheritance.cpp
94 lines (77 loc) · 1.46 KB
/
multilevel_inheritance.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Multilevel Inheritance
#include <bits/stdc++.h>
using namespace std;
// Example - 1
// class A
// {
// public:
// int a ;
// A()
// {
// cout << "Enter the value of A : ";
// cin >> a;
// }
// };
// class B : public A
// {
// public:
// int b;
// B()
// {
// cout << "Enter the value of B : ";
// cin >> b;
// }
// };
// class C : public B
// {
// public:
// C()
// {
// cout << "The sum of two number : " << a + b << endl;
// }
// void print(){
// cout<<"Hello this is multilevel Inheritance\n";
// }
// };
// Example - 2
class student{
public:
int roll_no;
string name;
void get_data(){
cout<<"Enter the roll no : ";
cin>>roll_no;
cout<<"Enter the name : ";
cin>>name;
}
};
class marks : public student{
public:
int m1,m2,m3;
void get_marks(){
cout<<"Enter the marks of 3 Subjects\n";
cin>>m1>>m2>>m3;
}
};
class result : public marks{
public:
int total;
void display(){
total = m1+m2+m3;
cout<<"The Name of student is : "<<name<<endl;
cout<<"The Roll Number of student is : "<<roll_no<<endl;
cout<<"The total marks of "<<name<<" is "<<total<<endl;
}
};
int main()
{
// Example - 1
// C a;
// a.print();
// Example - 2
result lokesh;
lokesh.get_data();
lokesh.get_marks();
lokesh.display();
return 0;
}