-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHierarchicalInheritance.cpp
More file actions
89 lines (86 loc) · 2.14 KB
/
Copy pathHierarchicalInheritance.cpp
File metadata and controls
89 lines (86 loc) · 2.14 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//Hierarchical Inheritance
#include<iostream>
using namespace std;
class Student
{
protected:
char Name[30];
int Roll;
char Branch[30];
public:
void get()
{
cout<<"\nEnter Name of the Student => ";
cin>>Name;
cout<<"Enter Roll Number Of the Student => ";
cin>>Roll;
cout<<"Enter Branch of the student => ";
cin>>Branch;
}
void show()
{
cout<<"\nName of the Student : "<<Name;
cout<<"\nRoll Number of Student : "<<Roll;
cout<<"\nBranch of the Student : "<<Branch;
}
};
class Result:public Student
{
private:
int Marks[5];
float per;
public:
void get1()
{
Student::get();
cout<<"Enter marks of five subjects: \n";
for(int i = 0; i < 5; i++)
{
cout<<"\tSubject "<<(i+1)<<" = ";
cin>>Marks[i];
}
}
void Show1()
{
Student::show();
cout<<"\nMarks obtained in five subjects are : \n";
for(int i = 0; i<5; i++)
{
cout<<"\tSubject "<<(i+1)<<" = "<<Marks[i]<<endl;
per = per + Marks[i];
}
per /= 5;
cout<<"\nPercentage of the student : "<<per;
}
};
class Sports:public Student
{
private:
char Sport[30];
public:
void get2()
{
Student::get();
cout<<"Enter Student's Interested Sports => ";
cin>>Sport;
}
void show2()
{
Student::show();
cout<<"\nStudent's intrested sport : "<<Sport;
}
};
int main()
{
Result R;
R.get1();
cout<<"\n----------------------------------------------------"<<endl;
R.Show1();
cout<<"\n****************************************************"<<endl;
Sports S;
S.get2();
cout<<"\n----------------------------------------------------"<<endl;
S.show2();
cout<<"\n****************************************************"<<endl;
return 0;
}