 So as I said, we are meeting here primarily to discuss the makeup test paper and answers, but I will also like to advise you how to approach a question paper. Each one of you must have your own style. Do you all read the question paper completely before starting anything? I don't think you do that. So what I plan to do is spend about five minutes in advising you how to approach a question paper in an exam and how to approach an individual question. And then we'll discuss the answers to the makeup test. So this is a very long thing on solving an examination paper. First of all, you should read the entire question paper, complete question paper, all questions you should read. What happens when you read it? You try to understand what that question is about. Then while reading the question, you also form an opinion in mind. This is simple, this is difficult. You should arrive at this judgment for all the questions. And what you should do? You have a question paper in your hand, question one, two, three, four, five. So whatever judgment you have arrived at, you break it into three categories. It's a simple, medium complexity and difficult. So I was just telling people that the approach to solving a question paper has to be first you read all questions and then in your mind, you classify questions into simple, medium and complex. And what category do you classify? You say simple means you generally know the answer. You can write the answer. The medium means you have a general idea, but you have not done a similar problem. So you may have to do some working on it. And difficult means you have no idea of the solution. Now you arrive at one more judgment that every question that you read, this is simple, but how long it will take me to solve? Five minutes, ten minutes, eight minutes, twenty minutes. This is difficult. So I don't really have an idea. So my estimate may be wrong, but it will be always on the larger side. Then you say medium. You can form some idea, I will need some. And then you mark each question on your question. So let's say nine questions, fully read that question. Let it take ten minutes. But I am telling you it is worthwhile investment. Because first of all, when you read, you understand. Later on, when you try to solve the problem, that understanding will remain in your mind. You would anyway have to read that question completely when you attempt to solve it. So you read it first. And then write on your question paper against question number one. You say simple, five minutes. Question number two, simple, ten minutes. Question number three, medium, fifteen minutes. Like I have written here. So I am taking this question one, simple, ten minutes. Question two, simple, three minutes. Question two, simple, five minutes. Question four, medium, fifteen minutes. Like that. Notice that questions become difficult naturally. And the time required is more. Now if you add up all this time, you will find that you cannot solve the paper in two hours. This is your individualistic. Anybody who has done a lot of programming in life, he may be able to come up with estimate which will say in one hour he can solve. Suppose I have not done much programming, I may say it will take three hours. Now if that happens, what should be the approach? The approach is clearly now to identify what questions I will solve. And then spend entire two hours on those questions rather than attempting everything very quick. So what happens psychologically, if you see ten questions, you will be under tremendous pressure throughout the test. And then sometimes what will happen is you will go to one question. Then suppose you are halfway through, you are stuck. You will leave it, go to another question. Again you will get stuck halfway through. Another one and a half hours you will find that you have six partially solved questions. Now suppose you come back to question one. What will happen? You will have to spend one more time to read that question again, to remember what you were doing and do that. So you have actually wasted your time. So the approach is that you first classify the questions, estimate for yourself how long it will take. For example, I have estimated for myself. Now you notice 20 minutes plus 20 minutes plus 20 minutes, 15 minutes plus 25 minutes, 10 minutes plus 15 minutes, now if I go backwards, I will never be able to solve a simple problem. So what should happen? If you have a strategy, select all the simple problems. Once you know that these are the questions you are going to attempt, believe me, if you attempt only 50 percent of the marks, but you can get full 50 percent score. Because you are now clear that in these two hours you have to do only this, you will not be wasting your time doing here and there. Suppose you are able to finish those earlier, then spend the remaining time on the other. This is the best strategy, second. So once you have selected the questions, start with the simple questions. Now how do you approach an individual question? Now read that question once again. Abhi deko pehli baar paratha, second time again you read, you will now understand it better. This time you sit down and formulate an approach and write down those rough steps. Now this is something you never do, you start writing programs. The ideas which occur in your mind, you don't write them. You may be worried about writing correct English, but if you are writing rough steps, how does it matter whether it is English, Hindi, Telugu or whatever, it is for your own sake? So why can't you say rough and say step 1, 2, 3, 4? This is how I will solve it. And then when you start writing program or start writing answer, write in the appropriate English or C++ syntax whatever. This will help you because once you have written down the steps 1, 2, 3, 4, then you will know you have to do this, then do this, then do this. So you will not forget anything. Now after writing the answer, suppose question 1 you have finished. Before going to the next question, quickly read and check the answer. Because you are in a time pressure, after solving it once you will go to the next question. You will say that at the end I will come back. And you know what will really happen? Suppose you get stuck at some questions, then you will come back to this question. But by that time you have forgotten what you have written. So you will have to read that again very carefully, you will be wasting your time. So the approach should be once I take up a question, I will solve it methodically. I will check it myself once again. And once I have done that, I will never come back to it. Never. Okay. This strategy it is obvious in many other walks of life. Games we play. Do you play chess? Everyone knows how chess is played. So I will tell you one difference between an amateur style and a professional style. Suppose I am an amateur and I am playing chess. After some moves the situation will become complicated. So what I will do now? I will say suppose I move my pawn here, what will happen? I will think he may move this, he may move that. But after two or three moves I am confused. So I will forget that and I will say, okay suppose I move my queen here, what will happen? Then after some time I will say, suppose I move my knight here, what will happen? And after doing this I will again come back and examine what if I move my pawn again. So what you are doing is you are going again and again wasting your time visiting everything. What does a professional do? If he says okay I will look at the pawn, then he will look at all possibilities with the pawn. If I play this pawn that fellow may move his knight, I may move my bishop, some two, three moves he will analyze in his mind. And he will generally arrive at a result good or bad. So suppose he says good, he will store it in his mind. When he goes to see other alternative like moving a knight, after that he will never come back to revisit that pawn. If you want to think about the pawn, then think about it. That is how he saves time. And when he has to make a move, forty moves in two hours, he is able to maintain that time because that is the discipline. In general this approach is useful in life while solving all hard problems. I am saying this in the context of question paper but this applies everywhere. Any problem you will have alternatives? You have to examine those alternatives. You examine one alternative halfway through, then examine second, then examine third, then examine fourth. Again you visit the first alternative and again start spending time on evaluating it. You lose time. This is not necessarily will give you the perfect results but this will give you the best results in the available time. So this is the approach I suggest. It is in this context that I will try to see the solutions to the problems that you have. Let's take question one. So I have tried to write here the thinking. Remember we have already identified as a simple question. We have estimated some time, five minutes, ten minutes, whatever it is. But now I am again reading this question. So let me read this. It says, write the exact output when the following program is executed with input formed by the last digit of your roll number. If roll number is 1 1 0 5 0 0 3 8, input for R is 8. If it is 1 0 D 1 4 1 0, input for R is 0 etc. So what I have understood? The input to this program is last digit of my roll number. You will notice I have written here. If my roll number is something, so the input is 6. Now answer. What does it say? Write your roll number first and then write the output. The output means I have to execute this program. Now when I execute a program, usually what will happen? That program will have some input statement, some assignment statement, calculations, some iteration, some if. All of these work on variables. So which variables does it work on? The variables which have been declared in the program. Here is what I will do. All of you have this question paper. We will start going through this question paper and follow this approach. Execute each instruction of the program. Write the values of different variables, array elements to which any assignment is made. A value can change only when an assignment is made, otherwise it will not change. So any assignment is made, I write down that value. And I keep writing that. If there is an iteration, I will go through the loop as many times as it wants. Keep writing that. You will notice that at the end, when I write the output, I can never make a mistake because I would have almost acted like a computer and executed. In real life, what you do? You solve this mentally. Or this is, my roll number is 6, so this becomes 5, this becomes 4, and then you will write the final answer. Maybe you can make a mistake in that process. So let us follow this process and see what do we get. So you have to tell me, I will assume now that the last digit of my roll number is 6. So when I start looking at it, it says int R, N, K, M, A, B, C, D, A5. Okay? It says array A and all others are R, N, K, M, A, B, C, D. Now when I have read the paper, I know what is the output being produced? A, B, C, D. See, out statements are with A, B, C, D. So A, B, C, D will be my final output in any case. Let me write them in this corner, A, B, C, D. Because some value will come there once, that will become output. Other variables, I will notice what are the corresponding changes. Immediately I have for K equal to 0, K less than 5, K plus plus, A, K equal to 0. Let me write down the other variables. One is R, the other is N, the third is K, fourth is M. So I have written all the variables which have been declared. Now I start executing the program. So now you have to tell me what does the next statement do? For K equal to 0, K less than 5, K plus plus. So this is an iteration by counting. It will vary K over what values? 0, 1, 2, 3, 4, because less than 5. And what it is doing? A, K equal to 0. This means what happened? Here all the values have become 0, 0, 0. All values have become 0. Next one it says input R. Now R is getting value. So what is going to be the input? The last digit of my roll number. I am assuming last digit is 6. So R becomes 6 now. I go to the next step. N is equal to R by 2 plus 1. Now if it is 6, R by 2 will be how much? 3, 3 plus 1 will be how much? So N has become 4. Just for the sake of it, because some people will have odd roll numbers. Some people will have even roll numbers. Suppose your roll number was 5. So I will also write it for 5. If it was 5, what would have been N? R by 2, 5 by 2 is how much? No, not 2.5 because it is integer division. So it will be 2 and 2 plus 1 will be 3. So far we are so good. Now next statement. Value of N is N. So value of N will be 4. What will be the output? Value of N is 4. Correct answer? No confusion there. Next it says for K equal to N, K greater than 0, A plus equal to K, K minus minus. And there is no body there. So that means only an iteration is moving. So what is happening? K is now starting with N. And what is the lower value? Up to K greater than 0 it will continue. So when K becomes 0 it will stop. So that means from N down to 0, K is going to move. Initial value of A is how much? Initial value of A is 0. So I will write here. This was K. So what is A now? Initial value of A was 0. What I am saying? A plus equal to K. Initially A is equal to 0. If one iteration ends, then what will be its value? This is same as A equal to, means whatever A's value is, K will be added. So now when K is N, what will this become? What is the value of N? Say 4. Let's forget this, we are taking this value. So N is how much? 4. So 0 plus 4 is how much? 4. Then K minus minus. So K will become 3. Now what does this statement A equal to A plus K will do? 4 plus 3. 7. This will become 7. Then 3 will become 2. 7 plus 2 is 9. Then 2 will become 1. 9 plus 1 is 10. Will this become 0? No. K greater than 0, only I am doing up to K equal to 1. But when K is equal to 1, that is the last time this iteration will be conducted. After that, the last increment operation will be executed. K minus minus or A plus equal to K will be executed. After that, when the iteration will come back, at that time it will discover K is not greater than 0 and it will terminate. So what will be the value of A at the end? Whatever is the last value here? So output will be, value of A is 10. Suppose you had started with N is equal to 3. So what happens here? A is 0. K is initially 3. Then it will become 2. Then it will become 1. And then it will become 0 when you come out. If it was initially 3, 3 plus 0 how much? 3. Then 3 plus 2 how much? 5. Then 5 plus 1 how much? 6. So what will be the value now? 6. So can you now see whatever is the final value is to be written? Do you agree that doing it mentally is not a good idea? Writing it down is a better idea. So if you write this down, you can never make a mistake. Let us look at the next steps. So B has been printed out as either 10 or 6 whatever depending upon your input number. Now I start with M equal to N and K equal to 0. So what is the value of M? And remember we had concluded what was our N? N was 4. Right? If my input number is 6, N was 4. So M is equal to N means M is equal to 4. K is equal to 0. And I am trying to calculate the value of C. If I read the program at the end it says C is equal to A4. You know whatever is my array A whatever is this element value I am going to print because it says C is equal to A4. So whatever is the value in this location that will get assigned to C and that will get printed. We have to find out what that value is. So now we go through this iteration. What is it saying? The iteration says do A K plus plus equal to M plus plus. While first of all tell me the meaning of this iteration. Again what is happening inside each iteration? A K is being assigned the value of M and after that K is being changed M is being changed. So if I am not sure in my mind I can actually write this down saying that look this is equivalent to what is it equivalent to? A K is equal to M. K is equal to K plus 1. M is equal to M plus 1. Correct? This is the meaning of it. Once I write this it will be very easy for me to look at whatever is happening. So I will now execute this iteration. Starting value of K was 0. So first of all I am going to say A0 is equal to M. What is the value of M? 4. So A0 is 4. Then I am changing K so K becomes 1 and M becomes 5 because M is equal to M plus 1 I have written. Each K less than 5 answer is yes. So I will come back to the iteration again. I will re-execute these statements here. When I execute what will happen now? A1 will become 5. So 5 will be written here because K has become 1. And then I will again increment K and M. So M will become 6. K will become 2. This is less than 5. Again I will go back. Again execute the statement AK equal to M. That means A2 is equal to 6. Here I will write 6. And after that again this will become 7. This will become 3. Okay. I come down. Is K less than 5? Yes. It is still less than 5. So I will again execute these statements. What will happen inside these statements? AK is equal to M. A3 is equal to 7. So I will put A3 as 7. Okay. And now again execute these statements inside the loop. So what are these statements? K is equal to K plus 1. This will become 4. M is equal to M plus 1. This will become 8. I again come back to the last statement. Why K less than equal to less than 5? Is K less than 5? Yes. He is suggesting that because K plus plus appears as a standalone expression in the index K will increment automatically before assigning to AK. If that happens then the whole program will not work because I will be trying to assign something to A6 which does not exist. Anyway let us follow this logic. We will see exactly what happens. While we speak he is I think testing that program on the actual machine. Has anybody run this on the machine? Nobody has tried it. Anyway, let us go through this logic. We will come back and correct it if necessary. Fine. Abhidha kama ayam log K has become 4 and M has become 8. So what it means is A4 should be assigned the value 8. So 8 value will come here. Still the program is not over. K is equal to K plus 1 is still remaining. So K will now become 5. M is equal to M plus 1 is still remaining. So M will become 9. But now when I come to the while while K less than 5. Is K less than 5 now? No. So I will come out. When I come out I say C is equal to A4. And then now C will be assigned a value which is this. So that means it will become 8. And when I say C out C is so much it will become. Now tell me whether you attempted such a thing. You wrote your answer like this. You got the correct answer. And you got full marks. In this part you got marks. What was the answer that you wrote? Your roll number is 4. So what was the value of N in your case? How can N be 4? R would be 4. So what is N? N is 4 by 2 plus 1 which is 3. And for 3 you work this out. So what would have been your answer in this case? You will notice that if N is 3 you will start M with N. So you follow the same logic. In your case M would have started with 3 and it would have become 4, 5, 6 and 7. Isn't it? So you should have written 7, 5. But you will notice how to write it. Now if you write things like this even as a rough work there not only you can make no mistake but people who read your answer will understand what logic you are trying to apply. Instead if you just write your answer this if it is wrong you get 0. If it is right you get full marks. Suppose there were 4 marks for this question and you get only 0 or 4. But if you have written this then somebody who is reading the answer will say this person has tried to think like this and maybe you will get some partial marks for your thinking. So it is always better to write like this. In exactly the same fashion you should work with all the remaining parts. There is only one remaining part here we can solve it in this simple case here. D is starting with 10. Now what is the question? The second part D is equal to 10. Switch N. What is the value of N we have taken for ourselves? 4. So our N is 4. But it could have been 3 whatever whatever. Now let us read the statement case 1, case 3, case 5. If N is equal to 1 or N is equal to 3 or N is equal to 5 it will do whatever it says. Is our N 135? No. So this does not apply. The next one says case 2, case 4. Our case is 4. In that case what it is doing? D is equal to 10 minus N. N is 4. So D will be equal to 10 minus 4 which is 6. I can write 6. If N was 2 I would have written 10 minus 2. But if N was 1, 3 or 5 what would be D? Minus of that number. Very simple. So it has taken time to explain but you will be able to do it very quickly on piece of paper right? Not an issue there. Consider now question 2 and question 3. These have come together because the paper says for question 2 and 3 this is the problem. Now let us read the problem. What does the problem say? A mathematical function is defined over x as follows. f of x is equal to 13.66 square minus 284.7x plus 98.2. And then it says following formula is given to calculate a value v. v is equal to f of y plus f of minus y upon f of z plus f of minus z. This is the formula and the function. Now the question 2. Write a c plus plus function which calculates and returns the value of f of x for any given x. And second question 3 says write a program which will take values of y and z from the user and calculate value of v by calling the function written in question 2 above. So what I have to do? First I have to write a function. That function should do what? Take a value of x as a parameter and return a value of f of x. First part I should always write a function prototype not the complete function. I have to give a name to the function. So let me write this as I will call it fun. This is the name of my function. It has to have some parameters and it has to have a return type. Now what is the type of parameter I will get? It is supposed to calculate something given x. But you can see the expression. They are all fractional values. That means x is expected also to be fractional. So I can write what value will it return? Will it return integer? It will return float. So I write float here. So this is the main function statement I have written already. It is very quick. Float, float, one parameter, one return. Suppose I have given you a function of x and y. Then you would have taken two parameters and you would have written one value. Now I have to write a function. So I start with a opening curly bracket. I have to calculate the value of the function and return it. There are two different ways of doing it. I will assume that I define something called a result. Since the value to be brought back is a result value which is floating point, I am naming it something. And is it not simple to simply say result is equal to? What should I write here now? Yes. 13.6 multiplied by x square. x into x plus, sorry, minus 284.7 into x plus 98.2. I have written that equation for the function. Now I have calculated result. I should return the result value. So I will simply say one function. You see how easy it is to write the function? Is it necessary to declare an additional variable result? Assign, calculate and assign a value to result and then return it. Is it necessary? If not what else can you do? Suppose I say don't declare an additional variable called result. I can write the function as you see I have to calculate one floating point value and return it. I needed one expression to calculate it. Since that is the only thing I have to do it is perfectly possible for me to write an expression and say return that expression. Of course, c plus plus will not return the expression. It will calculate that expression and resulting value it will. So I have saved one variable and I have saved one statement result equal to this. However it is in my opinion a better programming practice to always write the function let's go to the previous slide like this. Why? It is clear to everybody what you are doing. Second, suppose somebody says that the calculation of result is complicated. If x is less than 10 you do something. If x is greater than 10 you do something else. Then you require an if then statement you can't write it just in the return. In general it is a good idea that in a function whatever is to be returned whatever is that type you declare a variable of that type. Calculate the value of that type and say return that variable. Please note the difference thing. This only defines that the value returned by the function will be of type float. What you are returning is not known. That will depend upon what you have written in the function. What you are writing here float is declaring a variable called result. Now this declaration of the result you can declare 20 variables if you want. Every time you declare a variable you have to define its type. It is not necessary that you return result. You may return anything else abrakadabrakad. C++ compiler doesn't know what you are going to return. But C++ compiler wants that anytime you define a variable it should be given a type. Then only it is a valid declaration. So in float whatever else you want you have to declare it. And after declaring then you can use it. So please note that the fact that the function returns a floating point has nothing to do with whatever you write here except in your return. In your return whatever you type is treated as an expression actually. Even if you are declared this as integer because you have said float here the integer value would have been converted to floating point and sent back. So what you return is what is defined in the name of the function. But what you write here if at all you are using a variable 1, 2, 3 whatever you have to declare all of those variables. These are all called local variables inside that. I should be correct. I didn't tell you that coming here I had executed that program myself. If I had said minus minus k you may try that. If I had said plus plus k then what you say would have happened. Okay anyway. So you have understood this this is how I write the function. But I have to write the main program. Now what does that main program say I will now look at question 3 and I will write here only and somewhere in the margin I will say question 3. So I start writing int main now in the main program what am I supposed to do the problem question 3 says write a program which will take values of y and z from the user calculate the value of v by calling the function written in question 2. So there are 2 values which are supposed to be read y and z and then I have to use that formula to calculate. So I have to calculate the value of v and I will have to read values of y and z clearly I require 3 variables all of them are floating point so it is very simple I will say float y z and v I have to read the value of y and z I am asking the user to give me values it is only proper that I give a message out first what should I say see out give values of y and z is that correct that if I knew I would have done that but if I do not know I will be able to do this he is suggesting an additional thing he is saying I say care c h 3 and he says c h 3 is equal to c h minus 50 so basically I am saying I don't know what you are giving me I don't know whether the other form will be on that side or this side so I will test both I will test against your c h I will test against c h 2 and I will test against c h 3 if a character is equal to anyone I will add the count now I can form a strategy of roughly writing my code properly I can for example having done this I will say n is equal to string length of sentence do you remember this function string length it will calculate the string length then I will say count equal to 0 and now I will say for I equal to 0 I less than n I plus plus and what I have to say if the ith character of sentence is equal to anyone of these so what will be my if statement now if sentence I is equal to c h or sentence I is equal to c h 2 or sentence I is equal to c h 3 I will say count plus plus that's it I am examining each character in the sentence if that character is c h or c h 2 or c h 3 I increase the count at the end if I just say c h so you see I have constructed a perfect program now I need to just write it properly