 Okay, coordinate based graphics, this is how you might, how simple CPP lets you do things. Circle C1 200, 225, 225 will create a circle called C1 centered at 200, 225 with radius equal to 25. Okay, similarly you can create a rectangle if you wish called R1 centered at 200, 200 with width 50 and height 70. You are allowed to move around or rotate these objects, so if you say R1 dot right 45, then that rectangle will turn, okay, through its center. C1 dot move will cause that circle to move 10 steps to the right, 10 pixels to the right and 20 pixels above, okay. And an elementary, this is something like lecture four or something like that. An elementary graphical input facility is also provided. You can say int z equals get click, okay. What this does is it waits for the user to click on the screen. Then whatever coordinates x, y the user clicks at, 6553 times x plus y is sent back, so z gets that value. So if you want to know where the user has clicked, then you have to take that z and divide it by do integer division by 65536, that will get you the x coordinate, do modulus by z percent 65536, that will get you the y coordinate, okay. So basic clicking, basic graphical input has been established, okay. So at this point, reasonably interesting animations can be done. You can move around squares, circles, things like that. You can click, you can say, oh, I want that circle to come over here, all those things can be done, okay. So what are the educational goals? People are having fun, but we should also have some education going on, okay. So implicitly, we have introduced the constructor and members in tags. As you can see, this C1 of 200, this thing is just a call to a constructor. I'm not going to tell the students anything about constructor on the first day, okay. But I'm going to tell them that this is how you create a circle called C1, okay. I'm not going to tell them about constructors. Similarly, what is going on over here is dot right is just a member function call. I'm not going to tell them that this is a member function. I'm not going to tell them about objects or anything like that. They are focusing entirely on drawing things, making rectangles, moving them around, okay. But implicitly, they are learning. They are learning constructor syntax. They are learning dot notation and everything like that. Okay, now I want to talk about recursion because I think recursion is a really important idea in computer science and its counterpart, induction, is the most important idea perhaps in mathematics. So recursion and induction are among the most important ideas in computer science and mathematics, okay. So first I'm going to show you a demo which will enable you to draw what I call a mathematical tree. Well, a mathematical tree in the sense it doesn't look like a real tree. It's kind of a tree that we draw in computer science. So there is a branch, so there is a root, then two branches, two branches, and so on, okay. I'm going to draw it from bottom up. You usually draw it from top, but that's okay, all right. So this, the tree has a natural recursive structure, yes. The left side is just a small tree, the right side is just a small tree, and the whole thing together is a big tree. So it has a natural recursive structure. So we can use this, the graphical, showing this graphically, will just be a mirror of this relationship, okay. I'm also going to, okay, so the recursion becomes visible, we'll see that in a minute. I will also draw something which looks like a realistic tree, okay. This again is drawn using recursion. Again, it has a very tiny, very simple looking program, but that simple looking program does some interesting magic, okay. So, okay, so let us, let me, let me go to that. Yeah, so, so I have slowed down this drawing. Otherwise it happens very fast and it doesn't tell you in what order things get drawn. But you noticed how it got drawn, right? The left side got drawn first. Even in the left side, okay, let's run it again. Maybe I should have slowed it down further. The left of the left gets drawn first, then the right of the left, and so on, okay. So let me show you the program, okay. So this is, so you see that the program fits in this, in this tiny, tiny screen. So it is, there is a, there is a recursive function which contains a weight. So one, two, three, four, five, six, seven, eight, nine, there is a recursive function and then there is a main program which is just three lines, okay. So that's what, that's what, that's how large the program is. I want to show you one more recursive program, okay. So, okay, so let me show it to you first. So the tree, you can see that the tree is fairly small. The tree function is just about this long, okay. And then the main is just this, okay. The main is also very small. So let me explain, let me execute this, okay. So this is also a recursive program, okay. But there is a little bit more going on. I'm cheating here. I'm doing, there are things going on here which I have not told you about, okay. So what is happening over here is that when I'm making a recursive call, I'm passing the turtle as a parameter. So that's why you're seeing many turtles over there, okay. And then the turtle is a graphical object. You can scale it down also. So some scaling is also going on there, okay. As a result, you get something like this. But this is, this is drawn by using that very short program, okay. So I'm not drawing one branch at a time, okay. It's just, just recursion at its sort of very, very exciting best, okay. Okay, so drawing a realistic tree we saw, okay. So now I want to talk about other uses of graphics. So the way this graphics has been implemented, you get the code by the way, okay. So you get the code, so you can see how the graphics has been implemented. Now when we are talking about inheritance during the course, we have to have some good examples. This graphic system itself is a good example, okay. So there is a superclass, there is sort of a base class called sprite, which contains all possible graphic subjects. Which is a superclass of all possible graphic subjects. Rectangle, circle, polygon are subclasses of sprite. Turtle itself is a subclass of polygon, okay. You can see that in the code that will be supplied to you. Like everything that happens in, like the usual where it happens with inheritance. The sprite will hold all attributes which are common to all the objects in all classes, okay. So for example, data members like where that sprite is to be drawn. Every sprite has to be drawn somewhere. So those coordinates will be present, okay. It is oriented in a certain manner. So that orientation will be a data member in the sprite class. Movement, every sprite can be moved, left, right, whatever. So all that is also a member function in the sprite class itself. However, the subclasses will hold information which is special to those classes. So for example, the rectangle needs to have some additional information. What additional information do you need to keep in order to be able to draw a rectangle? Can somebody tell me what additional information do you need? What information do you need in order to have a rectangle? Width and height you need. Position is already there. Position is already there in the sprite class. But in the rectangle class, you need the width and height, okay. So there will be data members width and height. But there is also a member function which will actually draw that rectangle. So this function will be different for every class. So there will be a different function for drawing a circle, okay. So this hierarchy, the inheritance hierarchy, there is a built-in example we have once we do this graphics. Okay, there are a few other uses of graphics. You can generate interesting examples. There is a formula layout example. There is an example of n body simulation, which I will talk about. Then in general, you can do visualization. And visualization I have found helps remove bugs. Because if there is a bug, then that will get seen in glorious detail, okay. All right, now I want to come to some traditional issues in introductory programming. So this is the same list, so let me just go over it, okay. So this is always a contrary when we teach introductory programming. What is the difference between algorithms and programs? Of course, we can give definitions, but operationally what is the difference? When I think of writing programs, I think of when I think of program design, I think of writing a program in which you basically know what needs to be done, okay. So if you are given pencil and paper, then you would be able to do all the calculations and you would be able to produce the result. That is what program design is. Algorithm design, on the other hand, is figuring out what needs to happen in order to solve that problem. What calculations do you need to do, okay. From time to time, people sort of mix these things up. People might say that, oh, I want to ask a difficult question in CS 101. And then they ask a program design question, I'm sorry, an algorithm design question, which in my opinion is not quite fair. I mean, that is not a part of the course. So you should ask questions which are parts of the course rather than questions outside. So the important point to be noted is that for introductory programming, the focus should be on program design rather than on algorithm design, okay. However, recursion I make an exception for. So recursion is an algorithm design technique which has to be understood, okay. Maybe not understanding how to design new algorithms, but even to a certain extent, because it's a new way of thinking and it's really fundamental, okay. So I have lots of examples of recursion in the book. One more thing that I have done is that although I'm saying that the focus is not algorithm design, it's something like this. If you are learning a new language, okay. Say you are learning French, okay. So learning French becomes more interesting if you sort of read some French literature, right. Otherwise you are just reading meanings and words. That's not very interesting. You have to learn, you have to read something interesting. So analogously I feel that when you are learning programming, even though you are not going to invent new algorithms, you should study some interesting algorithms, okay. So the book contains lots of interesting examples which have been explained, okay. So some of these I'm listing over here. There are several of those which I'm not listing, okay. And there also are some advanced chapters which are meant to excite the students to go further. And so they have just been just to vet their curiosity, okay. And coding many of these is left for exercises, but the explanation is in enough details so that people can actually write the programs once they understand what the algorithm is doing, okay. Should we teach object, how should we teach object-oriented programming? Many, there are, we did a survey of how programming is taught. And we found that there actually are people who teach object-oriented programming from day one. On the very first day they will introduce what is an object, what are member functions and things like that. But by and large that doesn't seem to be a good idea. I mean that seems to be a very tricky idea, okay. Because I think it is like putting the cart before the horse. I mean if you want to have object-oriented programming, then you have to understand member functions. Or you have to understand members. But how can you understand members without understanding simple variables? So there is a lot of difficulty. My philosophy is fairly simple. I pose problems, okay. I pose the simplest problem first and then make more and more complicated problems. And I teach whatever is needed to program to solve that problem. So in this course, eventually you will get to a point where yes, now object-oriented programming is needed. In my opinion, that is the point at which you should teach object-oriented programming, not earlier. Everything should be driven by this utility idea. Students should be able to see why we are doing things, okay. So there is a chapter on inheritance-based design. So inheritance is treated very, very seriously. There is a chapter on it. In fact, an application has been developed in an earlier chapter. And then that application I rewrite, okay, using inheritance. The new implementation is nicer in that it is easier to extend it, okay. And in fact, a non-trivial extension is actually worked out in the text, okay. Software engineering, I would like to make a few comments, okay. So first of all, writing the specs of a program must be stressed, okay. Many bugs come up because students start programming without fully understanding the problem. So it is really important to write down what is the input? What is the output? What are the conditions? What are the constraints between the input and output, okay? This is easy to say and very easy to forget, okay. I mean, we tend to think that, oh, I have understood the whole thing. But then we forget that there are these corner cases that we have not understood. And our students are like us. So writing things down is important and I have tried to stress that. And for the more difficult problems, I have tried to write down the specs to somewhat gory detail, okay. I think invariance and program proving are also important, okay. Not because I believe that every program should be completely proved correct before it is released out into the open. But because the basic skills are important, okay. You should know what it means to prove the correctness of a program, okay. So I have discussed this. I have discussed this with several examples and from time to time I have asked students to write down invariance. What do you think the value of this variable be at this point in the program? Okay, so things like that, reasoning about your own program is very important. And this is extremely important because I've seen students try out a few examples. And then they declare that, oh, I have a running program. I mean, these students have to be challenged and they have to be made more responsible. I also have a discussion about how to generate test cases. Nothing very, nothing very earth shaking. I mean, the usual thing, sort of try to make sure that all corner cases are covered. Use some random cases and things like that. But by putting a chapter in the book, I think students will do it more, more conscientiously, okay. So some of these things are things that we know but we don't always carry out. There is a discussion of libraries. String vector map are covered in reasonable depth. They're also developed from scratch, a baby version of the string class, okay. So this illustrates memory management and class design in general, okay. The priority class, the priority queue class is used and they're discussed also in the chapter on simulation. Okay, there are a few unusual topics that I discuss. In the 2011 standard of C++, a really nice idea, which was there earlier in the scheme and list and all such languages, called lambda expressions has been presented, okay. This is sort of an alternative to function pointers or function objects, which you might be knowing or you might even be knowing this, of course. But it makes several things very, very compact, okay. So I have given some prominence to this idea. I discuss in fair detail things like reference counting because the moment you step slightly outside the introductory arena, you should not have, you should be able to use memory properly. So there is an appendix which talks about reference counting. And there are some very nice language features already. C++11 again has some very nice language features for doing reference counting. I spent a fair amount of time on simulation, gravitational simulation, airport simulation. I also have a chapter where there is an example of Dijkstra's algorithm. So Dijkstra's algorithm can be viewed as a simulation of a real life system. So I discuss that real life system and I simulate it and as a byproduct of it, you get shortest path calculation, okay. So, okay, so I will do some of these demos. Okay, so plate design you have already seen, line fitting I will show you. Okay, so let me just go. Okay, so line fitting is probably something that you have done. Okay, so it asks me how many points I want, so I have given five points. Okay, and now I have the screen on which I'm supposed to click in five points. What has happened is it has fitted a line, the best possible line through these points to minimize root mean square error. Okay, I guess I have set it up so that it goes away very quickly. But anyway, the point is made, right? Okay, line fit, then I, yeah, so why am I doing this? Okay, so this is a programming exercise. As far as it's math is concerned, it's a fairly straightforward piece of mathematics. But the point is that this example, this programming exercise, becomes much more real when instead of specifying the coordinates by typing them in, you can click the coordinates on the screen. And then instead of printing out an equation of the line, you actually see the line on the screen, okay? So people will be much more interested in solving a problem like this. If they have graphics, if you just give it to them as a problem, as a textual problem, they will solve it, but they will not have as much fun. And they will not, I mean, they will not like it that much, okay? All right, so spiral we saw, okay, button-based controller, then tree drawing we have seen, okay, button-based controller, formula layout, gravitational simulation, airport simulation, okay? Yeah, by the way, all of these require less than 250 lines of code. Many of them require less than 50 lines of code, okay? So you may be tempted to think that many of these are difficult problems, but they really are not. Please read through before deciding to classify them as difficult, okay? All right, so I want to show button-based controller, formula layout, and simulations, all right? Okay, so this is another way to control the turtle. So what I'm going to do is I can manufacture buttons now, okay? So I have everything, simple CPP is everything so that you can manufacture buttons. So I can draw rectangles, the button is nothing but a rectangle. There is a text class, text is a graphical object, so I can place text in it. If I click on forward, the turtle moves forward. If I click on left, the turtle turns. I can go back and I can make it go forward, okay? So I can keep doing this. This can be done in week two or week three. The only additional statement it needs is the if statement. The moment you do the if statement, you should do this because it's sort of, I mean, as I said, you have to keep the excitement going. So this is a way to do that, okay? So it doesn't require that much, but people use buttons all the time and they see here that, look, whatever they use, they can themselves manufacture. Okay, layout, okay, so this is the formula layout problem. This is really small, isn't it? Unfortunately, this control plus plus, control shift plus will not work on this. So there must be a zoom or something. It will not work on this. So I will just explain it on paper. So I want to draw a formula which looks something like this, okay? So even this is too small. So what is the problem over here? I have a formula like this and I want to use the graphics machinery to draw this on the screen, okay? So how will I specify this? I will specify this as say one plus, one, sorry, one upon, okay, let me just write it, one plus, one upon, one plus usual, like our usual expression, I will specify it. I want to write a program which will take this description and generate this, okay? So this turns out to be a nice example of recursion. It has been discussed in the book. I wanted to show it to you, but I guess I will not, I will not worry about it because this thing is turning out to be rather tiny right now. So I'll just go on to the next demo. Okay, now what I'm going to show you is a gravitational simulation, okay? So there are planets, they have velocities and they attract each other by gravitation. All of these you can calculate, right? So if a force, if a body exerts a force on another body of attraction, then that force is in a certain direction. And the force is proposed by Newton's law. The force is equal to the product of the masses divided by the square of the distance in between them. So you can calculate these things. And based on that, you can see, okay, the earth is currently right now over here. It's going in this direction. The sun is over here. Because of its attraction, it really wants to go straight. But it will turn a little bit and it will go in this direction. Again, at each point, it will have to turn because of being attracted. And this calculation has been done in this program. It is a fairly simple calculation. It might seem complicated, but it actually is not really that complicated. There is a chapter which discusses this. Okay, I think I have to give this as a redirection rather than, okay. So obviously, the red circle in the center is the sun. This is the earth, the orbit happens to be a slightly eccentric over here. But the calculation is reasonably simple, okay. So it's not, well, it's slightly more complicated than what you might write without any, without, with very little thought. It's a little bit more complicated, okay. But this thing that you have learned in physics, you can actually experiment it on your screen. So you can figure out whether what they teach you in physics actually does make sense or not, okay. Let me show you one more. Okay, so this is a simulation of an airport, okay. So aircraft will come in, they will land and then they will go along some taxis ways and they will halt at some terminals, okay. Of course, I don't have beautiful pictures of the airport and aircraft and things like that. Everything is very schematic and you have to use your imagination, okay. So please humor me, okay. So this is an aircraft which comes in and that is where, that is the terminal where it lands, okay. So it's going to wait there for a little while, okay. Now, this look like the two aircrafts collided, but that is not the case. I have made those aircraft sizes very large and therefore it appears that they collided. But the whole point of this simulation is to make sure that they do not collide, okay. As you can see, while that aircraft is passing on this runway, the previous aircraft wait. So there is, they have to keep some distance in between them. So things like this are in fact done routinely when people build airports or train stations or anything these days is built with simulations. So having a simulation exercise is very important. And I think this is, this is reasonably within the reach of your students' abilities. Not on day one, but maybe on day 100 they should be able to do this or day 150, okay. Certainly by day 200 they will do it with absolute comfort and it's okay for you to tell them on day one that look, this is what you cannot do today but this you will be able to do on day 200, okay. Because you have to set a good goal for them, okay. So I'm at the end more or less, I'll just finish up, okay. So we have to excite the imagination of students and then challenge them. I guess I should just put down two quotes because, okay. So this is a quote which I like, which says something like, if you want to build a ship, don't drum up people together to collect wood. And don't assign them tasks and work. But rather, teach them to long for the endless immensity of the sea, okay. So you tell them that you make them want to go on big voyages and the rest they will do themselves. There is another quote which I would like to share with you. This is by Bertrand Russell. It says, when you want to teach children to think, you begin by treating them seriously when they are little, giving them responsibilities, talking to them candidly, providing privacy and solitude for them and making them readers and thinkers of significant thoughts from the beginning. That is if you want to teach them to think, okay. So on that note, I will conclude my talk. What are the contents of CS 101? Is it C or C++? C++. This is my first question. Yeah. And second, I want to ask that can we get some lesson plan that till when, how many days we'll go with simple CPP and then we'll continue with IOS stream and all? Certainly. So in chapter five, six, I think, repeat statement is dropped because loops are taught. Now functions are explained in chapter nine, okay. So then functions are explained after a basic description of functions. You tell students that, okay, int main, main is a function. You really should be declaring as int main rather than as main program. Can you do the lesson plan? So yeah, so I'm planning to put together, okay. So I was going to stop over here, but yeah. So this last point, transparencies for the lectures will soon appear on McGraw-Hill homepage and also my homepage. So they will answer your questions, but very briefly, the moment you introduce functions, int main can be introduced and even namespaces can be introduced. And so at that point, namespaces, int main and IOS streams can be introduced. So from that point onwards, they can deal with orderly C++, except if they want to do any graphics. Thus, if we set up these much goals as airplane and all, these are long-term goals and we have to finish up simple CPP within two, three weeks, I think. Then when will they prepare airplanes? Okay, so even that code that I showed you, okay. That was about 250 lines of code. Will they go with those codes or they learn other things of CPP? So this is an application, okay. So first of all, everybody doesn't have to do that airport simulation. I think everybody should learn some simulation, not necessarily airport simulation. They can go with that also if they like. Right, so that's exactly the point. Few of them can go specialize in simulation. Most of the time, most courses have a project. So there are several chapters in which material is suggested for projects. Simulation is, there are two chapters on simulation where this material is suggested. There is a chapter on this gravitational simulation, which is a different kind of a simulation, where material of that kind is suggested. The ideas which are suggested in gravitational simulation will actually apply to things like circuit simulation also, okay. So these simulations will later be combined with other programs also. Then only they'll be helpful. Students will ask, what are the applications of this simulation? The applications of these simulations are, if you want to build an airport, you have to do this. That is it, okay. So it does not have applications in school, okay. But if you want to, I mean, look, people today can get information about lots of things. In fact, what I want students to think about is, if there is something being built, we are going to have elections in a few days, or you probably already had elections, and our students must be able to understand all these different things, and they should be able to apply their knowledge to all such problems. So therefore, I think I'm very keen that students acquire the tools to do all these things. Let me give some concluding remarks to your question, because similar thoughts are in the minds of people generally. You asked about, what is the lesson plan followed in IITB? What is the syllabus in IITB? I do not know whether you have read my paper on the blended MOOCs for Indian students, which I had circulated. A specific observation that I have made there is that two teachers teaching the same course in successive years may teach it completely differently. So please understand that is what was happening. When I taught the course before Professor Ranade, I did not use simple CPP at all. I tried to use some easy windows with some reference to graphics, not because of the graphics, but because of the points that he made, that letting people handle graphics makes them learn easier, but that was a separate. Professor Sridhar Ayer, who will be speaking to you soon, and who has been teaching this course after him, does not use simple CPP at all. So please understand that there is no standard way or standard lesson plan that can be stipulated. But since we are going to use this book as a guide for our course and even for EDX CS 101, next year, for example, when I will be teaching it with Professor Suprati, we will more or less follow this. So the material that will get prepared for the teacher's training will be based on this. But that is not necessarily the only way of doing it. And in fact, each one of you, each one of you should be able to evolve one's own teaching plan. Since not all of us could be accomplished programmers or accomplished teachers like Professor Ranade, we might take help. That is exactly what we do when we use a standard textbook. Somebody has done a lot of work and it is much easier for me to understand that plan and follow that plan. That is how most of our teaching happens. It is in that context that the book is used. But it is not like there is a standard lecture plan in IIT Bombay which is followed, etc., etc. Absolutely nothing of that. Sir, actually we people are used to having a standard syllabus and we need to follow it. Yes. We have to do it. That is because you have never questioned that rule in your life. Sir, we have questioned but are head of the department, I don't know. We also head heads of the departments. The point is if I have the conviction and if I have the courage of conviction, I can always deviate from that quote. The important point is my students should learn to program. As long as they do anyway, we are standing between T and our people. Thank you, sir. Thank you very much.