Skip to content

Commit 85267b4

Browse files
committed
Inheritance
Inheritance types in C++
1 parent 07324cb commit 85267b4

File tree

5 files changed

+215
-0
lines changed

5 files changed

+215
-0
lines changed

Inheritance/Inheritance.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <iostream>
2+
using namespace std;
3+
#include"hiearchal.h"
4+
#include "single.h"
5+
#include "multiple.h"
6+
#include "multilevel.h"
7+

Inheritance/hiearchal.h

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//#pragma once
2+
//
3+
//class Doctor {
4+
//public:
5+
// string _name, _position;
6+
// int _salary;
7+
// Doctor() = default;
8+
// Doctor(string name, string position, int salary)
9+
// {
10+
// _name = name;
11+
// _position = position;
12+
// _salary = salary;
13+
// }
14+
// void print() {
15+
// cout << "Name: " << _name << endl;
16+
// cout << "Position: " << _position << endl;
17+
// cout << "Salary: " << _salary << endl;
18+
// }
19+
//
20+
//
21+
//};
22+
//
23+
//class HeartDoc : public Doctor {
24+
//public:
25+
// size_t _height;
26+
// HeartDoc() = default;
27+
// HeartDoc(string name, string position, int salary, size_t height) :Doctor(name, position, salary)
28+
// {
29+
// _height = height;
30+
// }
31+
// void print() {
32+
// Doctor::print();
33+
// cout << "Height: " << _height << endl;
34+
// };
35+
//
36+
//};
37+
//class BrainDoc : public Doctor {
38+
//public:
39+
// size_t _weight;
40+
// BrainDoc() = default;
41+
// BrainDoc(string name, string position, int salary, size_t weight) :Doctor(name, position, salary)
42+
// {
43+
// _weight = weight;
44+
// }
45+
// void print() {
46+
// Doctor::print();
47+
// cout << "Weight: " << _weight << endl;
48+
// };
49+
//
50+
//};
51+
//class EyeDoctor : public Doctor {
52+
//public:
53+
// size_t _expYear;
54+
// EyeDoctor() = default;
55+
// EyeDoctor(string name, string position, int salary, size_t expYear) :Doctor(name, position, salary)
56+
// {
57+
// _expYear = expYear;
58+
// }
59+
// void print() {
60+
// Doctor::print();
61+
// cout << "exp Year: " << _expYear << endl;
62+
// };
63+
//
64+
//};
65+
//
66+
//void main() {
67+
// BrainDoc bd{ "Huseyn","Brain",2200,70 };
68+
// bd.print();
69+
// cout << "---------Next Doctor---------" << endl;
70+
// EyeDoctor ed{ "Huseyn","Eye",2200,5 };
71+
// bd.print();
72+
// cout << "---------Next Doctor---------" << endl;
73+
// HeartDoc hd{ "Huseyn","Heart",2200,176 };
74+
// bd.print();
75+
// cout << "---------Next Doctor---------" << endl;
76+
//
77+
//}

Inheritance/multilevel.h

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#pragma once
2+
3+
class Person {
4+
public:
5+
string _name;
6+
string _surname;
7+
short _age;
8+
Person()=default;
9+
Person(string name,string surname,short age) {
10+
_name = name;
11+
_surname = surname;
12+
_age = age;
13+
}
14+
void print() {
15+
cout<<"Name: "<<_name<<endl;
16+
cout<<"Surname: "<<_surname<<endl;
17+
cout<<"Age: "<<_age<<endl;
18+
}
19+
20+
21+
22+
};
23+
24+
class Employer :public Person{
25+
public:
26+
float _salary;
27+
int _workExp;
28+
Employer() = default;
29+
Employer(string name, string surname, short age, float salary, int workExp) :Person(name, surname, age) {
30+
_salary = salary;
31+
_workExp = workExp;
32+
}
33+
void print() {
34+
Person::print();
35+
cout<<"Salary: "<<_salary<<endl;
36+
cout<<"workExp: "<<_workExp<<endl;
37+
}
38+
39+
40+
41+
};
42+
class Teacher :public Employer{
43+
public:
44+
string _subject;
45+
Teacher()=default;
46+
Teacher(string name, string surname, short age, float salary, int workExp,string subject) :Employer(name, surname, age,salary,workExp){
47+
_subject = subject;
48+
}
49+
void print() {
50+
Employer::print();
51+
cout << "Subject: " << _subject << endl;
52+
}
53+
};
54+
55+
void main(){
56+
Teacher t1{ "Huseyn","Hemidov",18,1000,2,"Chemistry" };
57+
t1.print();
58+
59+
60+
}

Inheritance/multiple.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//#pragma once
2+
//class liveInwater{
3+
//public:
4+
// liveInwater()
5+
// {
6+
// cout << "We can live only in water " << endl;
7+
// }
8+
//
9+
//};
10+
//class liveOnland{
11+
//public:
12+
// liveOnland()
13+
// {
14+
// cout << "We can live only on land " << endl;
15+
//
16+
// }
17+
//
18+
//};
19+
//class Amfibian:public liveInwater,liveOnland {
20+
//public:
21+
// Amfibian() {
22+
// cout << "We can live both in water and on land " << endl;
23+
// }
24+
//};
25+
//
26+
//void main() {
27+
// Amfibian a1;
28+
//
29+
//}

Inheritance/single.h

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//#pragma once
2+
//
3+
//class Team {
4+
//public:
5+
// string _name, _position;
6+
// int _number;
7+
// Team() = default;
8+
// Team(string name, string position, int number)
9+
// {
10+
// _name = name;
11+
// _position = position;
12+
// _number = number;
13+
// }
14+
// void print() {
15+
// cout << "Name: " << _name << endl;
16+
// cout << "Position: " << _position << endl;
17+
// cout << "Number: " << _number << endl;
18+
// }
19+
//
20+
//
21+
//};
22+
//
23+
//class Player : public Team {
24+
//public:
25+
// size_t _height;
26+
// Player() = default;
27+
// Player(string name, string position, int number, size_t height) :Team(name, position, number)
28+
// {
29+
// _height = height;
30+
// }
31+
// void print() {
32+
// Team::print();
33+
// cout << "Our work is defending";
34+
// };
35+
//
36+
//};
37+
//
38+
//void main() {
39+
// Player p{ "Huseyn","Defender",22,176 };
40+
// p.print();
41+
//
42+
//}

0 commit comments

Comments
 (0)