-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinheritance and polymorphism.cpp
58 lines (50 loc) · 1.4 KB
/
inheritance and polymorphism.cpp
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
#include <iostream>
#include <vector>
class User{
public :
std::string first_name ;
std::string last_name ;
int age ;
virtual void output(){
std::cout << "User Created...! " << "\n";
}
std::string get_full_name(){
return first_name + " " + last_name ;
}
} ;
class Student : public User{
public :
std::vector<std::string> learing_subject ;
void output(){
std::cout << "Student Created...!" << "\n" ;
}
Student(std::string first_name ,std::string last_name){
this->first_name = first_name ;
this->last_name = last_name ;
std::cout << "Student Created...! " << "\n" ;
}
} ;
class Teacher : public User {
public :
std::vector<std::string> teaching_subject ;
void output(){
std::cout << "Teacher Created...!" << "\n" ;
}
Teacher(std::string first_name ,std::string last_name){
this->first_name = first_name ;
this->last_name = last_name ;
std::cout << "Teacher Created...! " << "\n";
}
} ;
void output(User &user){
user.output() ;
}
int main(){
Teacher teacher1("Amal","Kamal") ;
Student student1("Namal","Kamal") ;
std::cout << teacher1.get_full_name() ;
User user = teacher1 ;
user.output() ;
output(teacher1) ;
return 0 ;
}