 Welcome back, in the last segment we discussed member functions, in this segment we will take the discussion further and see it in the context of the taxi dispatch problem. So let me remind you what the taxi dispatch problem was, so customers arrive and have to be assigned to earliest waiting taxis. And we now are going to implement the functionality which we implemented earlier using member functions. So first of all a structure to represent a queue. So let us say n is the maximum number of waiting taxis, n waiting is the variable which we are going to need to keep track of the number of taxis currently waiting, front is the index of the earliest taxi in the array that we are going to keep and the array elements front through front plus n waiting mod n hold the IDs of the waiting taxis. So remember that in chapter 14 we discussed this and there we said that this is a circular queue that is why that mod n operation happens, n is the length of that queue, maximum number of waiting taxis possible. And the queue is involved in two operations, inserting taxis and removing taxis. So these become natural member functions. And you will see that it is useful to have a member function to initialize the queue as well. So here is what the queue might look like. So we have constant n equal to 100, so we need to have some maximum length or the length of the queue and so that is 100. Then we have an array elements which are going to store the driver IDs of length n and then we are also going to have variables, members which are n waiting and front. Then these are our three member functions. So that is sort of the overall high level scheme of what we are going to do in this taxis patch problem. So let me just show you what each of these functions is going to look like. So let us start with initialize. So what do we want in initialization? If you remember when we created the queue we said that n waiting and front should become 0. And that is kind of a bare minimum that we want. The queue that we create should make sense, so n waiting and front should make sense and at the beginning that is how they make sense. So that is what we are going to do in this definition. So insert is going to contain the code of what is needed, what is needed to happen when you insert an additional element into the queue and remove is going to contain the code which is needed for removing elements from the queue. So what does our main program look like? So we create a queue, the struct and then we initialize it, oh there should be parenthesis there, so that is a typo, we need to have parenthesis and semicolon over here and then there is a loop. So we read in the command which the operator gives and if it is a D then we are going to get the driver details and we are going to try and insert it into the array, into the queue. If it is a C for a customer then again we are going to remove the driver. So we are going to take out the driver from the queue and this is going to be a reference argument so this will actually modify this driver and of course in either case, in this case if there is no driver waiting then we should print this message, in this case if there is no space to put in the new driver we are also going to put this message and if the driver removal is successful then we are going to say print a message saying assigning this driver. That is basically the main program. So the member function initialize, so this is actually fairly simple as I just described it is going to simply set n waiting to 0 and front also to 0. So we were doing this at the beginning in the old program but now notice that it has gone into a member function. So in particular if you look at this the internals of Q are not really visible and that is a good thing in the sense that this code is a high level code. The internals are being manipulated but they are being manipulated in these calls, in the member function calls. So this is the kind of separation of concerns that has come about because of all of this. So in particular the member functions modify the members of Q and the user which is this main program in this case is just going to call the appropriate member functions and the user where the main program is not really aware even of what happens inside this Q. If you remember we ourselves had two implementations of the Q and this main program would work with either implementation provided the functions themselves were changed but this program would not have to change if the signature of the member functions does not change. The member function insert is again not hard to write. So we are inserting a driver V and we are going to check if the Q has space and if so we are going to insert it at the front and we had a fairly extensive discussion of where the back of the Q is so it is at this position so that is where we insert and then we increment n waiting and we return true because this is successful if there were too many people waiting then the insertion is not successful and so we return false. So member function remove is somewhat similar so we check whether the Q contains some values otherwise we return false then the value to be removed should come from the front of the Q. So we take the value from the front and we increment front but of course this increment must be this circular increment that is if we are already at the last element of the Q then we should go back to the 0th element and of course n waiting should decrease. So as you can see we can in fact easily write taxi dispatch in terms of member functions and one point to note and I am repeating it but it is important which is that in this entire program we are not really looking at the details of the Q. So our concerns have been nicely separated the member functions worry about the details of the Q and the user program just calls the right functions. So this exercise is about adding one more operation so you should certainly attempt it. So the member functions only contain the logic of how to manage the Q and we had defined invariants about n waiting front and things like that and these apply only to the member functions. The main program is not concerned with those invariants the main program only contains the logic of dealing with the taxis and the customers. So this is the so-called separation of concerns and in some sense the new program is simpler as compared to what we had earlier where these concerns were mixed up. So if you can separate out concerns it is always a good idea. So that really concludes this lecture and here are some concluding remarks. So structure should be used to collect together the attributes of an entity and generally represent an entity. So if there is an important entity in your program then you should have a structure which is representing that entity. If that entity is made up of parts then your structure should contain the parts and the parts themselves may be structures that is fine but usually it is good to have this kind of a correspondence. Member function should be written to represent valid operations and actions of the entities and the invariants which we define for the entity should be satisfied by our member functions. Now later on we will see that we can make this whole philosophy a little bit stricter in the sense that so far we have been recommending that accesses to entity should go through member functions but later on we will be able to force this, we would be able to say or we would be able to make the compiler declare an error if the user tries to access an entity in some other ways. So you may or may not want to do that but you should note that if you sort of design structures or such objects which are strict then you can be sure that look that I am not doing the wrong thing even by mistake I am always acting according to the rule book and therefore I could not be making a mistake and of course you should be paranoid about making mistakes because a program is going to be run in so many ways and so many times and you cannot afford to make a mistake in even one of those times and therefore anything that reduces mistakes is a good thing. So that concludes chapter 17 of the book and I definitely will encourage you to solve your problems at the end of that chapter and we will stop this lecture, thank you.