SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
‫م‬
‫جل‬‫ا‬
‫نية‬‫مي‬‫ل‬‫هوريةما‬
‫م‬
‫م‬
‫م‬‫وزارةمالتعلميمالعايل‬
‫م‬
‫الب‬‫و‬
‫ح‬
‫ثمالعلمي‬
‫م‬
‫م‬
‫ر‬‫ي‬‫ز‬‫جامعةماجل‬
‫م‬
‫ة‬
‫م‬
‫لكي‬
‫م‬
‫ه‬‫ال‬‫و‬‫ةمالعلومم‬
‫م‬
‫ة‬‫ندس‬
‫م‬
‫تقنيةممعلومات‬
Type Of Inherence in C++
▪ Single inheritance
▪ Multilevel inheritance
▪ Multiple inheritance
▪ Hierarchical inheritance
▪ Hybrid inheritance
‫معلمالطالب‬
/
‫م‬
‫جماهدممحم‬
‫م‬
‫دمأ‬
‫محدمالفقية‬
.
‫معبريماجل‬/‫هندسة‬‫مل‬‫رشافما‬‫ا‬
.‫حدري‬
‫الورا‬ ‫أنواع‬
‫س‬ ‫لغة‬ ‫في‬ ‫ثة‬
‫ب‬ ‫ي‬
‫بلس‬ ‫لس‬
Single inherence:
#include <iostream>
using namespace std;
class person
{
protected:
string name;
string address;
int number_phone;
int age;
string sex;
public :
person()
{
name="null";
address="null";
number_phone=0;
age=0;
sex="null";
}
person(string n, string addr, int phone, int a, string s ) {
name = n;
address = addr;
number_phone = phone;
age = a;
sex = s;
}
void setName(string n) {
Person
Employee
name = n;
}
void setAddress(string addr) {
address = addr;
}
void setNumber_phone(int phone) {
number_phone = phone;
}
void setAge(int a) {
age = a;
}
void setSex(string s) {
sex = s;
}
string getName() {
return name;
}
string getAddress() {
return address;
}
int getNumber_phone() {
return number_phone;
}
int getAge() {
return age;
}
string getSex() {
return sex;
}
};
class employee : public person
{
private:
string major;
int experince_year;
public:
employee(string n, string addr, int phone, int a, string s ,string m,int exper){
name = n;
address = addr;
number_phone = phone;
age = a;
sex = s;
major=m;
experince_year=exper;
}
void set_majopr(string m){major=m;}
void set_experince_year(int exp){experince_year=exp;}
string get_major(){return major;}
int get_experince_year(){return experince_year;}
};
int main()
{
employee emp1;
emp1.employee("mogahed","IBB",713540851,20,"male","IT",10);
cout << "Name: " << emp1.getName << endl;
cout<<"Address: "<<emp1.getAddress<<endl;
cout<<"Number phone: "<<emp1.getNumber_phone<<endl;
cout<<"Age: "<<emp1.getAge<<endl;
cout<<"Sex: "<<emp1.getSex<<endl;
cout<<"Major: "<<emp1.get_major<<endl;
cout<<"Years Experince : "<<emp1.get_experince_year<<endl;}
Multi-Level Inheritance:
#include <iostream>
using namespace std;
class person
{
protected:
string name;
string address;
int number_phone;
int age;
string sex;
public :
person()
{
name="null";
address="null";
number_phone=0;
age=0;
sex="null";
}
person(string n, string addr, int phone, int a, string s ) {
name = n;
address = addr;
number_phone = phone;
age = a;
sex = s;
Person
employee
Manager
}
void setName(string n) {
name = n;
}
void setAddress(string addr) {
address = addr;
}
void setNumber_phone(int phone) {
number_phone = phone;
}
void setAge(int a) {
age = a;
}
void setSex(string s) {
sex = s;
}
string getName() {
return name;
}
string getAddress() {
return address;
}
int getNumber_phone() {
return number_phone;
}
int getAge() {
return age;
}
string getSex() {
return sex;
}
};
class employee : public person
{
private:
string major;
int experince_year;
public:
employee(string n, string addr, int phone, int a, string s ,string m,int exper){
name = n;
address = addr;
number_phone = phone;
age = a;
sex = s;
major=m;
experince_year=exper;
}
void set_majopr(string m){major=m;}
void set_experince_year(int exp){experince_year=exp;}
string get_major(){return major;}
int get_experince_year(){return experince_year;}
};
class Manager : public Employee
{
protected:
string deptname;
public:
Manager(string n, string addr, int phone, int a, string s ,string m,int exper,string dname){
name = n;
address = addr;
number_phone = phone;
age = a;
sex = s;
major=m;
experince_year=exper;
deptname=dname;
}
void setDeptname(int dn){deptname=dn;}
string getDeptname(){return deptname;}
};
int main()
{
Manager mang;
mang.Manager("mogahed","IBB",713540851,20,"male","IT",10,"CS");
cout << "Name: " << mang.getName() << endl;
cout<<"Address: "<<mang.getAddress()<<endl;
cout<<"Number phone: "<<mang.getNumber_phone()<<endl;
cout<<"Age: "<<mang.getAge()<<endl;
cout<<"Sex: "<<mang.getSex()<<endl;
cout<<"Major: "<<mang.get_major()<<endl;
cout<<"Years Experince : "<<mang.get_experince_year()<<endl;
cout<<"name departemant"<<mang.getDeptname()<<endl;
}
Multipole Inheritance:
#include <iostream>
using namespace std;
class person
{
protected:
string name;
string address;
int number_phone;
int age;
string sex;
public :
person()
{
name="null";
address="null";
number_phone=0;
age=0;
sex="null";
}
person(string n, string addr, int phone, int a, string s ) {
name = n;
address = addr;
number_phone = phone;
age = a;
sex = s;
}
Employee Person
Manager
void setName(string n) {
name = n;
}
void setAddress(string addr) {
address = addr;
}
void setNumber_phone(int phone) {
number_phone = phone;
}
void setAge(int a) {
age = a;
}
void setSex(string s) {
sex = s;
}
string getName() {
return name;
}
string getAddress() {
return address;
}
int getNumber_phone() {
return number_phone;
}
int getAge() {
return age;
}
string getSex() {
return sex;
}
};
class employee : public person
{
private:
string major;
int experince_year;
public:
employee(string n, string addr, int phone, int a, string s ,string m,int exper){
name = n;
address = addr;
number_phone = phone;
age = a;
sex = s;
major=m;
experince_year=exper;
}
void set_majopr(string m){major=m;}
void set_experince_year(int exp){experince_year=exp;}
string get_major(){return major;}
int get_experince_year(){return experince_year;}
};
class Manager: public Employee, public person
{
protected:
string deptname;
public:
Manager(string n, string addr, int phone, int a, string s ,string m,int exper,string dname){
name = n;
address = addr;
number_phone = phone;
age = a;
sex = s;
major=m;
experince_year=exper;
deptname=dname;
}
void setDeptname(int dn){deptname=dn;}
string getDeptname(){return deptname;}
};
int main(){
Manager mang;
mang.Manager("mogahed","IBB",713540851,20,"male","IT",10,"CS");
cout << "Name: " << mang.getName() << endl;
cout<<"Address: "<<mang.getAddress()<<endl;
cout<<"Number phone: "<<mang.getNumber_phone()<<endl;
cout<<"Age: "<<mang.getAge()<<endl;
cout<<"Sex: "<<mang.getSex()<<endl;
cout<<"Major: "<<mang.get_major()<<endl;
cout<<"Years Experince : "<<mang.get_experince_year()<<endl;
cout<<"name departemant"<<mang.getDeptname()<<endl;
}
Hierarchical Inheritance:
#include <iostream>
using namespace std;
class person
{
protected:
string name;
string address;
int number_phone;
int age;
string sex;
public :
person()
{
name="null";
address="null";
number_phone=0;
age=0;
sex="null";
}
person(string n, string addr, int phone, int a, string s ) {
name = n;
address = addr;
number_phone = phone;
age = a;
sex = s;
Employee Person
Manager Engineer
}
void setName(string n) {
name = n;
}
void setAddress(string addr) {
address = addr;
}
void setNumber_phone(int phone) {
number_phone = phone;
}
void setAge(int a) {
age = a;
}
void setSex(string s) {
sex = s;
}
string getName() {
return name;
}
string getAddress() {
return address;
}
int getNumber_phone() {
return number_phone;
}
int getAge() {
return age;
}
string getSex() {
return sex;
}
};
class Employee : public person
{
protected:
string major;
int experince_year;
public:
Employee(string n, string addr, int phone, int a, string s ,string m,int exper){
name = n;
address = addr;
number_phone = phone;
age = a;
sex = s;
major=m;
experince_year=exper;
}
void set_majopr(string m){major=m;}
void set_experince_year(int exp){experince_year=exp;}
string get_major(){return major;}
int get_experince_year(){return experince_year;}
};
class Manager :public person
{
protected:
string major;
int experince_year;
string deptname;
public:
Manager(string n, string addr, int phone, int a, string s ,string m,int exper,string dname){
name = n;
address = addr;
number_phone = phone;
age = a;
sex = s;
major=m;
experince_year=exper;
deptname=dname;
}
void set_majopr(string m){major=m;}
void set_experince_year(int exp){experince_year=exp;}
string get_major(){return major;}
int get_experince_year(){return experince_year;}
void setDeptname(int dn){deptname=dn;}
string getDeptname(){return deptname;}
};
class Engineer:public Employee,public person
{
protected:
string previous_work;
public:
Engineer(string n, string addr, int phone, int a, string s ,string m,int exper,string work){
name = n;
address = addr;
number_phone = phone;
age = a;
sex = s;
major=m;
experince_year=exper;
previous_work=work;
}
void setPrevious_work(string exp){previous_work=exp;}
string getPrevious_work(){return previous_work;}
};
int main()
{Manager mang;
mang.Manager("mogahed","IBB",713540851,20,"male","IT",10,"CS");
cout << "Name: " << mang.getName() << endl;
cout<<"Address: "<<mang.getAddress()<<endl;
cout<<"Number phone: "<<mang.getNumber_phone()<<endl;
cout<<"Age: "<<mang.getAge()<<endl;
cout<<"Sex: "<<mang.getSex()<<endl;
cout<<"Major: "<<mang.get_major()<<endl;
cout<<"Years Experince : "<<mang.get_experince_year()<<endl;
cout<<"name departemant"<<mang.getDeptname()<<endl;
}

More Related Content

What's hot (20)

PPTX
Lecture Introduction to Python 2024.pptx
fgbcssarl
 
PPT
Chapter 5 : ANIMATION
azira96
 
PPTX
Multimedia-Lecture-3.pptx
vishal choudhary
 
PPT
Chapter 4 : SOUND
azira96
 
PPTX
Multimedia chapter 5
PrathimaBaliga
 
PPT
Computer graphics
katherineschuster
 
PPT
Vector graphics
lenance
 
PDF
Immutable vs mutable data types in python
Learnbay Datascience
 
PPT
Lecture6 text
Jay Patel
 
PPT
multimedia image.ppt
JoyFatimaVergara
 
PPTX
Introduction to Computer Graphics
arnelllemit2
 
PPTX
Program analysis
Aarti P
 
PDF
Computers and text
chitcharonko
 
ODP
Introduction to Python - Training for Kids
Aimee Maree
 
PDF
multimedia making it work by Tay Vaughan Chapter1
alichaudhry28
 
PPT
Chapter 02 multimedia systems hardware and software
Urvi Surat
 
PPTX
Animation
marwa_ma
 
PPT
Chapter 2 - Beginning the Problem-Solving Process
mshellman
 
PPT
Multimedia software tools
Jay Patel
 
Lecture Introduction to Python 2024.pptx
fgbcssarl
 
Chapter 5 : ANIMATION
azira96
 
Multimedia-Lecture-3.pptx
vishal choudhary
 
Chapter 4 : SOUND
azira96
 
Multimedia chapter 5
PrathimaBaliga
 
Computer graphics
katherineschuster
 
Vector graphics
lenance
 
Immutable vs mutable data types in python
Learnbay Datascience
 
Lecture6 text
Jay Patel
 
multimedia image.ppt
JoyFatimaVergara
 
Introduction to Computer Graphics
arnelllemit2
 
Program analysis
Aarti P
 
Computers and text
chitcharonko
 
Introduction to Python - Training for Kids
Aimee Maree
 
multimedia making it work by Tay Vaughan Chapter1
alichaudhry28
 
Chapter 02 multimedia systems hardware and software
Urvi Surat
 
Animation
marwa_ma
 
Chapter 2 - Beginning the Problem-Solving Process
mshellman
 
Multimedia software tools
Jay Patel
 

Similar to Type Of Inheritance in C++ language (Object-Oriented Programming ) (20)

PPTX
OOPS Basics With Example
Thooyavan Venkatachalam
 
PPTX
Inheritance.pptx
RutujaTandalwade
 
DOCX
computer project code ''payroll'' (based on datafile handling)
Nitish Yadav
 
PDF
Chapter 8 Inheritance
Amrit Kaur
 
PDF
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
petercoiffeur18
 
DOCX
Classes(or Libraries)#include #include #include #include.docx
brownliecarmella
 
DOCX
Pratik Bakane C++
pratikbakane
 
PDF
Use the code below from the previous assignment that we need to exte.pdf
sales87
 
PDF
So here is the code from the previous assignment that we need to ext.pdf
leolight2
 
PPTX
Object Oriented Programming using c++.pptx
olisahchristopher
 
PDF
Using C++...Hints- Use binary file readwrite to store employee .pdf
fashionfolionr
 
PPTX
OOPS 22-23 (1).pptx
SushmaGavaraskar
 
PPTX
labwork practice on inhetitance-1.pptx
soniasharmafdp
 
PDF
#include iostream #include fstream #include vector #incl.pdf
shahidqamar17
 
PPTX
Object Oriented Programming using C++(UNIT 1)
Dr. SURBHI SAROHA
 
PDF
Object Oriented Programming (OOP) using C++ - Lecture 3
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
PPTX
inheritance in C++
tayyaba nawaz
 
PDF
Having issues with passing my values through different functions aft.pdf
rajkumarm401
 
PDF
c++Inheritance.pdf
RanjanaThakuria1
 
PPTX
Inheritance
Misbah Aazmi
 
OOPS Basics With Example
Thooyavan Venkatachalam
 
Inheritance.pptx
RutujaTandalwade
 
computer project code ''payroll'' (based on datafile handling)
Nitish Yadav
 
Chapter 8 Inheritance
Amrit Kaur
 
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
petercoiffeur18
 
Classes(or Libraries)#include #include #include #include.docx
brownliecarmella
 
Pratik Bakane C++
pratikbakane
 
Use the code below from the previous assignment that we need to exte.pdf
sales87
 
So here is the code from the previous assignment that we need to ext.pdf
leolight2
 
Object Oriented Programming using c++.pptx
olisahchristopher
 
Using C++...Hints- Use binary file readwrite to store employee .pdf
fashionfolionr
 
OOPS 22-23 (1).pptx
SushmaGavaraskar
 
labwork practice on inhetitance-1.pptx
soniasharmafdp
 
#include iostream #include fstream #include vector #incl.pdf
shahidqamar17
 
Object Oriented Programming using C++(UNIT 1)
Dr. SURBHI SAROHA
 
Object Oriented Programming (OOP) using C++ - Lecture 3
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
inheritance in C++
tayyaba nawaz
 
Having issues with passing my values through different functions aft.pdf
rajkumarm401
 
c++Inheritance.pdf
RanjanaThakuria1
 
Inheritance
Misbah Aazmi
 
Ad

Recently uploaded (20)

PDF
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
PDF
Français Patch Tuesday - Juillet
Ivanti
 
PDF
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
PPTX
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PDF
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PPTX
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
Top Managed Service Providers in Los Angeles
Captain IT
 
Français Patch Tuesday - Juillet
Ivanti
 
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Ad

Type Of Inheritance in C++ language (Object-Oriented Programming )

  • 1. ‫م‬ ‫جل‬‫ا‬ ‫نية‬‫مي‬‫ل‬‫هوريةما‬ ‫م‬ ‫م‬ ‫م‬‫وزارةمالتعلميمالعايل‬ ‫م‬ ‫الب‬‫و‬ ‫ح‬ ‫ثمالعلمي‬ ‫م‬ ‫م‬ ‫ر‬‫ي‬‫ز‬‫جامعةماجل‬ ‫م‬ ‫ة‬ ‫م‬ ‫لكي‬ ‫م‬ ‫ه‬‫ال‬‫و‬‫ةمالعلومم‬ ‫م‬ ‫ة‬‫ندس‬ ‫م‬ ‫تقنيةممعلومات‬ Type Of Inherence in C++ ▪ Single inheritance ▪ Multilevel inheritance ▪ Multiple inheritance ▪ Hierarchical inheritance ▪ Hybrid inheritance ‫معلمالطالب‬ / ‫م‬ ‫جماهدممحم‬ ‫م‬ ‫دمأ‬ ‫محدمالفقية‬ . ‫معبريماجل‬/‫هندسة‬‫مل‬‫رشافما‬‫ا‬ .‫حدري‬ ‫الورا‬ ‫أنواع‬ ‫س‬ ‫لغة‬ ‫في‬ ‫ثة‬ ‫ب‬ ‫ي‬ ‫بلس‬ ‫لس‬
  • 2. Single inherence: #include <iostream> using namespace std; class person { protected: string name; string address; int number_phone; int age; string sex; public : person() { name="null"; address="null"; number_phone=0; age=0; sex="null"; } person(string n, string addr, int phone, int a, string s ) { name = n; address = addr; number_phone = phone; age = a; sex = s; } void setName(string n) { Person Employee
  • 3. name = n; } void setAddress(string addr) { address = addr; } void setNumber_phone(int phone) { number_phone = phone; } void setAge(int a) { age = a; } void setSex(string s) { sex = s; } string getName() { return name; } string getAddress() { return address; } int getNumber_phone() { return number_phone; } int getAge() { return age; } string getSex() { return sex; } }; class employee : public person
  • 4. { private: string major; int experince_year; public: employee(string n, string addr, int phone, int a, string s ,string m,int exper){ name = n; address = addr; number_phone = phone; age = a; sex = s; major=m; experince_year=exper; } void set_majopr(string m){major=m;} void set_experince_year(int exp){experince_year=exp;} string get_major(){return major;} int get_experince_year(){return experince_year;} }; int main() { employee emp1; emp1.employee("mogahed","IBB",713540851,20,"male","IT",10); cout << "Name: " << emp1.getName << endl; cout<<"Address: "<<emp1.getAddress<<endl; cout<<"Number phone: "<<emp1.getNumber_phone<<endl; cout<<"Age: "<<emp1.getAge<<endl; cout<<"Sex: "<<emp1.getSex<<endl; cout<<"Major: "<<emp1.get_major<<endl; cout<<"Years Experince : "<<emp1.get_experince_year<<endl;}
  • 5. Multi-Level Inheritance: #include <iostream> using namespace std; class person { protected: string name; string address; int number_phone; int age; string sex; public : person() { name="null"; address="null"; number_phone=0; age=0; sex="null"; } person(string n, string addr, int phone, int a, string s ) { name = n; address = addr; number_phone = phone; age = a; sex = s; Person employee Manager
  • 6. } void setName(string n) { name = n; } void setAddress(string addr) { address = addr; } void setNumber_phone(int phone) { number_phone = phone; } void setAge(int a) { age = a; } void setSex(string s) { sex = s; } string getName() { return name; } string getAddress() { return address; } int getNumber_phone() { return number_phone; } int getAge() { return age; } string getSex() { return sex; }
  • 7. }; class employee : public person { private: string major; int experince_year; public: employee(string n, string addr, int phone, int a, string s ,string m,int exper){ name = n; address = addr; number_phone = phone; age = a; sex = s; major=m; experince_year=exper; } void set_majopr(string m){major=m;} void set_experince_year(int exp){experince_year=exp;} string get_major(){return major;} int get_experince_year(){return experince_year;} }; class Manager : public Employee { protected: string deptname; public: Manager(string n, string addr, int phone, int a, string s ,string m,int exper,string dname){ name = n; address = addr; number_phone = phone;
  • 8. age = a; sex = s; major=m; experince_year=exper; deptname=dname; } void setDeptname(int dn){deptname=dn;} string getDeptname(){return deptname;} }; int main() { Manager mang; mang.Manager("mogahed","IBB",713540851,20,"male","IT",10,"CS"); cout << "Name: " << mang.getName() << endl; cout<<"Address: "<<mang.getAddress()<<endl; cout<<"Number phone: "<<mang.getNumber_phone()<<endl; cout<<"Age: "<<mang.getAge()<<endl; cout<<"Sex: "<<mang.getSex()<<endl; cout<<"Major: "<<mang.get_major()<<endl; cout<<"Years Experince : "<<mang.get_experince_year()<<endl; cout<<"name departemant"<<mang.getDeptname()<<endl; }
  • 9. Multipole Inheritance: #include <iostream> using namespace std; class person { protected: string name; string address; int number_phone; int age; string sex; public : person() { name="null"; address="null"; number_phone=0; age=0; sex="null"; } person(string n, string addr, int phone, int a, string s ) { name = n; address = addr; number_phone = phone; age = a; sex = s; } Employee Person Manager
  • 10. void setName(string n) { name = n; } void setAddress(string addr) { address = addr; } void setNumber_phone(int phone) { number_phone = phone; } void setAge(int a) { age = a; } void setSex(string s) { sex = s; } string getName() { return name; } string getAddress() { return address; } int getNumber_phone() { return number_phone; } int getAge() { return age; } string getSex() { return sex; } };
  • 11. class employee : public person { private: string major; int experince_year; public: employee(string n, string addr, int phone, int a, string s ,string m,int exper){ name = n; address = addr; number_phone = phone; age = a; sex = s; major=m; experince_year=exper; } void set_majopr(string m){major=m;} void set_experince_year(int exp){experince_year=exp;} string get_major(){return major;} int get_experince_year(){return experince_year;} }; class Manager: public Employee, public person { protected: string deptname; public: Manager(string n, string addr, int phone, int a, string s ,string m,int exper,string dname){ name = n; address = addr; number_phone = phone; age = a;
  • 12. sex = s; major=m; experince_year=exper; deptname=dname; } void setDeptname(int dn){deptname=dn;} string getDeptname(){return deptname;} }; int main(){ Manager mang; mang.Manager("mogahed","IBB",713540851,20,"male","IT",10,"CS"); cout << "Name: " << mang.getName() << endl; cout<<"Address: "<<mang.getAddress()<<endl; cout<<"Number phone: "<<mang.getNumber_phone()<<endl; cout<<"Age: "<<mang.getAge()<<endl; cout<<"Sex: "<<mang.getSex()<<endl; cout<<"Major: "<<mang.get_major()<<endl; cout<<"Years Experince : "<<mang.get_experince_year()<<endl; cout<<"name departemant"<<mang.getDeptname()<<endl; }
  • 13. Hierarchical Inheritance: #include <iostream> using namespace std; class person { protected: string name; string address; int number_phone; int age; string sex; public : person() { name="null"; address="null"; number_phone=0; age=0; sex="null"; } person(string n, string addr, int phone, int a, string s ) { name = n; address = addr; number_phone = phone; age = a; sex = s; Employee Person Manager Engineer
  • 14. } void setName(string n) { name = n; } void setAddress(string addr) { address = addr; } void setNumber_phone(int phone) { number_phone = phone; } void setAge(int a) { age = a; } void setSex(string s) { sex = s; } string getName() { return name; } string getAddress() { return address; } int getNumber_phone() {
  • 15. return number_phone; } int getAge() { return age; } string getSex() { return sex; } }; class Employee : public person { protected: string major; int experince_year; public: Employee(string n, string addr, int phone, int a, string s ,string m,int exper){ name = n; address = addr; number_phone = phone; age = a; sex = s; major=m; experince_year=exper; } void set_majopr(string m){major=m;} void set_experince_year(int exp){experince_year=exp;} string get_major(){return major;}
  • 16. int get_experince_year(){return experince_year;} }; class Manager :public person { protected: string major; int experince_year; string deptname; public: Manager(string n, string addr, int phone, int a, string s ,string m,int exper,string dname){ name = n; address = addr; number_phone = phone; age = a; sex = s; major=m; experince_year=exper; deptname=dname; } void set_majopr(string m){major=m;} void set_experince_year(int exp){experince_year=exp;} string get_major(){return major;} int get_experince_year(){return experince_year;} void setDeptname(int dn){deptname=dn;} string getDeptname(){return deptname;} }; class Engineer:public Employee,public person { protected: string previous_work;
  • 17. public: Engineer(string n, string addr, int phone, int a, string s ,string m,int exper,string work){ name = n; address = addr; number_phone = phone; age = a; sex = s; major=m; experince_year=exper; previous_work=work; } void setPrevious_work(string exp){previous_work=exp;} string getPrevious_work(){return previous_work;} }; int main() {Manager mang; mang.Manager("mogahed","IBB",713540851,20,"male","IT",10,"CS"); cout << "Name: " << mang.getName() << endl; cout<<"Address: "<<mang.getAddress()<<endl; cout<<"Number phone: "<<mang.getNumber_phone()<<endl; cout<<"Age: "<<mang.getAge()<<endl; cout<<"Sex: "<<mang.getSex()<<endl; cout<<"Major: "<<mang.get_major()<<endl; cout<<"Years Experince : "<<mang.get_experince_year()<<endl; cout<<"name departemant"<<mang.getDeptname()<<endl; }