 So we'll start with an introduction to computing. What we're going to do is we're going to describe a character which is like a Buddha character, an idiotic person. We call him Mr. Dumbo, who represents the machine. We'll look at Dumbo's memory capacity. We'll figure out how Dumbo interacts with us. Then we'll look at the Dumbo's computing capabilities. Specifically, how does Dumbo execute instructions? Finally, we'll look at the most important aspect of our computing model, namely the ability to store our instructions. That is what makes Mr. Dumbo very peculiar. We'll end with two sample programs written in a programming language called C++. Many of you would be familiar with that, but what is important here is the model of computing that we are going to use. We are not going to discuss the underlying hardware with which computers are made. Our objective here is to learn how to compute using whatever hardware we have. An analogy that I can think of is that if you are learning to drive a car, you need not know how the internal combustion engine works, how is the petrol or any fuel is burnt inside, how the walls move, etc. You need not know that in order to drive the car well. However, later on when you have learned to drive the car well and reach your destination, you might wish to know more about the internals of the car. So that is the approach that we are going to follow in the computing. So here is my Buduram computer. We call him Mr. Dumbo. So what are the characteristics of Mr. Buduram? First, Mr. Dumbo has several assistants. We call them junior Dumbo's. I have shown two of them, but there could be many more. One of them could represent the hardware which basically executes my instruction. In which case that junior Dumbo will be really junior junior Dumbo because he would be at the bottom line executing my instructions using and or nor gates of the electronics. We are never going to touch that particular aspect in this course. We will assume that somebody does that job well. On top of it are layers which are called software layers. A software layer which handles, for example, input output. Another software layer which handles command and control the machine. A third layer which is actually a combination of hardware and software which handles actual computations. All of these tasks are relegated to junior Dumbo's. As far as we are concerned, we interact with senior Dumbo using a mechanism which is artificial actually, but that is what has been implemented through what we call programming language, compilers, operating systems and so on. Again, we need not understand those details as long as we understand how to make Mr. Dumbo do our bidding. That's our restricted view of computing. So again to repeat, we have one major Mr. Dumbo or senior Mr. Dumbo and a whole lot of junior Dumbo's. What are the capabilities of Mr. Dumbo? Dumbo cannot do anything on his own. Fantastic capability. But Dumbo can execute instructions absolutely correctly. Somebody has to give instructions to Mr. Dumbo. Obviously, we as prospective computer programmers propose to give instructions to this Mr. Dumbo. Now what instructions can we give Mr. Dumbo? We'll have to analyze that. We'll discuss that when we discuss the computing capabilities of Mr. Dumbo. Obviously, like God, we cannot say let there be light. Mr. Dumbo cannot switch on lights. Mr. Dumbo can do limited things. We'll have to examine what exactly Mr. Dumbo can do and where to give only those instructions which Dumbo can execute. Basically, he can do arithmetic operations, logical comparisons. He can manipulate strings. He can take a long name and break it into two pieces, three pieces called making substrings. He can add numbers. As we shall see later, he can even calculate logarithms. He can calculate sine and cosine. He cannot of course solve symbolic manipulation. He cannot solve differential equations through symbolic manipulation. It essentially does numerical computations or symbolic computations. So essentially, our friend Dumbo can operate upon and manipulate values and produce resultant values. That is Dumbo's limited capability. Since Dumbo can compute, we call him a computer. So that is the genesis. Dumbo, a very stupid person who cannot do anything on his own but can execute instructions absolutely correctly. An additional feature is he can execute instructions very rapidly because he doesn't have to move furniture or something. He has to compute. He has to compare values. He has to take this. He has to do some manipulation. Those things he can do very fast. When computers begin their life in late 40s, do you know when the first computer program was executed in this world on a digital computer? 1949 in a British lab. It tried to calculate the factors of a given number. And it could execute a phenomenal 1,000 instructions in one second. Today's Mr. Dumbo can execute more than a billion instructions in one second. So that is the rapidity with which technology has grown. Of course, for us it means that our program will get executed faster, will get our results quickly. Don't forget that there are still problems lying on the critical part of the spectrum which take even today the fastest computers could take days and months to solve those problems. We shall refer to these problems later on in the course when we discuss more complex problems. So, since Mr. Dumbo can compute, we call him a computer. Once again I repeat, he can execute instructions absolutely correctly and pretty rapidly, but he cannot do anything on his own. There is an additional problem with our friend Dumbo. He cannot remember anything. So for example, if I ask you to add two numbers, let's say 5 and 12, you will come up with an answer 17 without writing it down on a piece of paper. Because you would be storing 5 and 12 as two numbers in your mind. And in fact you can do mental arithmetic and store the results 17 also in your mind. Human beings have phenomenal memory capacities. Mr. Dumbo unfortunately cannot remember anything in his head. So therefore he requires something else. Much like we have notebooks, books, registers, whatever. So we will model a gadget for Mr. Dumbo to remember things. We will use a cupboard with different drawers. The drawers will work as memory. Each drawer is a memory location. So Dumbo's memory, see he is now laughing because he can remember things. Provided they are kept in these drawers. These drawers are named A, B, C, D, E, F, whatever. In fact they need not be A, B, C, D, could be Alpha, Beta, could be Abraka, Dabraka, any name. Because curiously it is not Mr. Dumbo who gives these names. We suggest to Mr. Dumbo that these are the names that you should give to the values that you are going to store in these names. So we have to supply all these symbols. Dumbo on his own cannot do anything. Why names? Why not numbers? Well, it could be any symbol real. In actual practice later on when we will consider the hardware, we will find out that corresponding to a drawer in my cupboard there is something called a hardware memory location which contains so many bits or bytes which will be used to store a value represented appropriately in a binary format. We shall discuss all of these things in due course. Right now we presume that there is a higher level model of computing that we are developing and therefore our Mr. Dumbo uses a cupboard with drawers to store values. Each drawer is a memory location and it is named uniquely. So what you can see is these drawers are currently closed. If you open them you can see a value inside. So each drawer contains some value. For example, you may have a number say 437. Let's say it is stored in a location named B. So I have shown here the drawer B containing a value 437. What is 437? An arpeggio number. 12 minus 17 minus 2000, 99,200 something, whatever. Can we store absolutely any number? Can I store a number with 200,000 digits? Well, our Dumbo is good but he is still ordinarily not that capable. So subsequently we will have to discuss the limitations that Dumbo has on representing numbers. What is the largest value? What is the smallest value? Can it represent fractions as values? Actually not. But can it represent decimal values stored equivalently in binary format or something? Answer is yes. Those values are represented in a particular format called floating point format. We shall discuss the floating point format later. But it is possible for Mr. Dumbo to store values like 2.3174 or minus 28.294, et cetera, et cetera. We shall see how that can be. Essentially numerical values can be stored. Mr. Dumbo can also store character strings. So this is the name Ranadeh. Ranadeh incidentally is Professor Abiram Ranadeh, my boss currently. The head of the computer science department and a very distinguished professor. He taught CS 101 earlier so I have chosen his name. So if I want to store his name, his name could be stored in let's say a memory location called F where I have shown the value as being stored as Ranadeh. So is this clear? Dumbo uses memory drawers to store values. Each drawer is uniquely named. Obviously if you have two drawers with the same name B, then you'll have problems. Because later on if you ask Mr. Dumbo to look at a value in location B, which B does he use? Can you afford to have in a housing colony two houses with exactly the same address? There will be a lot of confusion. So unique names are required to identify values. There are some more peculiarities of this memory. Each location can contain only one value and not multiple value. This is so different from a piece of paper which I have shown lying inside the drawer. For example, if this is the piece of paper that represents my memory, so I can not only write 437 here, but if I want in the same paper I can write 23.987. I can write my name Fatak as a string. So how many values does this paper have now? Three values. Unfortunately Mr. Dumbo has very limited memory capacities. These three values will have to be stored in three separate locations. There is no concept as of now that our Mr. Dumbo has to store multiple values. Later on we will discuss more abstract structuring of these data values when we discuss arrays for example or linkless or queues and such things. We'll find out that there is an abstraction capability available with Mr. Dumbo where he can put together a set of values, classify them as a separate structure. Still an individual value is what will occupy the memory drawer in the memory location. The values in locations are normally unknown. Suppose there is a location, let's say we call it beta. So this is the name of the location. This is one of the drawers that Dumbo has. What is the value inside? Now that is a major point to be remembered. If you have actually a cupboard you can have drawers containing nothing. Right? You can have drawers in which you have not put anything. Unfortunately Mr. Dumbo's drawers are not permitted to have nothing. Even if you want to say that drawer contains nothing you have to give a value to Mr. Dumbo to store it inside called null value. Otherwise there will always be some value. What will that value be? Since we do not know that value we will generally put an unknown value as a question mark. So ordinarily a memory location will contain some value which is not known. So how does a desired value get into a location? A desired value gets into a location in either the two ways. Either we supply a value which Dumbo stores there in that location or Dumbo calculates and puts some value there. These are exactly two possible ways in which a desired value can get into a memory location. There is absolutely no third way. No value through black magic can come and sit into a memory location. And please note as I told you earlier none of these activities namely supplying a value to Mr. Dumbo which he stores there or Dumbo calculates something and puts a value there. None of these things can happen automatically. Dumbo is incapable of doing anything on his own. So for each of these we will have to give an instruction to Mr. Dumbo which Dumbo will execute, carry out. It could be either a value to be taken from me and put it in the memory location or it could be a computation which the Dumbo does and puts a value. Is that clear? So this is the memory model of our computing that we use. To recapitulate again Mr. Dumbo can execute instructions, can manipulate data values, can also exchange values with us and Dumbo cannot remember anything. So he stores values in a memory which is modeled by a cupboard containing drawers. Each drawer has to be uniquely named and we have to supply the name for that drawer. The values inside that drawer will be the values corresponding to that name. So when we say beta for example or we say A or we say B or we say D we actually refer to the value inside the drawer and Mr. Dumbo is capable of looking at the value or putting a new value there. How do we exchange values with Dumbo? So Dumbo uses a card. Does this look like a card? It has wheels. So Dumbo has his memory is generally he is the computer for us. We are sitting outside somewhere. So remember what I said? Dumbo can take values from us and give values to us. He uses a card. That card is called data bus for short. Actually very curiously the computer scientists have goofed up and they have called this path as the bus. So this path that you see, this is called the bus. Now bus ordinarily for us means a vehicle which runs on a path. But forget the nomenclature. For us the bus means the path and the cart on it. And this cart or a wheelbarrow or whatever you may call, it can move data between us and computers. So he can put a value in a location as instructed or can copy a value from a location and give it back to us. Is this clear? That's how Dumbo exchanges values. But Dumbo does anything only if instructed. So what kind of instruction should we give Mr. Dumbo to collect a value from us or to give us a value? Here is an instruction which we give Mr. Dumbo to read a value from us and put it in a memory location. So look at this carefully. C in greater greater B, semicolon. Looks like a funny instruction, right? Suppose you want to ask somebody to keep something in a drawer. What will you say? Take this pen and keep it in the second drawer. You can understand that instruction very easily and you expect the other person also to understand it. But Mr. Dumbo is very peculiar. He understands instructions given only in a certain way. In fact, all the instructions that he can understand together constitute a language which we call a programming language. It is different from English, different from Marathi, different from Hindi, Hebrew, Spanish, whatever. It's a different language. It's a computer language. There are many computer languages. We shall look at that later. But our Mr. Dumbo, we shall call him C++ Dumbo. You may want to note down this moment. Can you read this? Who is C++? It's not Marathi. It's not Hindi. It's the name of a programming language which computers used. It's actually written as C++. Why such funny name? All computer languages have funny names. We shall see the history of programming languages sometime later in the class. These names are given by computer scientists who invent these programming languages or who define these programming languages. Now the individuals have their own idiosyncrasies. So I can't define any language. So original languages of the kind that we use which are called higher level languages were named first as abbreviations. The language called FORTRAN, for example. This stands for formula translation. And this was the first higher level programming language introduced in the world in 1956 by a group of computer scientists, some working for IBM Corporation and some who were users of IBM machine. So since 1956, this higher level programming language came into being which has studied the subsequent abstraction such as compilers and operating systems required to actually make the instructions written in this language run on a hardware computer. But as I said earlier, that does not concern us. Similarly, there was a language called COBOL. This language COBOL which stands for Common Business Oriented Language. This was defined in 1960. This was defined in 1956. Then there was a language called ALGOL which stands for algorithmic language. In fact, we shall see later that the computer's instructions that we write which are collectively called a computer program often refers to the instructional implementation of an algorithm that we have in mind to solve a problem. And then there have been languages languages. So the present C++ Dumbo that we are discussing has its origins in a Dumbo called C-Dumbo which was a C programming language understanding Dumbo. And the programming language was named C because somebody has just few years earlier had defined a programming language called D. So you can see how nonsensical things end up confusing us at the end. Nevertheless, we'll take our Dumbo to be a C++ Dumbo. So coming back to our slide, in C++ the instruction to say, please collect a value from me and put it in your drawer is read as C in greater, greater B. That is why the natural questions which should occur to you is why C in? Why not simply say input or because the computer is going to read a value from us? Why not say read? Or since computer is going to get a value from us, why not say get? Now these are questions which are no answers. I mean, you can argue about the word in any language. Forget the computer programming language. For example, if I want somebody to go very quickly to my office and get some paper, I'll say run. If I have to do the same thing in Hindi, I'll say bhaagoh. Now somebody who is Tamil will say what is bhaagoh or somebody who is Spanish will say what is run. These questions are no answers. Somebody decided to name these things like this. There is an additional thing. In English or in Hindi, if I make some small spelling mistake, the fellow can still understand the written instruction. Like instead of bhaagoh, I say bhaagoh, he can still understand that I mean running or something. But in computer programming, Mr. Dumbo is so dumb that unless the instruction is exquisitely correctly spelled, Mr. Dumbo will get confused. So we have to say, for example, to get a value b, we have to say c in greater, greater b semicolon. Again, why greater, greater, why not less, less? Well, we shall see less, less very soon. But these are peculiarities of symbolism that people have used to define. Nevertheless, the purpose of c in greater, greater b is that if we tell Mr. Dumbo, c in greater, greater b, what Mr. Dumbo will do is take the card, bring it to us, collect the value from us, carry it all the way to the major Mr. Dumbo, who will put it in the memory location which will be named as b. This is very clear. Please understand that when this value is put in, no matter what existed in the location b earlier, that will be destroyed. Old value will be destroyed. Please remember what I said. There's never an empty drawer. So that drawer contains something. It might even contain the same value that we have supplied. But that is incidental. It contains a question mark as far as we are concerned. That question mark will be wiped out and this value will be put in. Let's do a quiz. If I give this instruction c in greater, greater b, and let's say I give a value 32. The value 32 goes there. I again give in an instruction c in greater, greater b. What will Mr. Dumbo do? He will say, boss, you just give me a value. Or he will take a value but say, no, no, I have just put a value. I will not do anything with it. Or it will take the second value, religiously wipe out the old value and put the second value in. What do you think it will do? Last one. Remember, Dumbo is Dumbo. He cannot think. It does not have common sense. So if you give him an instruction c in greater, greater b, five times, he will religiously collect five values from you. And only the fifth value will be there in the location. He is Dumbo. Dumbo can also give us values from locations. The instruction to do so, so c out less, less g. What it means is, look up the value in g and give that value to me. So Dumbo will copy values from his memory locations and present these to us. The values in locations are undisturbed. This is the difference between getting values in and giving values out. Getting values in destroy the existing contents. Giving value out is merely, he reads up the value from that location, sort of copies it, and the copy is kept in that cart, and the cart is pushed in. The value remains in that storage. In short, an output operation or exchanging values to us does not destroy the contents of memory locations. But getting value in destroys the original contents and the new contents replace them. There is simple and common sense. Anybody has any confusion here? Please raise your hands. Okay, so there is simple concept. There is a useful variation. Ordinarily, if I say c out greater, greater g, the following may happen. Suppose the value of g is 12.24. This is what I see. Now if I have given instructions to compute only one thing called g and the Dumbo gives me that value, I know it is a value for g. But suppose I have asked Mr. Dumbo to compute 25 different things and then give me all those 25 different things, maybe one after another. I have given a sequence of names in the desired order. But when the values come to me, I will only see the value. I would know which value is what. Would it not be nice if I had, for example, the value of g is, you agree that this will look better? I can understand things better. So to permit that, Mr. Dumbo actually has a variation of the instruction of c out, which says value of count is c, for example. So I have here a string which is printed verbatim by the computer to me. And then will be shown c, whether you put a comma or whether you put another less less depends on the syntax. We will discuss the exact spellings et cetera, et cetera later. This is just to build a model of computer. So you are very clear on exchanging values between Dumbo and us. Good. Now we go over to the computing capabilities of Mr. Dumbo. Oh, here is some trying out of Mr. Dumbo's input output. Notice that I give him these two instructions. Give value for b. Why am I saying this? Suppose I had said only c in greater, greater b. What would happen? Dumbo will come to a cart and say, give me a value. But even I won't remember what value I have to give him, whether it's for b or a or d or whatever. So it is nice to give first an instruction which will tell me later what value I am supposed to give. So give me the value for b. This will first come out. This c in greater, greater b will actually permit this junior Dumbo to take a value, say 437, and store it in b. You'll recall we had this value 437 in b in our memory model. And we had a string stored in location f. So let's look at the next one. Give value for f. So we give this value. There is a small trickle here. When I say run a day here, how do I know it means the word r, a, and a, d? Of course that's what I mean. I don't mean Professor Rana Day himself, right? There will be no point in carrying Professor Rana Day inside a memory location. So to indicate very clearly that I am giving actually a string value, the value that I should give should always be written using a double apostrophe here, a quotation. So whenever we give a value, we would delimit that value on either side by a quotation mark. This means that a string is being given. What will get stored in f is, of course, the string without the quotation marks. But this is an absolute discipline that we have to follow. Whenever we give a string value, an actual value, it has to be in quotation marks. We shall see variations thereof when we are giving bulk values of 815 names, et cetera, how exactly that is handled. So is this clear? Okay. Now we look at Dumbo computing. Let's assume that using that input and output, we have stored two numbers in drawers or locations called A and B. Let's say A contains 35, B contains 12. We said earlier that Dumbo can add these two numbers and store the result in some other drawer called sum. Even here, the drawer containing 12, which is drawer B, we presume that A contains 35. So here is a sum. Why I have shown a question mark? That's because I don't know what value it is. I presume that A and B are to be added, so I have determined the values in A and B by, let's say, giving the input to that Dumbo. But sum, I do not know what it is. I don't care. This is the current situation. But if I want Dumbo to do this, we have to give Dumbo an instruction. The computational instruction that is given is sum equal to A plus B, same equal. There's another instruction to C plus plus Dumbo. It does not mean that I am giving him a formula saying A and B together always add up to sum. That's not a formula. It is actually a formula insofar as the right-hand side of that equal to simple is concerned. The equal to symbol is to be treated as an operation of assigning a value to a symbol. So sum is a symbol which I am computing. Right-hand side is A plus B. Mr. Dumbo is expected to calculate A plus B and put the value, resultant value, on whatever is the symbol which is there on the left-hand side of the equal to sign. This is in fact called an assignment statement, as we shall see later, where this is a variable to which we are assigning a value and named a drawer in which that value will be kept. Very obviously, while right-hand side can have a very complex expression and we shall see what are the rules by which we can write an expression, on the left-hand side there must be exactly one name. So because only in one name the final value can be stored. This is an instruction that we give to Mr. Dumbo. Mr. Dumbo being dumb immediately goes into a hurdle. How do I do that? So Mr. Dumbo again uses one of his assistants. Some junior Dumbo's come in. Let's call him junior Mr. Dumbo. What he does is he actually uses rough sheets like I have these pieces of paper to do the computation. Much like what you would do in a complex arithmetic. So whether it is simple or complex, Dumbo has no other way. What Dumbo's assistant will do is that he will first access the location A, copy the value 35 onto a register. Then he will open the register B, look at the value 12, copy into another register. Then he will actually add these two values on that piece of paper or register. The addition will be 47 naturally. And finally this junior Mr. Dumbo will store this value 47 back onto the draw. The location sum will now contain value 47. An extremely simple exercise where I am going through this is exactly how a new value can be computed and put inside any memory location and there is no other way. One way was getting a value from outside and putting it in. The second way is compute using any complex formulation that you have but ultimately that computational result will get a value which can be put inside a memory location. So this is what Mr. Dumbo does. I have shown here a table on which he sits. He is the assistant. So he should actually be a shorter fellow. He sits on this table. He opens up draw A, gets value 35, opens up draw B, gets value 12, adds these two, gets the result 47, takes this value 47 and puts it in the location called sum. I am explaining this elaborately to also to indicate that it is not in zero time that such computations can be done. A lot of work is involved. Excess memory, open drawer, copy value. Except that Mr. Dumbo does this very fast but just to give you an idea to execute any one instruction that I give or to copy one value from memory on to the register to sum two numbers, any one of these things. If Mr. Dumbo takes one unit of time then if Dumbo has to do five or seven things it will take seven units of time. If Dumbo has to execute 1,000 things for solving a very complex expression such as computation of logarithm of a value by summing up an infinite series after truncating it after so many terms it may take much longer. Even the longest time it may take but we are trivial because it might be a few microseconds for us. But few microseconds is thousand times more than a few nanoseconds. You should remember that later on when we discuss the computational complexity of our algorithms when we compare two different ways of computing and find out which one is faster or which one requires less memory these issues will become very important later. So coming back to the computing model I think it is very clear that Mr. Dumbo through the use of these local registers can do some simple computation. So going back to the original instruction then A and B will continue to hold the existing values 12 and 35 and the location sum will now contain 47. We now have two basic capabilities of Mr. Dumbo understood in our model and we have also understood how to give instructions to Mr. Dumbo. The first capability is collecting values from us putting them in memory locations and giving any value back to us. That is we call input-output capability. The other capability is computing capability and assigning the resultant values to a particular memory location of our choice. That is the computing capability. Together with the input-output capability the model is now complete and we can actually make Mr. Dumbo do some useful work for us. But how do we give instructions? How many instructions will we have to give if we have to add two numbers? Agreed? First I have to give a value. Semi-colon. We agree that I will have to give these four instructions to my friend Dumbo. First read a value A, next read a value B, next calculate A plus B and assign the value to some and next give me back that sum. How do you propose to give these instructions? You give one instruction, computer executes it, you give second instruction, computer executes it, you give third instruction, computer executes it. Dumbo can do a little better than that. But it is extremely useful to remember that that is not how normally machines behave. Most machines take one instruction at a time and execute it. Suppose you are driving a car. What do you do? You first start the car, get out on the highway, put it in the gear, press accelerator, the car moves forward. You find a buffalo in between, you press a brake, car stops. If there is no traffic on the road and you are riding a bicycle, again the way you will instruct the bicycle is when you press the pedal it will start moving. When you rotate the handle right, the bike will turn right, rotate it left, bike will turn left, etc. Suppose you know exactly the route map from your hostel to this place. You will still have to keep giving instruction to a bicycle every time you want it to execute. Can you prepare a set of instructions knowing exactly the road map from your hostel, let's say hostel 5. Everybody has seen hostel 5? Which hostel you are most familiar with? Any hostel? Fine, fine, lots of hostels. But effectively you will have to get the bicycle out of your hostel gate, turn right or left appropriately, take the road and when you come near the convocation hall, stop the bike and then get into the class. But can you give all these instructions on a piece of paper and show it to your bike and just sit quietly so the bike automatically moves? Doubtful. In fact not possible. Most machines behave like this. But our Mr. Dumbo is a very special machine. We can write all our instructions in advance and give the entire lot to him and tell him I have written these 5, 10, 1,000, 10,000, 50,000 instructions. Please execute all these instructions in the given sequence. First this, next this, next this, next this, next this. That is the specialty of the friend Dumbo who is actually a computer. This collection of all instructions is called a program. So a computer program is nothing but a collection of instructions which we write in advance. Naturally we can't write the instructions in isolation. We'll have to think about which memory locations to put what values in how to compute and appropriately where to give input instructions, output instructions, computational instructions, etc. and a lot more which we shall study in this course. But the fact is that all these instructions can be put together in a single lot called a computer program and Mr. Dumbo can store this program inside. This is called stored program computing and the architecture of computers is therefore called a stored program architecture. This was the biggest logical invention of the last century. Till then computing machines were there. You are familiar with calculators. So earlier calculator if you take any calculator you'll put a value then press plus then put some other value press equal to you'll get the result. You are giving instruction calculators following it. Today you will find there are many programmable calculators. Programmable calculators are nothing but a junior Mr. Dumbo who can actually take a whole lot of my instructions in advance and automatically execute. But Dumbo perfected it for the first time in 1949 when the first computer program was executed where you collectively put all the instructions. I'll repeat again. Mr. Dumbo or C plus plus Dumbo or for that matter a Fortran Dumbo or Algol Dumbo or any Dumbo or the real computer which we shall be working with. These are all spatial machines. They can store pre-written instructions somewhere inside and automatically execute them. Where does Dumbo keep the program? Remember we started by assuming that Dumbo cannot remember anything. Yes Dumbo cannot remember anything. So what Dumbo does is it uses some space from the same cupboard. It has one big cupboard. It uses some space of that cupboard to store data values and some other space to store the instructions of my program. Logically these two are separated out and we have to inform Mr. Dumbo that what we are giving you is a program and later on when program is executed all instructions are executed by Dumbo in the given sequence what we give or get our data value. So there is a mechanism to tell Mr. Dumbo that what I am giving you is a program and then all instructions of the program will be taken by Mr. Dumbo and stored in a separate sort of space. It may use ten drawers. It may use twenty drawers. It may use hundred drawers. It may use two drawers. It depends upon how many instructions I am giving. Would those drawers also be named A, B, C, sum, etc., etc.? Fortunately not. We do not have to worry about how Mr. Dumbo stores those instructions. Actually Dumbo will use memory locations more like numbered locations. 0, 1, 2, 3, 4, 5, 6, 7, 8. And those individual memory locations at the level of hardware will not necessarily contain all my instructions which I give to a C++ Dumbo. All these instructions will be translated with the help of additional junior Dumbo's called compilers about which we will talk later who will translate all these instructions into bits and bytes that the original Mr. Dumbo can understand and carry out those instructions. But we need not bother about that. All we assume is that yes, our friend Dumbo is capable of collecting instructions from us as a whole which we call a computer program. We give it to him to begin with. Mr. Dumbo can store this program inside those drawers and can carry out instructions one by one automatically. And we also necessarily confirm that the instructions are kept somewhere else. Imagine what would happen if the instructions are kept in my data drawers. So suppose my data drawer called C contains an instruction and somewhere I have an instruction which says C is equal to 25. So that instruction will go away and the value 25 will go there. That is not to be permitted obviously. Now here is a complete program so let us look at this program. You will notice that in this program there are some instructions which we have already seen. For example, C out less less, give two numbers. C in A, C in B, sum is equal to A plus B. C out, sum is sum. You can all recognize these instructions. We just saw them as instructions pertaining to Dumbo having to collect two values from us A and B calculating sum is equal to A plus B and giving us back that sum. But in this program or the collection of instructions we suddenly have extra instructions. Let us read and try to make sense out of these extra instructions. There is a very funny thing here. It says hash include I O stream. What is this? We do not know. The correct answer is we do not know. So this is actually an instruction which our C plus plus Dumbo understands that the subsequent instructions in the program which are given will require the help of one Mr. Junior Dumbo who is called the I O stream Dumbo. I O stream is the name of another Dumbo who will actually handle input output for me. That is the meaning. We need not understand that meaning. For the time being we will keep this instruction always as the first instruction of my program. The next instruction says using namespace STD. STD actually stands for standard. Now what the hell does it mean? What is namespace? Well, you remember we said that all drawers are given names. What kind of names can be given? This is one program. I can actually as we shall see later I can give Mr. Dumbo 20 different programs together. I might be using the same name in one program to mean something and another name in another program same name in another program to mean something else. There could be confusion. So there is a definition called namespace, the space from which names are chosen by me. And I have to actually qualify each name that I use in my program with that namespace. So instead of doing that I am saying using namespace standard. Basically what I am telling Dumbo is, Baba, I don't understand this complex mechanism. I am doing some simple things. So use all my names in the context of something standard. I don't want to be bothered further. Again, we do not know the complete meaning of these two lines. It is like this. Let's say Swahili which is a language spoken in Africa someplace. Anybody know Swahili here? No, good. What you do? Oh my God, dangerous fellow. So suppose we have Mr. Dumbo who understands only Swahili. Then we might have simple instructions like read this, read this, calculate this, give me this. But that Mr. Dumbo needs to understand so many other things about my program. I don't know how it is to be said in Swahili. So I will ask some expert who will say first say this, then say this, then say this. So I will mug it up without understanding. And I will reproduce that followed by my instruction. That's exactly what we are doing. Our C++ Dumbo we know can read values of A and B, calculate some and give us out that value. All other things are we take it as something standard. Something abrakadabrakad. Some black magic. Something standard. So in all our programs we'll write these two things. Please notice a special line here which says slash slash. And then curiously an English language sentence here. Slash slash. Again an English language sentence. What these two sentences say? This program takes two integer numbers as input and calculate their sum. So what does Mr. Dumbo do? The first two sentences we said are instructions to our C++ Dumbo of some standard kind. But what is this third and fourth line of my instruction tell Mr. Dumbo? Any guess? Well, those people who have written programs are shouting come in, come in, come in. But if I have never written a program in my entire life I will presume that this is some kind of instruction which is trying to tell Mr. Dumbo in plain English what I am trying to do. The actual fact is Mr. Dumbo does not understand English. It is the C++ Dumbo. So very obviously this line is not meant for Mr. Dumbo. So for whom this line is meant? For us who read this program. Imagine such programs are printed out on a piece of paper and you suddenly see a program to figure out what that program is doing. Ordinarily you will have to go through all the instructions and execute them exactly like Mr. Dumbo does to understand what that program is doing. That is idiotic. So we would expect any human being who has written a program for our C++ Dumbo to be kind enough for other human beings and write a few explanatory pieces in plain English. That is what is written here in these two lines. However, since these two lines do not make any sense to our C++ Dumbo for him it is Greek and Latin, not C++. So to tell him don't worry, please forget these lines. We put these two slashes here. So these slash slash and slash slash. Any line in my program which begins with a slash slash in a C++ program means it is a comment line that comment is meant for me and my fellow human beings. Mr. C++ Dumbo, please ignore these lines. So even if there is a valid instruction written in this line Mr. Dumbo can understand C++ Dumbo will ignore that because it is a comment line. So we are already looking at a very formal structure of a formal programming language called C++ and trying to understand how C++ programs are written for our Mr. Dumbo. First two lines, some standard abracadabracad, we don't understand what they do. We guess that these will permit Mr. Dumbo to understand our program properly and we put exactly as they are without any thinking. If we don't put them, my programs will not run plain and simple. Mr. Dumbo cannot understand it. Later in this course, we will understand what exactly is the meaning of this. The next two lines, well, they are comments for me. Mr. Dumbo has nothing to do with them. The next line, int main who is int, well int is a short form for integer. Ordinarily you associate integer with numbers. Integer, string, fractions, etc. But why are we saying int main, opening bracket, closing bracket? Have you ever seen in any of your normal writing including mathematical writing an opening bracket immediately followed by closing bracket with nothing inside? That is stupid, right? Well, this is the stupid way in which Mr. Dumbo is being advised that what follows is my main program. So instead of saying I am writing my main program I have to tell Mr. Dumbo something like int main, opening bracket, closing bracket. Again we will take it as a gospel truth for the time being. We will not wonder why such silly thing is required to be done. We will assume that that is how the C++ Dumbo understands a program. The program itself is written inside one pair of brushes. So this is an opening brass and this is a closing brass. Can you see that? So whatever is written after opening brass and whatever is written after closing brass before closing brass is the program actually. The instruction. We generally write an opening brass on the same line as int main opening bracket, closing bracket. Then write all my instructions and at the end after the last instruction I write a closing brass. That is to be the standard way in which we will write programs. Of course there are variations possible. As we shall see these brasses can physically appear somewhere else along with the first line at the end of last line etc. But this is a practice we will follow. Why? Because we want our human colleagues to read this program easily. So if everybody uses exactly the same standard way of writing then anybody else reading this program will say the program starts here program ends here. That is the purpose. Let's analyze subsequent lines. Int A, int B who are these jokers. Well, remember we said we are going to add two numbers to get the sum. We also said that there are no names to the drawers originally to begin with for C++. We have to supply the names that we want to use to store values. This is our way of saying that I am going to use two names A and B and each of these two names will store integer values. That is the meaning of the word int here. Int means integer. A is a symbol which means there is going to be a location in your memory called A in which you are going to require to store integer value. Int B. This is not an instruction to carry out any action. This is actually a preparatory instruction. Before you carry out the instructions which I give please make these preparations. What Mr. Dumbo will do is it will take a level A, stick it on to one location take a level B, stick it on to another location. Then follow the instructions. I hope you can all understand these instructions very easily. See out given two numbers. C in greater greater A, C in greater greater B. Sum is equal to A plus B. C out less less. Sum is sum. Return zero. Who is return zero? Why should I return zero to anybody? I should return 25, 47. I should return the value of sum. Well, the value of the sum is being given to me by Mr. Dumbo. So how do we interpret this return zero? So actually if you recall just to give you an analogy we said that my program will be executed not by the main Mr. Dumbo but by a junior Dumbo. What actually happens is Mr. Senior Dumbo gives him these instructions after setting up the memory locations and so on. And at the end when Mr. Junior Dumbo has given us the value of sum the Junior Dumbo actually hands over control to Senior Dumbo and that's how it works. So it is his way of saying return but why not only return why return zero? Well, the Junior Dumbo either has carried out my program instructions correctly or he has goofed up he has found some mistake. For example suppose I ask him to divide A by B and the value of B is zero. Now we know that anything divided by zero is infinity. But since infinity is not a number which either Junior Dumbo or Senior Dumbo understand we will get confused. And when he gets confused he will run to Senior Dumbo saying so that indication of is a value other than zero here. So if the return is not zero then the program has not been executed correctly if return is zero program has executed correctly. Again we will not bother about the semantics of these additional instructions at this moment. We will just take it to mean that always in a program where the main instructions are input, output and computations we shall precede these instructions by these standard things. We shall always precede the actual instructions by commands which are meaningful for that program. I should not write the same comment everywhere that is not standard. And at the end of all my instructions I will say return zero semicode. Is that clear? This is how our Mr. Dumbo behaves. He is asking some question because he has done some C++ programming so he is trying to figure out what is the problem with this program. Actually there are many problems with this program. They are all there by design. He is mentioned one of them which most of you would not be able to spot out now because if you are not executed a C++ program you do not know where Mr. Dumbo will shout at you saying I do not understand this but consider this simple I have said int a, int b how many symbols I am using? a, b and a fellow called sum what should we sum? Suppose we leave it to Mr. Dumbo and Mr. Dumbo interprets as a character string calculates a plus b takes the numerical value converts it to some arbitrary character z and gives us z instead of a numerical value. It will be nonsense. So what I must do here I must say int a, int b, int sum I must define every symbol. This is one error I am pointing out. There are many errors and one of the assignments in your first lab will be to find out such errors, correct them and run that program correctly. Here is another program which converts temperatures from degrees centigrade to degrees Fahrenheit. Forget the rest of the crap. Here the only thing of importance is my centigrade values and Fahrenheit values may be fractional values may not be integer. C and float f instead of int I am saying float c, float f all I do is I ask for centigrade value, get in the value for c I do the computation c multiplied by 9 divided by 5 plus 32. Everybody is familiar with this formula? Standard form. So c plus plus Dumbo fortunately understands this calculates f and c out f it will give me 9. There are two quizzes which I wanted to conduct here but there is no time so I will not have quizzes now.