 Welcome to this course on data structures and algorithms. In the last session, we looked at an illustrative example of Mumbai Vada Power restaurant and we saw how the activities in the restaurant could be easily implemented using queues. Of course, we require some additional data structures. In this session, we will write a C plus plus program to implement the illustrative example and processes that we saw last time. The data structures that we will require first will be information to be stored for food and customer arrival. So, one structure we use is food info which contains information, food item, name and rate. We will of course, need an array of structures to store complete menu information. We will see how this is handled. Another structure we will require is customer info. This contains information of customer, ID and arrival time and this is the order in which they arrive and stand in the queue to place an order. We will require one queue which we call customer queue. It is of the type structure customer info because this is the information that we will push into the queue. Let us look at other data structures which are required for the orders place and the orders that go to the kitchen for preparation. So, we have a structure called orders which contains information of the order placed by each customer. Please note that there will be many more details such as individual items, their cost, etcetera. For this illustration, we are assuming that the only pertinent information to illustrate our queue usage is there namely token ID and cost to be paid. We presume that when the order is placed, the person pays that cost and the token ID and cost to be paid is the information that order placed by each customer contains. Next comes the kitchen data structures. Now, for kitchen we will have an array which will contain the information for all orders. Each individual order is stored in the structure order along with the preparation time for each order. This is where the orders which are placed in the queue are transferred once the order is placed. Once all orders go to kitchen, the items are prepared as per the preparation time. Of course, different items will require different preparation time. So, in order to dispatch these orders which are handled by another queue called order dispatch, we need to sort this array on the increasing order of the preparation time so that the order which requires minimum preparation time goes out first and so on. Finally, all orders which are ready for dispatch will end up in order dispatch queue which contains the token ID of the order which is ready to be collected by the customer. Let us look at the functions that we need to write. First and foremost, the back end information about the restaurant. So, we will have a load menu function which passes information of one item to the function set food item. The set food items in turn is a function which loads the details of complete menu of the restaurant. There is one more function to represent the arrival of a customer. This function simply pushes the information of the customer on the queue called customer queue. This includes customer ID and arrival time. Please note once again in this illustration, we shall be using some arbitrary arrival time because our idea is to demonstrate the user queue. Another function that we will require is we call it place order. Now, this place order will actually generate a token ID and cost which is assigned for each order placed by the customer. Please note that in actual practice, the order will contain many details of all individual items, their quantities, etcetera. But again for this simple illustration, we will just store token ID and cost. Now, once that is done, each order has to go to kitchen. You remember, we said that we shall have an array and in that array, when an order goes to kitchen, we shall store not only information about order place, but also preparation time for that order. Again note that the preparation time could be random in real life, but for illustration, we are using an arbitrary fixed time for every order. Another function which we require is for dispatch orders. As and when the orders become ready, they go to the dispatch queue and these orders then can be collected by the customers. So, the loading in the queue for dispatch orders, what is required is simply token ID. For this simplified processing, let us look at the program that we will have to write. First, different structure. The customer infrastructure has customer ID and arrival time. The food infrastructure has food ID, string which represents the food name and the rate, orders represent token ID and the total cost and struck kitchen which is actually struck of the type orders, order and preparation time. So, for each order, there is a preparation time associated with it which is part of the kitchen structure. Let us now define the class restaurant. First, the private members. So, we will put static customer ID with which we will start assigning customer ID numbers to different customers. We will have orders in kitchen, token ID, etcetera, etcetera. We have the struck type kitchen with say 100 items and food info which again has 100 items. Next, we look at the formation of queue. So, we define the queue which is customer info queue. We call it customer queue. Similarly, we have a queue which is order dispatch queue. We have already seen these queues earlier. This is a brief explanation of what a customer queue is. We have no public members which are essentially the function that we will be writing. You are familiar with all the functions. We have briefly seen them. Load menu, set food items, customer arrives, place order, order goes to kitchen and finally, dispatch orders. This is typically the sequence in which activities will happen and for each of these, we shall have different functions written. This ends the class. Of course, at the end of the class, we will require some initialization for class member variables. These are all set to 0, 0. These are arbitrary number 1000. We had used this similar concept in the bus queue also. So, all customers will start their numbering of token IDs from 1001, 1002, etcetera, etcetera. Next, we look at the set food items functions. This will get an integer ID, a string name and the rate at which a particular item is sold. We simply assign that ID, name and rate to appropriate components of the element by food index that we have. That is a simple function that we have. There is a load menu function. Now, ordinarily load menu will read the data about all different items and their rates probably from a file. Here, for simple illustration, we have assumed that there are 12 items. So, individually each item will set by giving the item ID, the name of the item and the rate. This will complete loading of the entire menu for the illustrative example. We now write the function for customer arrival. There, the parameter is time. We have the customer info, which we call simply CUST. We put in the CUST ID an incremented value of a static value that we have already assigned. That was 1000, if you will remember. So, first time this function is called. Customer ID starts at the base 0. So, the individual customers will be given ID is 1, 2, 3, 4 at this time. We also assign the time, which is passed on to this particular function as the time of arrival. Next, we push this particular information in the customer queue. For the benefit of confirmation, we print out the customer queue back dot customer ID and customer queue back dot arrival time. Please note that every customer arrives at the back of the queue and that is where we need to print the information from. Next, let us look at placing the order. Here again, there is a token number that is allocated to every person who places an order. The base is 1000, if you recall. So, every time an order is placed, the order token ID will be 1000, 1000, 2000, 3000, etc. Every time this function is called with a parameter of cost, all that we do is order dot cost is set to cost, order dot token ID is set to the next ID. We again print for verification purposes and we pop the customer from that queue. Why? Because the customer has placed the order, got the token, paid the money. Now, the customer has to wait separately for the fulfillment of the order, which will come through dispatch. Next order goes to kitchen. Every time an order is placed like this, it must be inserted in the array, which we have used to represent kitchen information. Now, we have K as an array. So, orders in kitchen is the serial number of the orders, which are received in the kitchen. This is incremented by one, every time a new order goes to kitchen. All that we need to store is order information and the preparation time. Once again, I will remind you, we are going to use an arbitrary preparation time for this illustration just to emphasize how queues are properly used. Next comes the important function of dispatching orders. Now, we presume that orders are prepared inside the kitchen and orders are prepared in the time of preparation that has been allocated for each order. Obviously, if there are 4, 5, 10, 20 orders, different orders will become ready at different time. Therefore, what we do is, we sort the entire array on preparation time. So, that is the lowest preparation time comes first, then comes the next and so on, which means that this kitchen array will now be ready to be used for dispatching function. All that we do is for I equal to 0 to order in kitchen, suppose there are 4 orders, 10 orders or whatever, one by one. We take the order token ID and the ith element of K and push it on to order dispatch. For the benefit of confirmation, we just print that the dispatch token ID is so and so on. Notice what we have done. In the dispatch order, we have assumed that orders are prepared as per the time of preparation. Using that, we have sorted the array on time preparation time, then we are simply pushing sequentially from that sorted array one order by another in that sequence to the dispatch queue. This brings us to the main program, which is actually very simple. We define orders as a struct, which we have defined. So, this is the order element. The restaurant is MVP restaurant or my Vada Power restaurant and some variable here. Now, we first load menu. Remember, there is a function. This load menu will complete loading of all the menu items from some back end information. You will recall that currently, we are giving fixed information for all menu items and their cost. Next, customers arrive. Usually, large number of customers will arrive throughout the day or morning or afternoon session. Here again, we remind ourselves that we are simulating by a simplistic example, where we have only four customers who have come. So, we have one by one. We are calling this function by giving the time of arrival, which again is arbitrary. Once the people arrive one by one, they will go to the end of the counter and place the order. So, the first person place the order pays 165 rupee and once that is done, that order goes to kitchen. Second person does the same thing. Third person does the same thing. Fourth person does the same thing. So, at the end, all these four customers have placed their order and their order along with the wait time, which again we have arbitrarily defined 5, 10, 6, 14, etcetera goes to the kitchen. Next, we simply invoke dispatch orders. You will recall that this function of dispatch orders actually sorts the kitchen array on the field of preparation time and therefore, dispatches will happen in the order in which the orders are prepared. That is it. Here is the sample output. If you execute this entire program, incidentally the program itself is given as a separate file. So, you can run it. It will show customer 1, 2, 3, 4 arrive like this. Order place for customer with token number this, token number this, etcetera. Dispatch token ID. So, the dispatch queue is fulfilled and this is fulfilled in the order in which the items orders are prepared in the kitchen. So, in this session, we have implemented the simplified model of Mumbai Vada Pav restaurant. In real life, there are so many things that are required to be handled. Later on when we study additional data structures such as list, we will see a more efficient way of handling order information in the kitchen, not necessarily using an array, but using something else. But for the time being, please do read this program in conjunction with the previous illustration of the last session, so that your well was with how queues are used to implement such functionality as is required in any restaurant. Thank you.