 Hello and welcome to the NPTEL course on an Introduction to Programming through C++. I am Professor Abhiram Raniday of IIT Bombay and today's lecture will be an introduction to the course and some material will also be covered. So here is what I am going to do today, I will begin with an introduction to computers and computing, then I will show some simple programs, I will make some remarks on programming and then I will close with the spirit of the course. Let me begin with the observation that computers are everywhere, cars, phones, laptops, game consoles, cameras, televisions, refrigerators, practically anything you name contains a computer. You might have used a computer to train and plane or bus tickets, you might have used a computer to search the internet, predict the weather, maybe play games, lots of things. The goal of this course is to learn how to make computers do things such as those that we have mentioned. So let me begin with the question, what is a computer? A computer is an electrical circuit, it is a giant electrical circuit but nevertheless it is a circuit which can do the following things. It can receive data from the external world and by data we typically mean numbers. Now it can receive images and sounds but as we will see these will be represented as numbers. A computer can perform calculations on the data that it receives and it can send the results back to the rest of the world. Now what kind of computations does a computer perform is determined by a program that has to be loaded in the computer. Well, what is a program? A program really is a precise description of the calculations we want the computer to perform. By feeding different programs to a computer you can make it do different calculations and this course tells you how to construct programs or how to write programs which is what the process is normally called. Programs are written in a special notation called a programming language. In this course we are going to learn the C++ programming language. This was designed by Bjarne Strauss-Struck in the 1980s and it evolved out of the then existing and still existing C programming language. C++ is a very powerful and somewhat complex language. We are not going to be studying all of it. We will study a subset of it which is still going to be much more convenient and in fact safer to use than C and we will lay the foundations of learning advanced features for later courses. In this course in the initial weeks the programming environment will be C++ augmented with Simple CPP where Simple CPP is a C++ library developed in IIT Bombay. Simple CPP provides facilities which are convenient for learners. For example it allows you to do graphics, it allows you to draw pictures, this is certainly going to be more fun and probably learners or beginners will appreciate it. Then it provides an easy to understand statement called the repeat statement and we will see that today itself. It will also provide a main program keyword which also we will see today. Simple CPP can be downloaded from this URL shown here www.cac.itb.ac.in slash tilde ranaide slash Simple CPP. It is available on Linux and Mac OS as a library or as an IDE for Windows and Linux. Later weeks of the course we will just use C++. We may not use the features of Simple CPP but on the other hand if you want to do graphics the features of Simple CPP will definitely come in handy. We are going to be using the following textbook. The title is An Introduction to Programming Through C++ written by me published by a Mac Royale education in 2014. Here is the webpage for the book www.cac.itb.ac.in slash tilde ranaide slash book.html. It is available in physical and online book stores and it is integrated with the use of Simple CPP. Today's lecture is based on chapter 1 of the book and you are recommended to read that chapter. This course does not have many prerequisites well you do need to know the science and math of standard 11th and 12th because we will be using examples from that science and math. No knowledge of computers is expected you will learn all of that in this course. In addition to lectures we will have instructions and maybe even videos talking about use of computers. And more than anything you need enthusiasm you should want to do things with computers you should want to have fun with computers that is really most important. So let us get on with the main business we are going to write some very simple C++ programs. These programs are going to draw pictures on the screen and they will use a so called turtle simulator which is contained in Simple CPP. The turtle simulator is based on logo which is a language invented for teaching programming to children by Seymour Papert and others in the late 1960s. It is pretty old but you will see it is a lot of fun and later on in the course you will realize that it is really an interesting and a useful set of tools. The point of logo programming and the turtle simulator is to drive a turtle on the screen. So you will see a small triangle typically on the screen and you are going to drive it and the way you are going to drive it is you are going to write a C++ program. The C++ program will tell the turtle what to do. Now the turtle has a pen so as it moves it will draw. So that is how you will be able to make interesting drawings. Now you might think are we learning this serious subject of programming or are we learning drawing pictures which seems to be too much fun. But you will soon see that if you master picture drawing you will actually be mastering programming. So here is the first program. So I have shown it over here I am going to explain it one statement at a time. So the first statement include simple CPP in those funny looking brackets simply says simply it has the computer look I am going to use the simple CPP facilities then the main underscore program is a keyword which says that look what follows is the main program. So starting from the open brace all the way till the closed brace at the bottom of the page. Then the turtle sim command starts the turtle simulator what this does is that it is going to create a window it will have the turtle at the center facing right. Then you see the command forward 100 well in general this command is forward n where n can be any number. So in this case the turtle is being commanded to move n pixels in the direction in which it is currently facing. Right D where D is expected to be the angle in degrees tells the turtle to turn right. You can have a similar left command as well and weight tells the turtle to do nothing for T seconds. So these T seconds or in this case 5 seconds are what you are given to admire the drawing that the turtle has drawn. Now let us see what drawing the turtle will actually do by looking at the program. So this will start the turtle simulator and it will create a window then the turtle move forward by 100. So the turtle moves forward 100 so if the turtle is over here and facing in this direction it will move forward by 100 steps then it will turn right 90 degrees so then it will start facing in this direction. It will then move forward 100 pixels it will again turn right 90 then again move forward 100 steps then again turn right 90 and then again move forward 100 steps. So what has the turtle drawn as a result of this? It has drawn a square of side length 100 pixels and after that the turtle is going to weight and then the whole window will vanish and the program will come to a halt. So this is what the program is supposed to have done and let us see now how do we run this program. So for that purpose we need to install simple CPP on your computer. How do you do this? Well you have to see the instructions at this webpage. Then you have to type in the program into a file or the IDE whatever you have downloaded and let us say you call it square dot CPP then you have to compile it. So compilation can happen by typing s++ square dot CPP if you installed a library on Unix. If you installed the code blocks IDE then you simply have to press the compile button then you have to execute it. So on Unix you have to type dot slash a dot out which is the result of that compilation process. So we will explain to you what compilation means in a little bit but the result of the compilation process is a file called a dot out and you just have to execute it. On code blocks you just need to use the run button. So now I am going to show you exactly how this happens and I am going to use the simple CPP library and I will compile the program for you. So here is the program that I showed you earlier. This program is slightly different. So you had seen that there was a wait 5 seconds at the end of the program but here I have also put in these additional weights. So these weights 0.5, 0.5 are going to tell the turtle to wait for about half a second after each forward and right step. If I do not do that then a computer works very fast. So the turtle will move very fast and before you see it everything will be drawn and you will not really be able to see the movement in any nice way. So therefore we have put in these weights, these additional weights. So this has been typed into an editor and it is now in a file called square dot CPP. The name of the file is appearing over here as far as the editor is concerned. But you might have it in your IDE. So let me now try to compile that file. So for this I am going to say s++ square dot CPP. So this will compile the file and now I am going to execute it. So as you can see the red triangle appeared, it drew a square and now it is gone. So this is what that program did and this is what you can do. You can change the program, you can draw other things as well as we will see soon. So you just saw that program execute. Now I will suggest that you become familiar with that program and maybe you change that program a little bit. Do not make any major changes but see if you can change it so that it draws maybe a square which is 50 pixels on the side. Basically you just have to change that 100 to 50. But do it so that you get confidence of running something on a computer. Likewise a slightly bigger change is to make it draw an equilateral triangle. For an equilateral triangle you will just have to draw three lines instead of four and further more the angles will have to be different. For this purpose remember that the external angles of a polygon add up to 360 degrees and if the polygon is a triangle then there are only three angles and all of those exterior angles are equal. So therefore each angle must be 120 and that should be the turning angle. So what have we discussed so far? We have discussed general information about the course, we have talked about how to install simple CVP and we have talked about a program to draw a square. So we will take a break and resume in a bit.