File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change
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<<" \n id 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
+ }
You can’t perform that action at this time.
0 commit comments