 Welcome back. In the last segment we discussed how default values can be given to some parameters in a function that we are defining. In the next segment we are going to discuss another feature which can make it easy, make it more convenient to write certain functions and that is the so called overloading of functions and in this segment we will also conclude this entire lecture sequence. So C++ allows you to define multiple functions with the same name provided they have different argument lists. So the term overloading is used and perhaps we should really be saying overload the name, overload in the sense that the same name means some different things and the same name can be used to refer to different functions. So that is what C++ allows. So suppose you want to write a function to compute the area of a graphical object. Now the name area seems like a good name and perhaps you might want to use the same name to find the area of a circle or to find the area of a rectangle. After all what you are getting out is the area. So why should you use a more complicated name? Now C++ allows you to do this. I mean there is nothing, there is no explicit new feature that explicit new construct that I am going to talk about. You just have to do it that is all. The only requirement is that the parameter lists should be different. So long as the parameter lists are different you can do it and the parameters lists are need to be different because that is how C++ will note that the two functions actually are different. Otherwise if you write f of some x and there are two definitions of f of x that is not allowed. But if you write f of x where x is of type real and if you write f of x where x is of type int then C++ will know which function to use if you indeed have two separate functions defined. So I am going to show you this file area dot cpp in which I have written such functions and let us get to that. So here is the first definition of area and we are having a function area which is going to return a double and it is taking as argument a circle C. Remember we said that type of the shape the name associated with a shape is that shape itself. So you can pass that shape over here and we do not want to copy that shape and therefore we are passing a reference but whatever we are passing it has type circle and it is a reference to a circle object. Now inside this function we can extract the radius of that circle. So there is a command get radius so I can write c dot get radius and that will get me the radius of this circle and now we know that the radius of a circle is pi r square. So this is a simple cpp name so pi stands for 3.141592 whatever the expansion is to some large number of decimal places and we just multiply pi by r by r and return the result. So this area this function expects you to send it a circle a reference to it and it will calculate the area and return that value. Then I have an area of a rectangle. So again what is expected over here is a rectangle object should come rectangle name should come but graphical object but what is actually coming over here is a reference to it. So this r really refers to the graphical object in the calling function and so rectangle can be operated upon by a command get width so that gets the width of the rectangle and this get height will get the height of the rectangle and if you just take the product you will get the area so that is what this area does. So in this main program I have first something which creates the canvas then I am going to create a rectangle. This rectangle is centered at 100 and it has width 50 height 70. This circle is centered at 100 and it has radius 100 as well. Now the finally I have a command which will calculate the area of the circle as well as the area of the rectangle. So before proceeding further let us see if we can guess what this area should be. So the radius of the circle is 100. So pi r squared is going to be pi times 10,000. So it should be something like 34,109 something something so that is what it should be. And the area of the rectangle well the width and the height are 50 and 70 so the area should be 3500. So let us see whether that is what the program prints. So let us compile this and run it. So indeed the program has drawn the square and the circle and this is this whole thing is a 500 by 500 canvas so it is centered at 100 as you might expect. And let us see what area has it printed out. Yes it has printed out 31,415.9 and you may see the 3.14159 is the value of pi so that is just multiplied by 10,000. And the area of the rectangle has indeed been printed to be 3500 and that is correct because the width is 50 and the height is 70. So let us click to stop that program. So here is a quick exercise. So the area function that we wrote was taking shapes as arguments but you can have additional area functions and you are asked here to write an area function so that if one double argument is given it should be interpreted as requesting the area of a circle with that radius. And if two double arguments are given it should be interpreted as requesting the area of a rectangle with those side lengths. So the code itself is not complicated but the point is that if you can define these functions which have different argument lists in this case the argument list is a double and for the first one and two doubles for the second one and in fact you can have all the four functions existing at the same time because the argument for the very first one was a circle and for the second one was a rectangle and then the third one is a single double and the fourth one is two doubles. So all such all four can be defined and depending upon what arguments you pass the appropriate function will be executed. So that concludes this entire lecture sequence so let me make some remarks. So first I should observe that it is often useful to pass functions as arguments in a function call and there are many examples of this. So common examples are writing a single function that calculates the roots. So I will write a single function that calculates the root and to it pass the function whose root I need. So I do not have to write a separate function to calculate the root of different mathematical functions and this goes not only for roots but also for say numerical integrals or you might want to sum series. So for summing series also you can do this and there we saw that you can pass functions by specifying their name or by giving the lambda expression. And one method that I have not discussed in this lecture sequence is a C style method. So the C language from which C++ has originated had a different method and that method is a little bit more complicated and if you are using C++ you might as well use the nicer methods and I did not discuss it today but for completeness it is discussed in the book. Though in this course you will not be expected to know it. Then we said that C++ allows default values for the last arguments in a function and then we also said that C++ allows defining many functions with the same name provided the parameter types are different. So that concludes this lecture sequence and as always I will suggest to you that please look at the chapter and the problems given at the end of the chapter and please solve them for practice. Thank you.