 Welcome back, in the last segment we talked about lambda expressions, in this segment we are going to talk about how to specify default values to some parameters of a function. So as a motivating example, suppose we are drawing lots of squares and say most of these squares are black, but maybe for some we want to specify a color. Wouldn't it be nice if we can say, if I don't tell you what color to use, make it black. C++ allows this. So here is how. One or more parameters occurring at the end of the parameter list can be given default values. You can choose. If you have 10 parameters, you may say that the last three will have these default values. So if there are n parameters and suppose you have specified the default values for last n, in that case you must give, in your call you must specify at least the remaining, the values for the remaining arguments. So again, say I have 10 parameters and I have specified default values for the last three, then in my call I must specify at least 7 values and these values will go to the first 7 parameters. Well, what happens if I specify 8? Then instead of using the default value of the 8th parameter, I will use the 8th value that I specify. What happens if I use 9? Then instead of using the default values for 8, for parameter 8 and 9, I will use the 8 and 9 values that I specify. So in general, if you give n minus m plus r arguments, then the last m minus r will be, will take default values. And r of the arguments for which default values were supplied, the supplied will not use the default values but instead will take the values that you have supplied. So I am going to do a somewhat elaborate example. So it is kind of a squares but this circles are simpler than squares and therefore we are going to use a circle example. So the goal over here is that we want to draw a circle or really a disk because it is meant to be, it could be a solid disk, a filled disk. So what is the function? What is the function call? We are going to first specify the center of that circle and then the parameter requires us to specify the radius but by writing equal to 10, we are saying that look if the user does not supply, if the call this parameter is not, value is not given, then the value 10 should be used. Then there is an additional parameter where you may specify a color but if you do not specify anything the color black is assumed. And finally there is a parameter fill which is going to be true if you omit it. And what is going to be drawn? Well first of all a circle is going to be drawn. Then we are going to set its color to call the color, the parameter over here. Now the actual value that we are going to use could be black or the actual value that you specify in the call. And finally we are going to decide whether that circle should be filled with that color or not. And whether to fill it is going to be dependent on this parameter. If you did not specify an argument corresponding to this parameter then it will be filled. Otherwise it will not, if you specify a false argument it will not be filled. And then finally that circle that you drew whose color you set and you decide that to fill it or not fill it will be imprinted. So you remember that if you call a function then at the end everything that is created inside this function goes away. But if you imprinted then that imprinted picture will stay on the screen. So I am going to show you the code which uses this. So it is that same function first and now I am calling this function with different number of arguments. So first I am going to call it with arguments 100, 120 which says that the center is going to be at the coordinates 100 and the radius is 20. And then the color is going to be blue and the fill value is going to be false. So I have specified all the parameters, I have given arguments corresponding to all the parameters. So this should produce a blue circle but which is not filled and of radius 20. Now here I have changed the center position, the radius remains the same and the color remains the same but I have omitted the last argument. So I have only given 4 arguments but if only 4 arguments are given then this last argument is taken as true. So this should produce a blue circle which is solid with color whereas the first one should be a blue outline but no color inside. Then I have a circle with center 300, 300 and radius 20. So what will this do? Well only 3 arguments have been specified. So this argument is specified, this argument is specified, this argument is specified. The last 2 arguments are not specified. So the default values will be used. So the default value for this is color black and the default value for this is true. So this should draw a solid black disc centered at 300, 300 with radius 20. And what does this draw? Well even this is not specified. So this, if this is not specified the radius is 10. So the last call will draw a disc centered at 400, 400. Its radius will be 10, its color will be black and it will be filled. So let us see and then the program will wait until you click so that you can see what you have drawn. So let us see what does, how this works out. So let us compile it and run it. So exactly as we thought. So we have a blue disc here but not solid. Then a blue disc, then a black disc and finally when we just supplied the center even the radius was taken from the default value and that was so we have a smaller disc which has been produced. So here is an exercise based on this notion of default values. So the k norm of a math vector x, y, z, w whatever is defined to be the kth root of x to the k plus y to the k and so on. But most, the most common norm that is used is the two norm. So this is kind of the Euclidean distance like thing. So if I have a vector a two dimensional vector x, y then the call x, y, k should really give me the kth root of x to the k plus y to the k. So the kth root of all of this. But I want to be able to make a call norm x, y without passing the last argument. So that in that case the default value of k should be 2. So this should really return the square root of x squared plus y squared. So as I said the default value over here is made to correspond to what happens most commonly. And to help you write all of this, so you may note that the function pow of xr returns x to the r for any r including say 1 over 2 or 1 over k. So if you use that then this should be simple enough to write but you will have to use the feature of default values. So what did we discuss in this? So we discussed how to give default values to the last parameters in the parameter list. And one point to note in case it is not clear is that if you want to specify a default value for the arth parameter then you must specify a default value for all the subsequent parameters as well. And as we saw this can help you write programs compactly and you can sort of make the common case a little bit simpler. Next we are going to talk about another feature related to how you define functions, the so-called overloading of functions and we will also conclude this lecture sequence. So we will take a quick break.