-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx_2-inheritance.cpp
More file actions
84 lines (77 loc) · 1.51 KB
/
Copy pathEx_2-inheritance.cpp
File metadata and controls
84 lines (77 loc) · 1.51 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
#include <iostream>
using namespace std;
class Number // Base class
{
protected:
int num;
char name[20];
};
class student: public Number // Sub class
{
private:
int grade;
public:
void getname()
{
cout << "Enter name: ";
cin >> name;
}
void getnum()
{
cout << "Enter roll number: ";
cin >> num;
}
void getgrade()
{
cout << "Enter grade: ";
cin >> grade;
}
void display()
{
cout << "Name: " << name << endl;
cout << "Roll number: " << num << endl;
cout << "Grade: " << grade << endl;
}
};
class employee: public Number // Sub class
{
private:
int salary;
public:
void getname()
{
cout << "Enter name: ";
cin >> name;
}
void getnum()
{
cout << "Enter employee number: ";
cin >> num;
}
void getsalary()
{
cout << "Enter salary: ";
cin >> salary;
}
void display()
{
cout << "Name: " << name << endl;
cout << "Employee number: " << num << endl;
cout << "Salary: " << salary << endl;
}
};
int main()
{
student s; // Creating an object of student class
employee e; // Creating an object of employee class
s.getname();
s.getnum();
s.getgrade();
e.getname();
e.getnum();
e.getsalary();
s.display(); // Displaying student details
cout << endl;
e.display(); // Displaying employee details
return 0;
}