 So, we begin 15 minutes late, fortunately this slot is one and half hours, usually I will use this for one hour of lecture and half an hour of quiz or any other interaction, but today I am going to use the entire one hour 15 minutes for the first lecture. What I am going to discuss primarily is the set of programmable machines or the concept known as programming any artifact. We will specifically discuss how computers are programmable machines and to understand how computer programs work, we will try to form a conceptual model for which we will use an equivalent of a computer whom I prefer to call Mr. Dumbo. We shall see how exactly Mr. Dumbo works and how do we write programs for Mr. Dumbo. At the end we will see a couple of sample programs written in a programming language called C plus plus, which is the programming language that we are going to use. Right now the notion of programming language the words like C plus plus etcetera may not mean much to most of you which is ok as we go ahead we will discuss. So, just before you came in I was mentioning that we are going to discuss programmable machines and we are going to form a conceptual model of computers in our mind using an artificial character called Mr. Dumbo. But first we talk of machines all of you are familiar with machines when was the first machine invented what was the first machine sorry knife actually knife came much later in human life the x came first knife is what you use in modern times to kill each other from short distance x is useful for long distance travelers and besides you can't kill lion or deer or such things with a knife you need a bigger device. But still how long ago was that yeah yes around 10,000 B.C. So the movie has its effect is it. Ok bye. How long have we been there our species human species 10,000 years I mean I grant that biological evolution is a great thing but 10,000 years things do not evolve genetically that fast any idea how long human species have been around. Well the carbon dating shows that we are about 5 million years old yeah 50 lakh years roughly why I point this out is that for a long duration while humans always proved to be more intelligent than other animal species it did take them a long time to device mechanisms which could make their lives first safer and later more comfortable. When was the wheel invented you will agree that wheel and the associated gadgets which came along with the wheel like chariots, bullock carts etc proved to be a great help for movement of humans or gods. What is the recorded history of human life written history how old is that apart from seeing movies like 10,000 B.C. people do not seem to be strong on history ok. The recorded human history is about 5,000 years old. Now come to machines which transform external energy somewhere see machines like liver, pulley, wheels ok they do help but they essentially help in enhancing the human energy for whatever purpose you want but to use external energy today use solar cells and whatever. The first external energy used essentially was attempting to convert hot steam into motion. When was steam engine invented any idea 1850 1851 are you suggesting that Mangalpande or his colleagues invented it here that did not happen actually the earliest history of trying to work with steam goes back to the times of Greeks but it was not very effective till the steam engine in the present form incidentally it took a long time over about 70 years of different development but 1718th century actually was the time when the steam engine got. The internal combustion engine came out in the 19th century 1800 century. The point I am making is that we took 50 lakh years to evolve to a level where we could start controlling our environment ourselves. Only in the last 5,000 years we have established ourselves into different societies who work intelligently and together to make life better. Only in about last 400 years or so we have developed machines which significantly enhance our capability to live comfortably by converting external energy into either kinetic energy or whatever. Electronics as we know it today started evolving only in the 20th century. Computer is also a machine. The digital computer came into being only in late 1940s. So the history of computers as we know them today is just about 60 years old. The point that I am trying to make is that what has happened in the last 60 years in terms of significant developments had not happened in all of 50 lakh years, in all of 400 years preceding those 60 years and that is because even the other machines as we know them the gadgets as we use them, they themselves have been significantly enhanced because of this tiny thing called computer. And the difference between a computer and most other machines is that it is a programmable machine. Internet and web is what you are familiar with. You have all done railway reservations sometime or the other. You are familiar with railway reservation systems. Large number of computers with Indian railways, with banks, with other payment gateways and a machine in front of you connected to internet all help that. You would think that is a very complex system. So are systems which run banking and financial services. So are systems which run oil exploration. But these are nothing with respect to the computers which run huge amount of information processing tasks. You have heard of genome sequencing? That is a very complex computational task. Usually higher end computers which were deployed for such purposes were known as super computers. But today you have what is known as a cluster computing that means you have large number of computers. It is not uncommon to have 10,000 computers working together on a particular problem. Some of the more well-known cases is Google and Facebook. All of you have heard of them? Why? So how do you think Google runs? You see only the end result. But millions of people are harping on to Google making searches and so on. It is another exciting set of technology. But that is at the higher end. One other example of the higher end usage is analyzing astronomical data which comes through radio telescopes. That data simply cannot be handled by human beings, not possible. But at the lower end the computers have found their way because of the smaller and smaller and smaller size and cheaper and cheaper cheaper price. They have found their way into every other machine that we know of. Refrigerators, washing machines. These were plain simple Dumbo devices at one time. Today they are all very intelligent. A washing machine you can press one button and you can sort of program that machine. So once you put your clothes in first, let the water in, then hit the water for 10 minutes, then rotate it right hand side, then push some soap, then rotate it left hand side. All of this. Why? Because they are computers inside controlling the behavior of the washing machine. Any modern car has anywhere between 10 to 20 computers. All of us typically have a computer, at least one computer with us if we are wearing a digital watch. Every digital watch has a computer inside. If you have cell phones, the computer chip inside the cell phone is more powerful than the high end PC that was available 10 years ago. So that is the progress that is being made. Surely the progress is primarily in the field of electronics. But if that is the body of the computers, the brain of the computer comes out of the programming activity that we perform. So let us understand what programming is. This is the first observation. All machines do certain defined tasks and no machine does a task on its own. It requires to be instructed. So these react to given instructions. Take one of the most familiar machines, bicycle. Everybody is familiar with bicycle. It is a machine. So when you pedal, when you press the pedal, you are actually instructing the machine to move forward. When you move the handle left or right, you are instructing the machine to turn left or right. Of course, the balancing act you have to do yourself. But the machine reacts instantly to your instruction. You go to your hostel room in the evening and press a switch. The light bulb lights on. You switch it off, the light bulb goes off. So that machine is reacting to an instruction that you are given. Most of the machines work like this. And that is the reason why if you want to continuously use a machine, you have to be continuously present interacting with that machine giving instructions. Consider everybody has used calculators. No, not necessarily. I do not know. At least at our times, we had to use lock tables to do calculations. Everybody is familiar with lock tables? That is what you used also. So where did you become familiar with calculators? Individually. Anybody who has never used a calculator? Nobody. Wonderful. So here is an example. How do you use a calculator? Suppose I want to add two numbers, say 23 and 150 here. So what I will do? Of course, switch off the calculator and I will start entering the first number. So I will press 2, then press 3. After that, I will press a plus sign. Typically, when I press the plus sign, that number 23 may disappear from the screen. At least when I start entering the second number with the keys 156, you will see 156 there. And then you press an equal to symbol. So when you press an equal to symbol, what are you doing? Actually, you are instructing the calculator to find out the sum of the number which you have just entered and the number which you had entered earlier. And the sum is displayed as 179. How nice it would be if you could tell the calculator that, look, I want to add two numbers. I will give those two numbers to you one after another. Add them and show me the result. And somehow, you could make the calculator understand this set of three or four instructions and then started entering numbers without entering a plus symbol or equal to symbol or anything like that. You would call it a programmable calculator. Indeed, such calculators exist. What we are talking about is a unique machine which does not respond to an instruction as it is given but requires you to write all possible instructions one after another separately and give the entire set of instructions to that machine. That machine is called computer. So, a digital computer requires pre-written instructions. This is the first fundamental observation. Such a pre-written instruction set is called a program. So, you would have come across various equivalent of programs in your earlier life. Have you ever seen a list of instructions? So, take a recipe, cooking recipe. Anybody familiar with cooking recipes? Take whatever 500 grams of flour and then cut it into pieces, then cut some mirchi, cut something, whatever. I am not very good at it, so don't try to make any dish out of this. But essentially, the one, two, three, four, five, six, seven, eight instructions and when you follow them, so look at what someone has done. Someone has written a program to prepare some dish. That program is given to us. We are acting like a Dumbo computer and we are executing those instructions one, two, three, four, five, six and at the end we get a dish. Computer behaves much in the same fashion. So, this is something that we have to understand that a computer somehow is able to read the entire program and understand it. And after reading and understanding that program, it will set up the necessary environment for later on executing that program. Look at what will you do when you are looking at the recipe of any dish. So, for example, the recipe will first say you will require these ingredients. Now, if you are, if you are trying to make some nice pulao and the recipe says take 500 grams of rice, you are not going to go to market to purchase rice at that time. So, you will actually collect all the ingredients, keep them ready and you will keep them ready because you first read the entire recipe top to bottom and understood what context was required to execute that recipe. That process when applied to the computer programs means the following. When you write a program or set of instructions to do something, the computer must somehow read that entire program, understand it in its own native words. So, for example, you give me a recipe in English and if I have studied only Hindi, I will need to translate those English instructions into Hindi. Either I will do it myself, if I knew that language reasonably well or I will take somebody's help. This process of translation, compiling all the instructions and preparing the context for later on executing those instructions is the first phase that a computer does with a program. That process is called compilational translation. It is only after this is done, then the second phase starts where the program is executed and when your program is executed, it is at that time the specified computations are carried out, the results are given to you. So, this is the fundamental property of computing that we saw that there is a program, pre-written program is the computer will understand, but after all the computer program will contain some instructions, hopefully for doing some computations and therefore the computer must have some basic capabilities much like the calculator has, which we just looked at. So, what are the capabilities that a computer must have in terms of computational capabilities? So, here is a list, ability to handle numerical values. You all agree that it should be able to handle numerical values? The first line shows how you typically write numerical values. So, 257 minus 78, 4.675, familiar way of writing numbers? Fine, that is how you write numbers, but large and small values are written differently. So, how many of you are familiar with this notation? 1.4E18 or 0.356E minus 9. Have you come across this? Yeah, so this is called an exponential notation. If you want to write a very large number, how would you do that? Suppose you have to write a number, which is 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, lot of zeros. So, there is a short form to write it and what you do is you write a fractional part which is called mantissa and you simply write the power of 10 by which it should be multiplied. So, let us look at this number for example. So, this number is actually 1, 4, 0, 0, 0, 0, 0, 0, I will say dot, dot, dot. How many zeros can someone comment? Well, it is 1.4 into 10 to the power 18. So, there will be 17 zeros after 40. Now, this number is very unwieldy to write and therefore, you write it in this form. So, this form merely means 1.4 multiplied by 10 to the power 18. In exactly the same way, take another number, this one. This number is actually 0.000, everybody can say how many? It is a very small number and very unwieldy to write. You cannot write it very easily. So, most scientific and engineering calculations will always represent such numbers in a smaller form and that smaller form is called this exponential notation where you write this as 0.356 multiplied by 10 to the power minus 9. We agree that these are equivalent numbers, but this notation is small, but this notation requires actually two distinct values to be stored somewhere. One value which is the fraction, this is called mantisa. You just call it reprinted by number m, later m, mantisa and the other value which is the power of 10 is called the exponent. In fact, there is a third implied element and that is the number 10. This is called the base. There is no reason or rhyme to use number 10 except the fact that all of us are familiar with decimal system. We write numbers in decimal system and therefore, we take base 10 to represent this logic, but you realize that the base could be anything. In fact, if you do not have 10 distinct digits from 0 to 9, you would not get a decimal system. If you are, let us say, only 8 distinct symbols, consider 0, 1, 2, 3, 4, 5, 6, 7, then you will get a system which is called an octal system and the base would be 8. Later on, we shall see that the computers typically deploy a binary system because it has only two symbols, 0 and 1. So, the base is always 2, but that is a separate matter. We will discuss this later. So, as far as we are concerned today, we are comfortable with decimal numbers which are the fractions which are shown here. We are also comfortable by writing large and small numbers like this. Just one question on the side. If I want to add these two numbers, what will be the result? The number 1.4 into 10 to the power 18 added to 0.356 into 10 to the power minus 9. Sorry, anyone? I cannot hear the noise. Can anyone say what would be the result? My God! 1.4 10 to the power 18. Are you sure? You know, he is right. The actual mathematical value of adding these two numbers, if I have to write it, it will be like 1, 4, 0, 0, 0. How many of them, my friend? 18 or 17, whatever, followed by dot, followed by 9 zeros, followed by 356. But the answer given earlier is also not incorrect from a practical point of view. So, what is the difference? The difference is that while this is the correct mathematical answer to the problem of sum, adding this to this, in most engineering and scientific computations, where approximations run rampant, where any physical quantity cannot even be measured to this level of accuracy. We generally say a close approximation is good enough. And therefore, we say that any number which is beyond 6 or 7 digits of precision is not worth it, because that precision is not measurable anyway. Consider this. You are making a machine. You have decided the diameter of the wheel for a car or a cycle, bicycle, should be so much. Now, it has to be manufactured by somebody. Some mechanic is going to make it to what accuracy that diameter can be accurate. So, let us say the diameter is expected to be 2 feet, 24 inches, 30 inches, whatever. Can anybody manufacture that wheel with 30 inches plus minus 0.00000001 inch? Not possible. Different wheels will differ in diameter by a fraction more than that. And that is why to calculate or to represent values to that level of precision does not make sense in the practical way. Mathematically, however, that is the correct answer. In most of our calculations, which we do for the purposes of scientific and engineering calculations, we do not require this precision. And that is exactly what is embodied not only in computers, but even in calculators, even in lock tables. When you use lock tables, what is the accuracy that you will get of multiplication? You do not do addition using lock tables, but you have to multiply something like this will happen. Anyway, so the point being made here is that the precision of the numbers that will eventually get represented on computers will be limited. That's all. Let's go further. The computer must also have ability to carry out numerical operations. So it must say add, subtract, multiply or most calculators will use a common multiplication sign which is small x. When in some cases you will have star, we shall use star because computers use star symbol to represent multiplication. Division is our slash. I have put dot dot dot here to indicate that there are many more operations which the computer is capable of and we shall see those as we proceed. So this is the basic ability of the machine. Represent numerical values and perform arithmetic operations on those numerical values. Additionally, it must be able to collect numerical values from us and give us back the results if it is a programmable machine. After all, I am not going to write a program to add two specific numbers. I would like that program to be used by me to add some two numbers used by somebody else to add two other numbers, but somebody else to add still two other numbers. So what it means is that every time the program is executed, the computer must be capable of collecting the required numbers from you and therefore it must have an ability to collect those numbers in the first. So it must be capable of performing what is known as input operation. And of course when it does computation, it must be able to give us out the result value. Just like a calculator displays the result value on the screen, somehow the computer should be capable of conducting an output operation giving us value back. So input and output capabilities are fundamental to any computer. So again, representation of numerical values to a limited precision may be ability to do computations like add, subtract, multiply, divide and something else, ability to collect numbers from us, ability to give us back numbers. And of course imply the ability to store these numbers somewhere. When I read numbers from you, I can't forget them. I have to keep them because I have to later on add them, maybe multiply it something else, do whatever. So the ability to store these numbers is equally important. It is the storage capability which is rather unique to computers. The ability to store some values. So we consider that a computer has some kind of memory, certainly not like human memory, far different from it, but it's a memory which consists of some locations just like warehouses. So in every house, certain number of family members can stay. Okay, so that's people's house. So people are stored there sort of. So here a house will store a number and consider a colony of houses. Each house is a number, one, two, three, four, five, six. Each house can store some people. Here a memory location can store some value. Obviously when you store any value in a location, you should be able to get it out when you are doing some computations. Suppose I am a computer. Now I might have multiple locations. So from which location I should take a value and what should I do with it? You will not specify a location number. You will typically use symbolic names for these locations. So I should be able to attach a symbolic name to my location and refer to that value. In short, three simple things that a computer must have. A, ability to represent number, B, ability to manipulate those numbers. The second, input-output capabilities to collect numbers from you and give you back the number. And the third capability to store these numbers temple. Here is a sample program in English language. We presume that computer understands English for the time being. Let's read these instructions. Number one, get a number from me and store it in a location. Call this location A. I am saying that when you take a number from me, put it in a location, call it A because whenever I later on refer to A, I will mean this location. The second instruction says get another number from me because I am writing a program to add two numbers. Get second number and put it in another location. Call it B. Oh, sorry. I am not adding numbers. What is it doing? I say multiply the numbers in location A and B. Very good. So, it's a it's a program to do multiplication. Please note that while these instructions are written, there is no indication as to what this program is going to do. Only when I am reading the instructions, I am realizing what this program is supposed to do. The third instruction says multiply the two numbers. Now, this time it mentions the two locations A and B. So, A and B already have a value because of execution of the previous instruction. Store the resulting value in yet another location. Call it P and last instruction says give me the value stored in location. So, as I told you, imagine we are a computer and we are executing this program. It is written in plain English so we can understand it. Remember two steps. First step is compile this program, translate this program. There is no translation required but understand this program. The understanding phase is an important phase here. So, let us look at what happens during the understanding phase. The compilation process, I have written the same instructions. You may not be able to read them clearly, but you know exactly what they are, right? This time I will read every instruction, but I am not executing it. I am just reading the instruction understanding. What do I understand from first instruction? Well, I have to whenever I execute this instruction later, I will have to get a number from outside and put it somewhere. That somewhere is going to be called location A. So, should I not create some kind of a storage system? Let us say I need a location here which will contain some value and I will call it A. It is only when I read this instruction I understand that I will need a location. I read the second instruction. It says, get another number, store it in a location for B. So, what should I do at this stage? Create another box sort of and call it B. Third instruction says, multiply the numbers in locations A and B. Well, I already have locations A and B, but the result has to be kept in a third location called P. So, I will create another location P. The fourth instruction says, give me the value stored in location P. I already have location P. So, I will be able to give whatever value exists inside. So, please note that this compilation process has resulted in collecting the ingredients for my recipe ready for cooking. I have got rice, I have got namak, mirchi, whatever, whatever, so I have got these locations here. It is only after I do that I will say I am ready to execute your program. Now, when you ask me to execute the program, so here during the execution process, I am ready with the three locations A, B and P. And now I will execute each instruction in the given order. So, first instruction, get a number from me and store it in a location. This time, obviously, I will have to supply a number. So, let us say I supply 25. When I supply the number 25, what the machine will do? It will take it and keep it here. Then it will go to the next instruction. It will say again, give me a number. This time, let us say I give it a number 2. The second number will go where? In the location B. The third instruction will be executed, which says multiply the numbers in A and B. What will be the result? 50. And where is it to be kept? In location P, so I will keep it here. And the fourth instruction says, give me the value stored in P. So, this 50 will go out as there is it. Extremely simple, rather dumb way of doing things, but it is important to understand the steps by which the machine executes this program. Most of the programs that we will write in the initial days at least, I will ask you to hand execute your programs or algorithm, so that you know exactly what is happening inside. Here is an example. I have written a text test program. It is not a computational program, but there are instructions in English, which all of you can understand. I would like you to execute those instructions, execute that program, compile and execute that program, but try to be, let's say how quick you can be. Computer is very fast, whether you can be fast and you can be as correct as the computer. That's the challenge. You need not take down the instruction, they will be shown here. You just have to compile and execute that program. Let's say who is the fastest. So you made two mistakes, most of you. One, you forgot to compile. If you had compiled, you would have read all instructions before doing anything and if you had read all instructions, the last one says while executing this program, ignore all earlier instructions and raise both hands. However, most of you raise both hands, so it was a wrong execution because you had not ignored earlier instructions. So you did not execute the last instruction correctly. In fact, if by mistake you have executed all earlier instructions, then what is the semantic or meaning of the last instruction? Can somebody say? The last instruction says ignore all other instructions and raise both hands. But I have not ignored all other instructions. Should I raise hands? Well, does it say that don't raise hands? This is ambiguity. This is ambiguity and this ambiguity is the beauty of all natural languages. In English, Hindi, Telugu, Tamil, Portuguese, Spanish, anywhere, I can construct sentences, which may mean something to you and something else to you. Computers, unfortunately, can not afford the luxury of such ambiguity. So, computer programming languages are written to be very precise, are written to have a very clear meaning and are, of course, written to have strict rules of grammar and punctuation. We have rules of grammar and punctuation in English also, but the semantics or meaning is not very clear. So, two words I would like you to remember. One is called syntax and the other is called semantics. Syntax is about the rules of grammar and punctuation and semantics is about meaning. And any programming language that you use for programming a machine like a computer must have very clearly defined rules for syntax and semantics. So, I will get back to the computers. Suppose we rewrite our earlier program to add two numbers instead of multiplying two numbers. You will agree that this program will do the job. Get a value, put it in A, get another value, put it in B. Add the two numbers, put it in another location called C and finally give me the results for C. This looks like a good program for a computer to execute because we had done something similar with a calculator earlier whether you are multiplying or adding does not matter. To understand the intrinsic facilities that a machine has, I have created a caricature called Mr. Bouddhura. Bouddhura is a Hindi word to represent a very simpleton person. Not very brainy, certainly not noble or yet capability, but the obedient person can execute the defined task very well. You cannot think on his own. That's Mr. Bouddhura. Mr. Dumbo is an English word which has a similar meaning. So, I use that number. We want to form a conceptual model of what happens when numbers are brought in from outside, given out, memory locations, etc., etc. So, we will look at this. This is our Mr. Dumbo. That the first picture actually I tried to draw, but my colleagues did not like it. They don't think that it represents a computer. So, the second one was produced by professional animators. They said this is better. So, we have decided to use the second one. It has a screen-like face. So, you can sort of relate it to a computer. So, Dumbo cannot do anything on its own. It requires instructions to be given, very much like a computer, but it can execute given instructions correctly, again very much like a computer. Can do arithmetic, can do logical comparisons, can even do string manipulation. What is a string manipulation? A string is a collection of symbols typically put in double quote marks like your name is a string. So, for example, a computer would be capable of Mr. Dumbo and the actual computer would be capable of taking a name and breaking it into pieces. First name, last name, finding out whether a character p exists somewhere or character q exists somewhere or not etcetera. Those capabilities we shall see at a later stage in the course. But essentially it can manipulate values, produce results and give us the results. And of course it can compute. So, it's a computer. So, Mr. Dumbo is our computer. Unfortunately, like a real computer, Dumbo cannot remember anything in his head. So, he requires memory. He uses a cupboard. It's actually a chest of drawers. You all seen drawers. You would have drawers in your home somewhere. So, in different drawers you keep different things. Of course, drawers in human households contain variety of things. The same drawer can contain my purse, my watch, my pen, whatever. Here, Dumbo's drawers are special. Each drawer can contain one value. So, let's look at Dumbo's drawers because they represent exactly how a computer's memory behaves. Each drawer will contain some value. Here are some samples shown. It could be a number 437. So, for example, location B which is a tag on this drawer contains 437. Location F contains a name. How can a location contain a name? Can the name be very large? For that time being, we will ignore the capability of Dumbo's memory to contain names and strings. We'll concentrate on numerical value. Later on when we relate to actual computers, we will be able to understand how these character strings are represented. Now, this is something I would like you to appreciate, much like you appreciated the compilation process being a separate process and then an execution process. These are the peculiarities of computer's memory. A Dumbo can store one value in a drawer, not two values, not three, not five. Any drawer can contain only one value. How does a value get into a drawer? Obviously, unless Dumbo puts a value inside a drawer, nothing can come there. Dumbo can put a value inside the drawer in response to any one of the two possible instructions. The first instruction is of the input type. When we give a value, that is the time a Dumbo can put a value. The second instruction computes something and put the result value in a location. And whenever Dumbo puts a value inside a drawer, since a drawer can contain only one value at a time, if the drawer had any value earlier, that will be destroyed. So, please remember this operation of either in putting a value into a location or computing something and putting that value in a location will necessarily overwrite and destroy any earlier value that existed there. From now onwards, only this new value will be there in that location. The old value is gone permanently lost. Some values may already exist in those locations, in every location in time. Why? I am asking Dumbo to compile and execute one program today, but yesterday somebody else might have asked Dumbo to execute a program. Therefore, yesterday somebody else might have. It so happens that Dumbo's drawers are never cleaned automatically. In fact, in the case of actual computers memory, whichever memory locations you decide that you will use, you will find that location always contains something. Digital memory has no choice because remember digital numbers, binary numbers are made out of only two symbols 0 and 1 and every memory cell will either have to be a 0 or has to be 1. So, by definition every location will always contain something. This is the equivalent. We presume that Dumbo's memory will always contain something, but that those contents will be overwritten either because of an input operation or because of a computational law. Only thing is if we do not know what a value in a drawer is, we are reprinted by some question mark in our handwritten explanations. Okay, sir, we don't know what that value is. For exchanging values, Dumbo uses a cart, the familiar cart, wheel cart, first machine, right? So, uses this, takes it from us a value into the machine or takes a value from the machine and gives it to us. Since Dumbo does anything only if instructed, Dumbo requires a program to be written. So, we require a programming language. So, we define a programming language for Dumbo. We have to define only simple instructions, input, output, computations. That's it, right? So, let us say that an instruction of the form input B will mean that Dumbo should get a value and put it in location B. Input X will mean put it in X. Input abrakadabrakad means abrakadabrakad is the name of a location in which some value is to be put. Similarly, we can say that whenever input happens and the instruction is executed, the new value which the Dumbo gets in the car will replace any old value earlier. We produce a similar definition for an output instruction. This is easy to understand. Input X means get a value, put it in X. Output Y means whatever is in the location Y, give it back. Please note the difference between output and input operation. An output operation, Dumbo does not literally remove that value from the drawer. He actually copies it, puts it in the car, copy and gives it to you. So output operation is non-destructive. The memory location continues to contain whatever it was containing. Input operation is destructive. Now calculations. How do we make Dumbo compute? So we define some instructions for it. Let's assume that there are two drawers containing numbers 35 and 12. I have shown the drawer B open. Drawer A is closed, but we can sort of peep into it. So I have shown the number 35 as the value inside that drawer. So these are the two values in A and B. And if you recall the instructions that we had in mind, we want to add these two numbers to get a result which we want to put in C. Notice that drawer C is shown to contain a question mark. Means what? It contains some value, but we don't know what that value is. We don't care. We instruct Mr. Dumbo by saying C is equal to A plus B. So what does C equal to A plus B mean? I have written an explanatory here on the right hand side because you are all familiar with algebraic equations. You would write for example D plus B equal to X plus Y. This means that these symbols must have values such that D and P together must be equal to X and Y. That is an equation. What is being written here is not an equation. It is actually technically called an assignment operation. But it is an instruction to Mr. Dumbo equivalent to what we had written in English. Namely, add the numbers in locations A and B and put the resultant value in the location C. So this instruction which appears like an equation actually has two distinct parts. One is the right hand side which is an expression to be evaluated. When you evaluate the expression you must get one value as a result. And then the left hand side nominates a location in which that value has to be kept. So left hand side is the destination of the final result and right hand side is the expression which has to be evaluated. The equal to symbol in this particular case is called assignment operator. It is not equal to symbol. The symbol is equal to the other. It does not mean equal to. It means assign the right hand side value to the left hand side location. So how will Dumbo do this? Remember, the memory locations are in the drawers. So Dumbo uses something like a workbench like this desk like you have the desk. So it has some loose papers like you have. These are called registers. So what Dumbo does is it goes to the designated memory location. Whenever it has to execute C equal to A plus B it will access the location A copy the value 35 write it down on the notebook here. Then next copy the value 12 write it another piece of paper. Then it will add these two numbers get the result 47. And finally it will put the value 47 into the designated location. So this is an elaborate process. There is a component called arithmetic and logic unit inside the actual computer. We will know more about it later. That is the one which does these computations for the time being we will imagine that Dumbo has a sort of workbench in which Dumbo computes these things. Please note that A and B continue to hold the existing values. Nothing has changed but the location C. So you can see that the result value into a location called C. Here is again the repetition that Dumbo is a computer. So Dumbo is not like a calculator. And therefore we have peace to write a program in advance. Give that program to Dumbo. Dumbo will compile and will execute that program. Where does Dumbo keep the program? I said Dumbo has a stored program capability. You know I have written a program and I have given it to Dumbo. Given it means what? Remember, Dumbo can't remember anything. Now if it has to execute a program first it has to compile and then it has to execute. For all of it, it will need all the instructions available to Mr. Dumbo, not with me. Where will it keep the instruction? It so happens that Dumbo uses the same memory to store the program also. And that is why Dumbo or the computer is called a stored program machine. It is not just a programmable machine but it can store the program within it and then automatically execute the instruction. Internally, Dumbo logically divides the storage space. So some drawers are used for storing your values as designated in your program. Some other drawers are designated as an internal program space by Dumbo. That is where Dumbo keeps the program. Remember, Dumbo is capable of storing names like Rana Dayanath. So English-like language instructions also somehow it should be able to store. We are not going to the details of how it stores those instructions, how we handle those instructions. That is a matter of discussion for later part of the course. But the machine is capable of storing these instructions. I'll just quickly show a couple of animations. You'll find them useful. This is our Dumbo. They are the memory cupboards. Please note this A, B, C, D, E, F, G, H are only artificially written. Drawers don't come with predefined names. Names are the ones which we use in our program and Dumbo associates with them. This is an input operation in progress. Dumbo has got something from his card. He's putting it in some location. So maybe he's executing an instruction called input C and he's going away with it. So this is how this is how we Dumbo will arrange his memory and execute an input program. Let's look at the way Dumbo adds numbers. So he's executing an input A operation. Now an input B operation. And now it has to calculate C is equal to A plus B. Currently C has a question mark. We don't know what is there. So Dumbo makes a copy of 35, takes it out on his workbench in a register. Then he goes to drawer B, makes a copy of 12, puts it in another register there. Now he has to do the calculations. So it will perform 12 plus 35. We'll get a result 47 and we'll religiously take that value 47 and keep it in drawer C. Notice that the question mark has disappeared now because now we know what is the value. Might appear simple, but believe me that is how simple it is. Except that it is exactly like this and nothing else. So an input operation or a computational operation will destroy any existing value in the memory. New value will come in. And there is no other way value can get into a memory drop. And computations always cause more time than just input, output operations or assignment operations. We'll now quickly write a full-fledged program for Dumbo. But we will write it using the programming language that we have been defined. We have defined so far. What was it? Input A is one instruction. C is equal to A plus B is another type of instruction. Output C is third type of instruction. Of course, these three instructions don't make up a program. I'll have to input B also because there is another number. There is a problem when I have input A, input B, input X, input Y. Consider you have written a program which has 400 instruction and you are reading 20 different input values at different points in time. Now, Dumbo will create those 20 locations which are designated and religiously, whenever you say input X or input Y, it will come with a card to you asking you for a value. But will you find it easy to remember which value is to be given next? Supposing you forget which value is to be given when? So instead of giving the value for X, you give the value for P. That should not happen. So you should have some indication in what value is to be given at this stage. And for that purpose, we empower Dumbo with a modified version of output instruction where Dumbo can give us a message as an output rather than a value. And that instruction is shown here. It says output, give value of X. Whenever I write something in double quote, obviously it does not mean a location. So we'll presume what Dumbo will do is Dumbo will take the card. In that card, it will write this message. Give value for X and it will come to us. So when it gives me the output, give value for X, I know I have to give the value for X. This way, before every input operation or every input instruction in my program, if I include an output instruction giving me a message, then that will make my life easier. So we introduce this messaging mechanism for Mr. Dumbo. How many locations Dumbo has to use? You remember we said Dumbo can go through all instructions during compilation phase and know which are the locations which are required. But we can make the task easier. By telling Dumbo in advance that look, I am going to require locations A, B, P or A, B, C or whatever. So we introduce one more instruction which is not a computational instruction or input output instruction. It is a specification instruction. That instruction says integer location A. Please remember during execution, Dumbo will not execute anything because there is nothing to be done here. But during compilation, Dumbo will look at this and say, this fellow requires a location called A. So it will create that location. And if we have multiple locations, as will be the case in most of our programs, we will write an instruction like this. Integer locations A, B, C or A, B, C, X, Y, whatever. So as many locations it will create. Why are we using the word integer to signify that I have proposed to put integer numbers inside this loop? Later on we shall see variations and other things. Now my program is ready to be written. But there is one problem. If I have a 400, 500 line program, see programs are written by me to be executed on Mr. Dumbo is alright. But the same program can be used by anybody else. You are all familiar with matrix inversion, matrices in general. So matrix multiplication, matrix inversion. Suppose I have written a program to do multiplication of two matrices or to calculate inverse of a matrix. Now that will be a fairly long program. Now a friend of mine says that if I have written this program, so give it to me. I want to make some modifications because my matrices are a peculiar kind, but I will modify your program. So he takes my program. Now it is not a simple three instruction, four instruction program. It is a 500 instruction program. It is quite possible that my friend will not be able to understand exactly why I have written what instruction where. So he will ask me for explanation which I will explain verbally. Typically people prepare large write-ups explaining what that program does and how it does. But a still better way is to write such explanations as part of the program itself. Obviously anything that I write in the program becomes an instruction to Mr. Dumbo. So I should have a mechanism to say that look this is not a instruction for you. This is actually a comment which I am writing for the benefit of my friends or for my own benefit rate. So ignore this completely. Such comments can also be written in Dumbo's programs. So we introduce two mechanisms of writing comments. If we are writing a comment in one line, then we will write two slashes at the beginning of the line. Slash slash followed by something, anything. Dumbo will understand this slash slash is not an instruction for me. It is meant for some stupid human beings. I will ignore. If I want to write larger comment containing several lines of explanations, then I can use another mechanism where I will embed that comment into two symbols. Slash star and star slash. Why this peculiar thing? Why not three slashes and only two? Why not only one slash? Well, it's just I am designing the programming language, so I am designing it like that. Later on when you study C++ or for that matter any programming language, you will find that the grammatical rules and syntax rules are defined by those who decide that language. And we all have to follow. So is this easy to understand? Some explanatory comments that I will write in my program. Please note that during the compilation process Dumbo will strictly ignore these comments. In fact, whenever it translates all the instructions in the translated final compiled instruction set which the Dumbo will execute, these comments will find no place. These are only there as part of my text meant for ours. Equipped with this, my program for Dumbo will be like this. Let's just read this program because we have introduced a couple of very new and different concepts here. The first one says program add numbers. What should it mean to Dumbo? Nothing, absolutely nothing. Instead of writing add numbers, I could have written absolutely anything here. Dumbo looks at slash slash and says ignore. But it is useful to me. Later on if I have 20 different programs, I will know what this program, I am giving it a name and I am giving an explanation program to calculate some of two numbers. But now look at the next set of instructions. Integer, locations a, b, c. What does it mean? My program will use three locations, a, b and c. Better prepare your drawers for it. Next instruction, output. Give value of a. This is that message instruction. So no value will be output, but a message will come to me. And during the execution when a message comes, I know what I have to give. I have to give value for it. Same thing, input a, collect the value of it. So generally such messages and following input instructions will always appear in pairs. I calculate a plus b, assign it to c and then last instruction says output the value of location c. End of my program. Is this easy to understand? All of you can follow what is happening here. Okay. Now we will do a big jump and see the same program written not for our hypothetical caricature Mr. Dumbo, but for a real computer using a programming language called c++. Sorry. I have modified the sample program. First let's look at the modification. Can you guess what is the modification here? Commands are same. Definition of integer locations is same. But I am combining the messaging and input operation. Instead of writing multiple instructions I am saying one instruction give values for a and b. And the input operation say input a, b. They are equivalent. They will do exactly the same thing. This program will work exactly the same way as the previous program. Here is a c++ program. Just read this carefully. This is our first real program. It will actually work on a computer. But I want you to compare this program with whatever we have seen so far using the artificial caricature like Dumbo and see which are the lines in this program which we don't understand at all. Let's look line by line. So do you understand the first line? What does that line say? No, as far as the computer is concerned. Nothing. It's a command line. It's meant for us. But for us, it says file add underscore to underscore numbers dot cpp. We don't understand why this funny nomenclature is being used. We shall see that later. But anyway it is meant for human being. So we will figure that out. As far as the computer is concerned, no issues. Next line. Include iostream. So this you understand. Hashtag include iostream. Can we understand it? No. Stream we know only water stream and such things. So iostream we don't know what it is. So I'll put a question mark here. Currently I would like you to imagine because of the word IO it may have something to do with input and output. Can you guess that? Fine. So this is actually a specification instruction to C++ saying that a particular type of input-output operation is to be used as a standard method in my program which is called the stream input output. That's a complicated name. We take it that it's a specification instruction. We don't understand exactly how this will be interpreted by C++. But in all our programs we'll write this. Sometime towards the mid-sem we'll understand why such names are being used. But it is okay for us if somebody says in my programming language C++ if you want to write programs for me you better write this sentence at the top. Is it okay? You can assume that? Fine. The next. Using namespace std. Can you understand what it is? No. Nobody can. Because this is cryptic. Greek and Latin. Right? So this is, this has to do with the way the computer's memory and the name tags are associated. Namespace. You remember I mentioned address instruction space and data space. The namespace is the sort of set of naming conventions. I'm trying to give you a very crude simplified analogy. But effectively by saying using namespace std, std stands for standard. What it means to C++ compiler is that it has to use certain standard naming conventions which have been defined in that programming. As far as we are concerned we will just say we have to write this instruction at the beginning so that all the locations etcetera we define the names that we define in our program are correctly understood by Dumbo. Let's read the fourth line. Any problem with that line? So this you understand. This is a command. Incidentally in C++ you write the command the same way that we design writing comments for Dumbo. No difference. This program reads two integer numbers and calculates the sum. Knowing that what the program does, later on we are going to see this. Anyway I'll come back to this again. This int, blank, main opening bracket, closing bracket opening brass is all Greek and Latin. We don't understand what this is. So I'll put two question marks here. We don't understand what this is. Fine. We will take it as a mandatory statement which must appear at the beginning of every C++ program. There are some variations. You can also write void underscore main opening bracket, closing bracket, opening brass. So that is three question marks because we don't understand what void is. We don't understand what other thing is. We take it as a rule that this statement has to appear in a C++ program. But now look at the subsequent instructions. Can we make sense out of the next instruction? int a, b, c. Can you relate it to what we defined for Dumbo? We defined integer locations a, b, c. So this is an instruction which is a specification instruction for C++ which says look buddy, I'm going to use three locations a, b and c. Please prepare your drawers and name them with a, b, a. Next instruction. C out less less. Give two numbers. Can you relate it to something? It's an output instruction. Output message instead of output message we are saying C out less less message. Why C out and less less? This is the equivalent in C++ of C output. So this also can be understood. The behavior of C++ will be exactly same as Dumbo's behavior. So we understand this. Next one. C in greater, greater a, greater, greater b. What could it be? Input. So what we said for Mr. Dumbo input a, b. In C++ you say C in greater, greater a, greater, greater b. If you have a, b, c, d, e, f, g to be read, you will say C in greater, greater a, greater, greater b, greater, greater c, greater, greater b, etc. This greater, greater symbol actually is called an insertion operator. We are not going to those details. C in is an input specification which can take one value at a time. So greater, greater, any value. Greater, greater, another value. That's the way you specify input operation for C++. So this is also easy to understand. Next instruction. C is equal to a plus b. All of you can understand that. What is it? It's an instruction to C++ to calculate the value of a plus b and put the result in location C. Next instruction. C out less, less, some is less, less c. Can you understand what it is? It says output first a message, some is less and then a value of c. So two different things being output are combined into one step. I could have also written that as c out less, less some is equal to this and then c out less, less c. So I could have broken this up. Essentially it's an output. This is also understandable. What is return 0? I will put three question marks here. Anybody who can understand what could be the meaning of return 0 here must be a genius. Because return should mean what? Returning something. Now Lambo is executing this program. Lambo has already given me an output of the value c. So why Lambo is now returning something and why is he returning 0? To whom is he returning 0? Not know. So three question marks. Closing brush. Again a question. In this c plus plus program we are able to understand the definition instructions in ABC, the input output instructions and the calculation instructions c is equal to a plus. We can also understand the comments, but we cannot understand the reasons for other states. However if we now say that look we don't know much about c plus plus but if the rule is that in every c plus plus program such statements must occur at these specific places and then c plus plus will work properly. I will write those statements there. After all my intention is to write my computational program and as I can define my computational programs correctly I am comfortable. I will just show you this is my last slide. This is a program which converts temperatures from degree centigrade to degrees fahrenheit. All of you know that formula? Centigrade to degree fahrenheit. Just read this program very quickly. The first one converts c to f dot c p. This is a command c plus plus ignores it. Next one hash include less than and IO stream greater than. Again that famous sentence you know which has to be there as it is we don't know what for. We guess that it has to do with some definition but output. Next one using namespace s t d again the same. So notice these two statements come in this order in every program. The third one is another command to convert temperature from centigrade to fahrenheit. This is meant for you and me c plus plus will ignore it. The fourth one is that famous int blank main opening bracket closing bracket brass. The standard way of beginning every program is like this. As I said we will not discuss any reason for writing this for quite some time but suffice it to say that every program must have this instruction. This instruction will not be translated into any executable. This is actually the beginning of a program. That is how you begin a program in c plus plus. But next you can make sense from here to here is my algorithm. Let me read backwards c out less less f. You understand what it is? Output instruction. f is equal to c star 9.0 divided by 5.0 plus 32.0. Understandable. C in greater greater c. C out less less give temperature and degree centigrade. All of this is understandable. So if you go downwards it will first give a message read the value of c using the value of c and applying the formula it will calculate a new value which it will put in a location for f and give us the value of c. The only major difference is that earlier we had said int a comma b comma c. Here we are saying float c float f. We could also have said float c comma f. What is this? We do not know what float is. The only float that we know is something that floats on water. This is not like that. Float happens to be the type of values which are fractional values and not integer values. We will be discussing the float type values and how computer handles it later but take it to be exactly similar to int a b c. Now it is float c and f. The computer will use the same memory same driver but the value stored inside will be stored differently not in the integer fashion. This is not the difference. Yes, very good question. Why I have used 9.0? For example, why I do not write this as c star 9 divided by 5 plus 32. Isn't it? That is the question. At this juncture we are not capable of answering this correctly. Why? Because we do not see as human beings any difference this expression and this expression. We don't see any difference. As we shall see later because of the different way in which fractional numbers are internally represented and the rules of computations which will study in detail we will know later why we have to write like this and not like this. But as of now at least you are convinced that both of these are equivalent so you can write basic expressions and the rules later we will figure that. With this we will stop.