-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritence.cpp
More file actions
54 lines (42 loc) · 946 Bytes
/
Copy pathinheritence.cpp
File metadata and controls
54 lines (42 loc) · 946 Bytes
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
// inheritance.cpp
#include <iostream>
using namespace std;
// Base Class
class Person {
protected:
string name;
int age;
public:
void setPersonData(string n, int a) {
name = n;
age = a;
}
void displayPersonData() {
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
}
};
// Derived Class
class Student : public Person {
private:
int rollNumber;
float marks;
public:
void setStudentData(int r, float m) {
rollNumber = r;
marks = m;
}
void displayStudentData() {
displayPersonData();
cout << "Roll Number: " << rollNumber << endl;
cout << "Marks: " << marks << endl;
}
};
int main() {
Student s1;
s1.setPersonData("Ezan", 20);
s1.setStudentData(101, 89.5);
cout << "Student Details:\n";
s1.displayStudentData();
return 0;
}