00:01
Today we're going to be going over inheritance using a function that creates a member that has a name, age, phone number, address, and salary.
00:11
And then from there, we're going to inherit an employee and a manager.
00:19
So to start with, we need i .o.
00:21
Stream and string.
00:22
I've also got i .o.
00:23
Minip here as a library to set precision down here, just in case you want to change the output of the salary that we're printing.
00:32
And so to start with in our member, we've got a constructor in the public section that will take in the name, the age, the number, the address, and the salary, and it will set those here, changing these protected variables.
00:50
Down here we have our first child class that is inheriting from member.
00:57
It will inherit these, and they will show up inside this class as private.
01:04
And then we've got here a constructor for employee that takes the same parameters and one extra one here.
01:15
So it will pass all the ones that doesn't use to the parent constructor.
01:21
And then it will just set the employee specialization here.
01:27
And then down here we also have print specialization, which just prints out what we just assigned here.
01:34
And same for the manager.
01:36
We have our child constructor that passes most of the variables back to the parent constructor and sets the department along with a print department function inside main i just create a member as a base here filling out all the arguments and then we print out the base member salary same for the employee we create them we add this parameter on the end and then we print out their salary and their specialization and same for the manager we create that we pass in the department that they're a manager for print out their salary and their department and finish the program so i'll just run that and we can see the output on the bottom here we have our base member salary we have our employees subclass salary and specialization we have our manager subclass salary and specialization now if we wanted to set the position.
02:45
That's what this would look like here...