-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial18.cpp
53 lines (46 loc) · 1.16 KB
/
tutorial18.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
#include<bits/stdc++.h>
using namespace std;
/*
We can also pass arguments/ call base class constructors from the sub class in case of multiple inheritence
*/
class Human
{
public:
string name;
int age;
Human(string inp_name = "noname", int inp_age = -1)
{
cout<<"Human(base class) constructor called."<<endl;
name = inp_name;
age = inp_age;
}
};
class Student
{
public:
string dep;
Student(string inp_dep = "nodep")
{
cout<<"Student(base class) constructor called."<<endl;
dep = inp_dep;
}
};
class ChemicalEngineers : public Human, public Student
{
public:
int roll;
ChemicalEngineers(int inp_roll = -1, string inp_dep = "nodep", string inp_name = "noname", int inp_age = -1) : Human(inp_name, inp_age) , Student(inp_dep)
{
cout<<"ChemicalEngineers(sub class) constructor called."<<endl;
roll = inp_roll;
}
void Introduce()
{
cout<<"Hello! I am "<<name<<" and i am "<<age<<" years old. My department is "<<dep<<" and my roll number is "<<roll<<"."<<endl;
}
};
int main()
{
ChemicalEngineers saurav(49, "Chemical", "Saurav", 22);
saurav.Introduce();
}