-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion5.cpp
72 lines (62 loc) · 2.08 KB
/
question5.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <string>
class person{
protected:
std::string name;
int id;
public:
person(std::string name =" ", int id = 0){
this->name =name;
this->id =id;
}
virtual ~person(){}
virtual void displayinfo(){
std::cout << "The name is:: " << name << std::endl;
std::cout << "The id is:; " << id << std::endl;
}
};
/// USE OF VIRTUAL BASE CLASS TO SOLVE THE DIMOND PROBLEME
class student : virtual public person{
protected:
std::string major;
student(std::string name = " ", int id =0, std::string major =" ") : person(name, id){
this->major = major;
}
void displayinfo() override{
person::displayinfo();
std::cout << "The major of the student is:: " << major << std::endl;
}
};
class employee : virtual public person{
protected:
std::string position;
public:
employee(std::string name = " ", int id= 0 , std::string position =" "):person(name, id){
this->position =position;
}
void displayinfo() override{
person::displayinfo();
std::cout << "The Position of the Employee is:: " << position;
}
};
class teachingAssistance :public student , public employee{
protected:
std::string department;
public:
// THE BASE CLASS PERSON IS INITIALIZD BY THE MOST DERVIDE CLASS HERE IN THIS CASE IT IS THE TECHINGASSISTANCE
teachingAssistance(std::string name = " ", int id = 0, std::string major = " " , std::string position =" " ,std::string department =" "): person(name, id),student(name , id ,major), employee(name,id, position){
this->department = department;
}
void displayinfo() override{
student::displayinfo();
employee::displayinfo();
std::cout << "THe department is :: " << department << std::endl;
std::cout << "--------------------------------------------------" << std::endl;
std::cout << "The name of the student is " << name;
std::cout << "The id of the name above mensioned is:: " << id;
}
};
int main(){
teachingAssistance t("Saksham Humagain", 12, "Computer", "Ceo" , "Computer Science and Enginnering" );
t.displayinfo();
}