Skip to content

Commit 451d8d6

Browse files
Merge pull request #164 from saksham0308/patch-2
Create BasicInheritance.cpp
2 parents 5969e2a + dd4d064 commit 451d8d6

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

CPP/questions/BasicInheritance.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//private inheritance
2+
#include <iostream>
3+
using namespace std;
4+
class person
5+
{
6+
int id;
7+
string name;
8+
public:
9+
void set_p()
10+
{
11+
cout<<"Enter id\n";
12+
cin>>id;
13+
cout<<"Enter name\n";
14+
cin>>name;
15+
//cout<<name;
16+
}
17+
void display()
18+
{
19+
cout<<"Name is "<<name<<"\n";
20+
cout<<"Id is "<<id<<"\n";
21+
}
22+
};
23+
class Student:private person
24+
{
25+
string courseName;
26+
int fee;
27+
public:
28+
void get_s()
29+
{
30+
set_p();
31+
cout<<"Enter Course Name\n";
32+
cin>>courseName;
33+
cout<<"Enter fee\n";
34+
cin>>fee;
35+
36+
}
37+
void S_display()
38+
{
39+
display();
40+
cout<<courseName<<"\n"<<fee;
41+
}
42+
};
43+
int main()
44+
{
45+
Student s;
46+
s.get_s();
47+
s.S_display();
48+
}

0 commit comments

Comments
 (0)