Skip to content

Commit 43ec21d

Browse files
authored
Create SingleInheritance.cpp
1 parent fa5b428 commit 43ec21d

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

CPP/questions/SingleInheritance.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <iostream>
2+
using namespace std;
3+
class person
4+
{
5+
protected:
6+
string aa;
7+
public:
8+
string name;
9+
int age;
10+
void get_p()
11+
{
12+
cout<<"Enter Name\n";
13+
cin>>name;
14+
cout<<"Enter age\n";
15+
cin>>age;
16+
}
17+
void display_p()
18+
{
19+
cout<<"Name is "<<name<<"\n";
20+
cout<<"Age is "<<age<<"\n";
21+
}
22+
23+
};
24+
class student:public person{
25+
string courseName;
26+
int id;
27+
public:
28+
void get_s()
29+
{
30+
this->get_p();
31+
cout<<"Enter coursename\n";
32+
cin>>courseName;
33+
cout<<"Enter id\n";
34+
cin>>id;
35+
}
36+
void display_s()
37+
{
38+
this->display_p();
39+
cout<<"CourseName is "<<courseName<<"\nid is "<<id<<"\n";
40+
}
41+
};
42+
// class student
43+
// { public:
44+
// int data;}; // this will work but override above same class
45+
int main()
46+
{
47+
student *s;
48+
s=new student();
49+
if(s->name.empty())
50+
cout<<"Hello";
51+
s->get_s();
52+
s->display_s();
53+
person p;
54+
cout<<s->name;
55+
}

0 commit comments

Comments
 (0)