 So, we will continue our discussions from where we left last time. Today, we will look at the real computer a little bit. We will just look at some basic details which have implications on the way we do programming in high level languages. Other than that, we will just treat this as some kind of a byline story. Keep in mind, we will be revisiting the internals of the computer in greater details sometime later in the course. So, this is just to get you a feel that while we have been using our conceptual model based on a caricature called Dumbo, there is something real and that something real is very similar to the way Dumbo operates except that the internal details are different. So, you look at that. We had seen two sample programs in C plus plus last time. We will take another problem this time and try to write a C plus plus program, but this time we will look at the problem and the way the problem is solved. It is a simple problem. So, it is a logical extension of the program that we wrote last time, but this just to illustrate the methodical way in which you must approach problem solving. The meat of the lecture today will consist of rules that we need to follow while writing C plus plus programs. These will include the naming conventions. These will include the various data types or the different types of values that we can represent in C plus plus. Finally, the way numerical expressions are evaluated in C plus plus. We will very briefly look at the course organization for CS 101 because now we can define what exactly we wish to do. Along with announcements, I had already mentioned that we will have extra lectures tomorrow. These are lab lectures and the first lab for the course will be conducted for all students on Sunday. The exact timings for the Sunday will be announced tomorrow during the lecture, but I will describe in which way the labs are going to be organized. So, here we go. So, the first thing which is unique about digital computers is that it cannot represent information using multistate symbolism that we normally deploy. For example, our decimal numbers are written using 10 distinct symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Additionally, we have created a whole lot of additional symbols like all the signs plus, minus, star, non-competitional side we have symbols which represent alphabets of different languages differently. So, Greek, alpha, beta, gamma, delta, etc. look completely different from A, B, C, D which look completely different from C, C, C, gamma, etc. So, we actually have developed a whole lot of symbolisms. All these distinct symbols are used for different applications by human beings. The digital computers on the other hand because they consist of digital circuitry and the digital circuits are characterized primarily by the fact that they can represent two distinct states in which let us say electrons flowing through the circuits can exist which are distinguishable. So, one is called the on state, another is called the off state. It is just like a switch on, switch off. So, if you switch on the light with bulb bill light switch off bulb bill go off equal and rough. And therefore, traditionally these two states have been used to represent two symbols. Numerically, they correspond to 0 and 1. Consequently, everything that you wish to do with the computers, the information must be represented somehow using these two symbols and these two symbols alone. These symbols are called binary digits or bits. You are familiar with decimal number system which uses base 10, but we can actually have a number system consisting of any base. If you add 8 symbols, I had mentioned 0, 1, 2, 3, 4, 5, 6, 7 then you can construct a numerical system in which numbers are represented using the base 8 called octal numbers. You can have hexadecimal numbers which has base 16. Any base which is larger than 10 will require larger than 10 symbols. So, hexadecimal system for example, will require 16 different symbols. Since it is a numerical system we tend to use 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 as the first 10 symbols, but for additional 6 symbols we deploy letters A, B, C, D, E, F. Consequently, it is not uncommon to find a number written as 6 B, F. So, what is the value of this 6 B, F in our conventional notation? To understand that let us first try to find out how do we determine the value of 537. This is actually equal to 5 multiplied by 10 to the power 2 plus 3 multiplied by 10 to the power 1 plus 7 multiplied by 10 to the power 0. You agree? That is the basis of decimal system. So, whatever is the base you multiply it with the power 0, 1, 2, 3, 4 increasingly and multiply that with the digit that appears in that place. In the case of hexadecimal, the digits which appear are 6 B and F. How would you then interpret the value if you were to write it in some kind of a decimal value equivalent? You will say 6 multiplied by 16 raised to 3 plus B, B will stand, sorry 2, 16 raised to 2 plus now B multiplied by something, but B is not something that can be multiplied. So, what is the equivalent decimal value of B? Let us put it this way 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. So, A is 10, B is 11. So, therefore, this will be 11 multiplied by 16 raised to 1 plus F. F is 15, the last symbol in a hexadecimal notation. So, 15 multiplied by 16 raised to 0. Once you understand this, the binary system is much simpler. It has only 0 and 1 and the power that you will raise to will be of the base 2. Let us say this is a binary number. If you read it as decimal, it will read as 10011. But if I treat it as a binary number, what this will be in decimal terms? It will be 1 into 2 to the power 3 plus 0 into 2 to the power 2 plus 1 into 2 to the power 1 plus 1 into 2 to the power 0. So, this is no, just this value. Just to distinguish between different bases, we would tend to write this more correctly as a subscript 10 at the end and here a subscript 2 to indicate this is binary, this is decimal. I am just illustrating this for the sake of understanding. We will not be using binary number system for any purpose, including for tests and examinations. So, this is just for the understanding. The binary digits that we represent 0s and 1s will flow as electronic signals inside. Let us try to relate to the Dumbo's model of computing. What all did Dumbo have? Dumbo had a memory which was a chest of drivers and Dumbo had a work table where he could take the values and add and subtract and so on. So, you can imagine that inside that work table which is actually called a processor of the computer, we will have circuits which are designated by different symbols like this. So, suppose you want to add two numbers, the numbers will be added here. This circuit may go somewhere else. There will be another circuit here like this, some other input and so on and there will be a plethora of circuits like this. So, electronic signals will be flowing across these and they will be working on bits which come in and they will be producing bits as output. That is what they do. All these circuitry will actually constitute the component of the processor. These are implemented typically using transistors. In 1950s, 1950s when the computers were first generated, there were no transistors. There were big valves. Then transistors came. Then came integrated circuits which you are familiar. What you call a chip today has not 10 transistors, 100 transistors, 1000 transistors, but a billion transistors. That is the level to which electronics has progressed. The same set of electronics is also used to build computer memories. So, remember we represented computer memory by drivers in a chest of drivers in a cupboard for Dumbo. Roughly similar representation can be made by saying that, look, this could be a computer memory and these will be various locations. The difference is that what can go inside a location will be only bits. So, there could be maybe 1010111001 something in one location, 0000111111 in another location, etc. How many zeros and ones can be accumulated inside a single location? We do not know that. The capacity of a location will depend upon the number of bits that the location can store. Similarly, how many locations can you have? Well, as many as you can afford because memory can be attached to a larger and larger and larger. So, there are two aspects of the computer's memory. One is the size of the memory and the other is the capacity of a single location. So, totally how many bits will you have in the computer's memory? Size multiplied by number of bits. Very simple. The information flow between computer's memory, the computer's processor and the external world happens through a simple architecture similar to what we have seen in case of Dumbo. So, there is actually a large electronic path which incidentally is called a bus just like we call Dumbo's cart as data bus. So, this is the bus across which the electronic bits flow. There is indeed a memory here, a memory block and this is connected to the bus. The computer's processor is also connected to the bus. So, the processor is capable of reading from the memory, get some locations in, do the processing, add subtract, multiply whatever and push the results back to the memory. The equivalent of input output cart that we saw in case of a simplified Dumbo model is not represented here. This is like when Dumbo is computing. It will take values from memory, do some computation on the workbench, the registers that we said Dumbo has and put the results back. So, this processor is more like the workbench of the Dumbo. That is where computations will happen. Memory is the place where different locations will exist, different values will exist. Where do we exist? We exist outside of this. So, for interaction with us, there are other devices which are tagged on to the same bus. A device which you shall be seen mostly will be a terminal. So, there will be a keyboard like a typewriter keyboard and there will be a monitor on which you will see information that is displayed by Dumbo or the which you enter from your keyboards, you can see that information. So, this is the way your information exchange will happen. Please note that equivalent to Dumbo, the computer's processor in response to the execution of an input or output command will actually connect this terminal to the appropriate memory location doing required transformation of values, etcetera. What you will see on this terminal will not be a series of binary bits because that will be nonsense. We cannot make sense of it. What we will be using at the front end will be decimal numbers, 6, 5, 3.7, etcetera. What processor does with it is some kind of a translation. We will see exactly how that is done, more details at a later stage, but that is how we interact with the machine. Since this memory is digital, it is volatile. Your switch of the power contents go away. Now obviously, when you write a program like a C++ program, you enter it methodically here. Let us say some superior portion of the computer reads that program in C++, translates it into its internal native instruction set, executes it. Now, tonight it is switched off. Tomorrow you again come and you want to run the same program. Would you like to retype it again? You can do that if it is a three line program, five line program. You would not do it with 400 line program. So you would like some persistent storage available to the computer. So we can tell the machine, look, I have written a long program. I am entering it once. Keep it somewhere. Tomorrow I will come back again and ask you to run the same program. The provision exists in terms of a device which is called disk, which is also connected to the same bus. There are of course a whole lot of details which will not go into an extremely simplified architecture of the computer. And the point is, you do not see any one of this. You do not see this. You only see the terminal, where all of this happens inside. So in a nutshell, computer uses binary digits to represent information. We do not care one boot about binary digits. We would like to use decimal numbers as we are familiar with. We will only look at the binary representation of numerical values to the extent that it affects the correctness, accuracy, precision of the computations that will happen. Otherwise we will continue to deal with decimal numbers. Here are some equivalents of decimal and binary numbers. I think you can relate to them very easily. So you have 0, 1, 2, 4, 5, etc. As you keep writing, you know, 6, 7, 8, 9. The next value, what we call 10, is written by putting 0 here and 1 here. So when you reach the last symbol of a system, the next value will be 0 and 1 added on the previous side. Then you will start writing 11, 12, 13, 14, etc. When you reach 99, that is the end of the symbols for both the places. So you will put 0 here, 0 here and put 1 in the next place. That is 100th place. In exactly the same way, unfortunately in binary system, you exhaust the symbols. The moment you have written 2 values, 0 and 1, then there is nothing. So likewise, you go, the next number is written as 0 here, 1 in the next place. Then you go to 11, again end of symbols, 0, 0 and then 1, 1, 0, 1, 1, 1, 1, etc. There are of course simple mechanisms of converting binary to decimal, decimal to binary, etc. There are standard books you can refer to those who are interested. We are not going to bother with that except as I said, for those situations where the binary representation might impact the correctness of the computations that we do. Here are some interesting names. We shall be using them very frequently. 2 raise to 10 happens to be 1024 and 1000 has a nomenclature in human terms. We call it a kilo, like a kilogram is 1000 grams, kilo liter is 1000 liter. So kilo is a standard decimal term. But since 2 to the power 10 is very close to 1000, people in the computer world also refer to that as a kilo. So 2 to the power 10 is called a binary kilo if you want. Likewise, just as 10 raise to power 3 is a kilo, what is 10 raise to power 6? 1000, 1000, you have a English word for that. It is called a million. That million is called mega. These are Greek terms. So the closest equivalent is 2 to the power 20. So remember, just as there are words for powers of 10 by 3, 10 raise to 3, 10 raise to 6, 10 raise to 9, etc., there are similar words for 2 to the power 10, 2 to the power 20, 2 to the power 30, etc. And these are roughly kilo, mega, giga, tera, peta. Some of you are familiar with personal computers or those of you who have computers or who know more about it, would typically say, I have a 60 gigabyte desk. So what you mean is you have 60 giga of some units of information that can be stored in that desk. We shall see the notion of byte in a moment. But these are useful. We shall be in fact using them subsequently. Therefore, I thought I will just write them down for your information. Now, we come back to a little closer inspection of binary representation in so far as numerical values are concerned. The value that can range within a location will depend upon the number of bits that you have in that location. We already observed that. The smallest unit of number of bits of a location is called a byte. And the byte consists of 8 bits. 8 bits can store values from 0, 0, 0, 0, 0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1. In decimal numbers, this value is 0, this value is 255. What it means is I can store 256 distinct values in a byte. 256 distinct values in a byte. The smallest value can be 0, the largest value can be 255. Now, this is an obvious observation. One byte is too small. I mean, I will be doing scientific and engineering computations and I will require to represent very large numbers. Not only that, I will require to represent fractional numbers, negative numbers. The kind of mundane representation that I saw does not even permit me to store negative numbers. So, I will have to do something about it. What computers are capable of doing? So, we were discussing this that one byte is too small a unit. So, what the machine is capable of doing is actually it is capable of combining bytes like this. And the electronic circuitry has been designed to treat two consecutive bytes taken together as if it was one unit of information. Suddenly, you get more number of bits available. How many bits will you get with two bytes? 16 bits. How many will you get with 4 bytes? 32. How many will you get with 8 bytes? With 16 bytes? With etcetera, etcetera. Why do we talk of only 2, 4 and 8? Actually, as we shall see later, when we use higher level programming languages, it is possible for us to create abstractions which may even create a consecutive set of 23 bytes as one unit and we can do whatever we want to do with numbers which are represented in these 23 bytes. But that will be artificially done using higher level program. Intrinsically, the machine at the level of hardware is capable of handling numbers which are stored in either 1 byte or 2 bytes or in 4 bytes. And that is the reason why 2, 4 and 8 have specific implication. What it means is if I use numerical values in my programs which can fit into either 2 bytes or 4 bytes or 8 bytes, then I have native electronic instructions to handle those numbers, add, subtract, multiply. There is nothing artificial about it. That is the importance of this kind of configuration. So, consider internal representation of signed integers. Consider 4 consecutive bytes, 32 bits. These can together represent values between 0 and 2 to the power 32 minus 1. Agreed? That is the maximum value and this is the minimum value. But I want to represent positive negative numbers. So, intrinsically the circuits have been designed to permit handling of numbers where the first bit is not treated as part of the number. The first bit can be 0 or 1 and that is intelligently used to represent positive number or negative number. 0 means plus, 1 means minus. This is called signed representation and the electronic circuits are capable of distinguishing between signed representation and unsigned representation. Consequently, the range of values which can be represented will reduce by how much? Here are 31 bits. And here is a 0 or 1 sign. What is the largest value that you can represent by 31 bits? Largest value is 2 to the power 31 minus 1, all once. The largest numerical value, positive or negative, that can be represented now will be plus this much and minus this much. There cannot be any value lower than this. That is why the range becomes plus 2 to the power 31 minus 1 to minus 2 to the power 31 minus. There is a dichotomy here. The total number of values that we can represent this way appear to be 1 less than the actual possibility. Why does that happen? If I have 0s, all 0s is actually value 0. But I have a plus 0 and a minus 0 also. Actually, there is no distinction between the two. But because of the stupidity of my representation where 1 bit is reserved for sign, the capability of distinguishing between the two is lost because plus 0 and minus 0, we do not want to distinguish in any computational way. Consequently, people have designed a different way of representation which is called two's complement representation. We will not go into those details. Suffice it to say that two's complement takes care of this double representation of 0 in some way. It is a complicated way. Sorry, your question, please. So in some manner, it takes care of that dichotomy of plus 0, minus 0 and restores to us that extra value that can now be represented. Consequently, whenever two's complement notation is used and that is exactly what is used by the electronic circuits which are inside the computer for handling integer values, signed integer will generally mean this with a two's complement representation. And therefore, the value will be plus 2 to the power 31 minus 1. That is the largest value. But the smallest value will be minus 2 to the power 31. So, we do not go into the details of what jinx they do there. Those of you who are interested can read it. We are not going to bother with it ever again. Consequently, with this kind of two's complement notation, we revise our estimate of the range of values that we can represent. Four bytes give us this range. Two bytes will give us this range. And one byte will give us a range from minus 128 to plus 127. A signed integer of one byte would have given us minus 127 to plus 127 with plus 0, minus 0. But this is what we will get. Of course, if I say represent unsigned integer, I will not get any negative numbers but I will get 0 to the maximum value. Sorry. No. We had in the previous case plus 0 and minus 0. What I am saying is we are not going into the details of how. But there is a complicated mechanism called the two's complement representation. We are not looking at it. That two's complement representation represents every number uniquely including there is no plus 0, minus 0. There is only one 0 there. That representation is different. We are not discussing that. However, when that extra value which was lost earlier is restored, I will get the complete range of values from minus to the power 31 to 2 to the power 31, minus 1. How it does? We are not discussing. We are not bothered. We will just note these. Even this is not relevant. You see minus to the power 31 and minus to the power 31, minus 1. There is hardly much difference. As far as we are concerned, in fact what we should note is if I have a one byte location, it can contain very small numbers. If I have two byte location, it can contain relatively larger numbers. We will take it as approximately 32,000. And if I have four byte locations, it can contain still larger numbers. If I have eight byte locations, it can contain still larger numbers. That is good enough for us. So, circuits are designed to interpret and process different types of values. Curiously, these types of values include fractional values or large and small values of the kind that we saw. Remember, exponential notation 1.2e minus 10, etcetera. Those values can be represented. So, there are circuits which are called floating point circuits. We will see why they are called floating point separately. More importantly, there are circuits which will treat groups of bits not as representing a numerical value, but as representing a symbol a, b, question mark. These are all symbols that we use. So, these symbols are also represented inside the machine. And the machine circuitry is capable of interpreting a number as a symbol. Since that is relevant for us, we will look at this symbolic representation of information. Symbols are typically represented using one byte location. One byte can give us values between 0 to 255. That means 256 distinct symbols I can actually represent. So, there is a standard coding structure. One value and this symbol, one value and this symbol. The code that is used most commonly is called ASCII code. The word ASCII stands for American Standard Code for Information Interchange. You need not worry about those details. The Americans defined it first. So, that is okay. It is called ASCII code. But what ASCII code does it? It writes values from 0, 1, 2, 3, 4, 5, 6, 7, 8 up to 255. And it says this is the symbol reprint. So, actually now you will realize those of you have worked with computers. When you type on the keyboard and you see a letter T, let's say. What goes inside will be the equivalent bits reprinting the value of that symbol T. Similarly, whenever we say that computer is capable of converting your internal binary numbers into a decimal system and give it to you. What it is doing actually is not only converting to the base 10, but it is also converting individual numbers into symbols. Digit symbol 1, 5, 7, plus, dot. All of these are actually symbols. So, here are some symbols that I have noted. You might want to note down because the next page has some simple exercises. You might have to note down what is the value of this m, for example. What is the value of small n? 109 and 110. Does this tell you something more about what will be the number representing o and p? Small o and small p, yes? 111. So, you see you can guess. All alphabets a, b, c, d, f, g, h have been arranged in that table in a sequential law. Consequently, the value of p is greater than value of o. We shall see this significance later when we write programs to handle non-numerical information. Your names, for example. I want to arrange all the names in alphabetical order. Then I will have to compare the first character of one name with the first character of another name. And depending upon whether it is smaller or larger, I will take a decision on what comes first. This comparison will not be possible unless numerically the values are arranged in that order. There are some additional symbols like the plus symbol is reprinted by 43, equal to symbol is reprinted by 61. What is 32? sp is a blank. So, you see you are typing, I am typing my name, Deepak Fartar. I want to give a blank in between. Now, what appears to me to be a blank is actually a symbol and it has a numerical value which happens to be 32. Here are some simple examples. So, capital M plus small m. If I write this in my text, internally it will mean a sequence 77, 43, 109. Why? Because 77 is the value reprinting capital M, 43 is the value reprinting symbol plus and 109 is the value reprinting M. What is this sequence 109, 32, 43, 32, 77? Well, 109 is small m. 32 is blank space. So, there is nothing here blank space. Then 43 is plus. Then there is another blank space and 77 happens to be capital M. This has a small significance which I would like to explicitly mention. In terms of writing a computer program and we have seen a program written for Dumbo. We have seen a program written for C plus plus. I hope you will agree that logically and semantically there is no difference between capital M plus M and small m blank plus blank capital M. Logically, there is no difference. Both reprint the same adding two values, one reprinted by M, one reprinted by small. However, syntactically these two are completely different sequences of symbols. They may mean same thing. So, please remember that whenever we write our program in the text or whenever we give numerical values, there is somebody sitting inside the machine which is looking at each symbol as it comes and trying to interpret what value you have in mind. So, one small mistake somewhere you will have an issue there. What would this mean? I will leave it to you to work out. I will just give you a hint. Suppose, I write how many symbols are there? One k equal to five semicolon, four symbols in first line, four symbols in second line. You would think that there are eight symbols. That is not correct. What you think appearing on the next line does not appear automatically on the next line. Inside the computer, you only store a sequence of symbols. There is nothing like next line. There is nothing automatic about it. So, for next line, there is a symbol and that symbol has the value 10. So, every time you write a program on the screen and press carriage return on the keyboard and things go to the next line, actually a value 10 is inserted in that symbol. Internally, the machine maintains only a series of sequence of symbols. It is nothing like new line, new page, whatever. That is all you are in my notion. No, no. 10 is the value. You do not understand. 10 is not a set of two symbols that we are writing. 10 is the internal value stored in a byte to represent a symbol. One byte symbol, one byte can represent values between 0 to 255. Each one of these is a single value which it is not t equal to 10. These are different values. Each value represents one symbol. The value 10 represents a symbol which corresponds to new line. Just as value 109 represents a symbol m. That way you can say 109 is also three symbols. But what is written here are not symbols. These are decimal values from the previous table. Each decimal value represents one symbol. So, I am just writing those decimal values for illustration. That is all. I do not think you have followed that. Some confusion. k is equal to 5 is a program that I have written. These are symbols. Oh, sorry, sorry. You are saying this 10. I was confused with this and you are very right. So, let me correct it. I am sorry for the mistake. So, these are actually 1, 2, 3, 4, 5 symbols. You are right. Sorry, he pointed out correctly. These two lines, there are nine symbols. One and zero are two different symbols and this is not a single value. They are absolutely right. So, one will be represented by a value for symbol one. Zero will be represented by a value for symbol zero. Then a semicolon and then possibly a new line character. That is correct. Sorry. Let us put it this way. I will explain the gist but not the details because details are not important. The gist is as follows. Every symbol that we use in our writing on piece of paper or typing on the keyboard is internally represented by a numerical value. There is a table of values which associate symbols with those values. This is the table, representative entries from that table. There is an ASCII code table that you can find anyway. What I was trying to show in the next page was just an illustration that if I have written this as a text on my paper, capital M plus small m then internally what will it mean? Internally it will mean sequence of three distinct values. One representing the value of capital M symbol, another representing the value of plus symbol and the third representing the value of small m symbol. So, these three symbols will correspond to these three values. And the question I was raising is these five values will correspond to what? So, there is an additional symbol represented by value 32 which happens to be a blank space. That is why you see a blank space. So, that is all. All that I meant was that if I have different symbols in my text they will all be represented by a series of values including the new line which is a separate symbol internally. Although it is not visible to us. So, we get back to our programming. Now, we use only decimal numbers and normal text symbols. We presume that C plus plus compiler, we do not know yet what the compiler is is capable of generating appropriate values. We will leave it there. Fractions and floating point representations, we had discussed this earlier. We will write these as fractional numbers. The equivalent of scientific notation used is some fraction followed by letter E followed by some number. And these are two components, mantis and exponent. So, actually space is allocated for both these components inside consecutive bytes. So, for example, I have a large location. It may have two bytes, four bytes, eight bytes. I do not care right now. But few of the bits will be reserved for storing mantis and few of the bytes will be reserved for storing exponent. I will also tell you why it is called floating point. Take this number. This number can be written in which way? It can be written as 8, 3, 2, minus 5. Provided I assume that the decimal point is here. Let us say I assume that the decimal point is always here. That means I do not have to store decimal point explicitly anywhere. But I can still write the same number as 0, 0, 8, 3, 2, minus 3. Suppose my decimal point is always at this corner, then this number becomes mantissa is 0.00832. Then this will have to be multiplied only by 10 to the power minus 3 to get that number. So depending upon how I write the mantissa, the meaning of the number will change. Suppose I wrote this as 83.2. It will mean multiplied by 10 to the power minus 7. The fact is that in decimal number system, I can write my mantissa and exponent differently depending upon where I place my decimal point. That is the reason why that representation is called floating point. The same value gets represented in different ways depending upon where the point floats. A digital computer cannot afford this kind of luxury. So although this representation is called a floating point representation internally, what the computer does is it always fixes the point at the beginning of the portion of bits allocated to mantissa. And it always ensures that the first digit that starts is non-zero. So irrespective of the way you write your numbers in the text, internally the number will be converted such that the leading digit of mantissa will be non-zero always. The point will be presumed to be at the beginning of that point and the exponent will be adjusted appropriately to represent the correct value. But that term floating point has unfortunately stuck with the machine. I don't think we have ever used floating point representation for such thing. We just call it scientific notation. That's about it. So we will now look at a computer program which will find the cost of painting tanks. This is a simple problem. There is a petroleum company. It has oil tanks. For simplicity we have assumed that all tanks are exactly of the same dimension. They are all cylindrical tanks. Now every two years or three years because they are out in the open, in the rains and winds and whatever, they have to be painted. Somebody in charge of those oil tanks wants to find out how much will it cost to paint those tanks. The painting cost is always specified in terms of the area to be painted because that's the amount of work that I have to do. So let's say per square meter, per square foot, whatever. That's the rate at which I am prepared to paint. Given that they are cylindrical, I wish to calculate the total cost that I have. So what is given to me as input is the dimension of the tank. Dimensions are written here. The relevant dimensions for calculating area is height of the cylinder and the radius of the circular portion. Okay. For a given price of painting per square meter, find the cost. That's the problem. Invariably this problem people like you will solve in a jiffy because in your mind you already formulated what needs to be done. But when you write a computer program, there is a process by which you arrive at the program. You just don't start writing computer program the way you start solving simple problem. And this method is as follows. The first step is you analyze the problem. Now analysis of course is in terms of the computations that you need to do here. So these computations you will do problem analysis first. You will say I have a cylinder. How many cylinders? But all are same similar. So I will have three, one cylinder. Now this cylinder has a height h and this cylinder, the circular part has a radius r. I now say that the area to be painted will consist of the entire cylindrical portion. The area of the cylindrical portion is the area of the outer surface. Now there are in any cylinder there are two circular tops. But since this whole thing is sitting on the ground, there is nothing to be painted below. So only the top circular surface will have to be painted. I will have to add its area. The two areas are simply 2 pi r h and pi r square. You agree with that? This is absolutely simple formulation. Now if there are n tanks, then the total area to be painted will be how much? n into 2 pi r h plus pi r square. So this is the total area to be painted. If I multiply this by the rate of painting, I will get the cost. Simple computation, but I need to write a program for this. Writing a program, I know that I will have some values given as input. Some values I will have to do computations and there could be some values that will be part of the computations. Although they are not given to me as input, they are known as part of problem specification or as part of my analysis. For example, in my calculations, the symbol pi appears. Pi is not a variable value. Pi is a constant. It is not given to me by anybody. In my engineering or science knowledge, I have gathered that I will have to deploy pi. But I will have to use that as a numerical value and therefore I might want to keep the value of pi in a location for use during my computations. I will now design my algorithm and these are the typical steps when I design the algorithm. So I will identify the computational objects first. Values which will be given as input, radius. I have to choose a name to represent radius. I choose r. Value for height. I choose h. Value for number of tanks. I choose n tanks. I could have chosen any name. In fact, we will discuss what the different nomenclature is and so on. But I could actually have different names chosen. I could choose any one of the different possible names. Price for printing. I use the word PRIC to represent price. Other values needed, I need a value of pi. Since I do not have that complicated Greek symbol available to me, I will use a simple name PR for pi. And finally, using all the analysis that I have done, I have to do some computations which will result in a value. That value is going to be cost of printing. There is a spelling mistake here. So the cost of printing, I denote it by price. What is my algorithm? Algorithm is very simple. First, read the input values. Then calculate the cost using the formula price multiplied by n into 2 pi h plus pi r square. And then output the value of the cost. Simple. This is the program which will calculate the cost of printing. We have gone through similar C plus plus programs. While you take it down, I will let me first explain the various lines once again. The first line is a command. All of you remember commands? They are not meant for C plus plus, they are meant for us. The first line command tells us that some name for the program written for CS101 in August 2008. The next two lines are specification lines which we take as standard specification for any C plus plus program. Hash symbol include less than I O stream greater than. So that is a line that we will write permanently. The next line is actually a declarative instruction for C plus plus compiler. It is not part of our algorithm. It says using namespace std. See using some standard namespace. The third line says in main opening bracket, closing bracket and opening brass. We discussed this earlier and we said this seems to be a mandatory line which indicates beginning of my program. So I have to write it there. We shall later on see what it means. But beyond these lines, now everything should make sense to you. Float RH pi equal to 3.14159 comma price semicolon. This is one specification statement. Int n tanks semicolon float cost. So you see I can use these declarative statements as many times as I want in my program. In a single declarative statement, I can declare as many names as I want. So actually I forgot to declare cost in the first time. So I wrote a separate statement. Statements are separated by semicolons. There is an additional thing that we are seeing here. Not only the name pi is being declared here asking the C plus plus to reserve a floating point location for it. But it is also being initialized with a value so that I do not have to give that value as an input. Or I do not have to create a separate assignment statement during program execution. Such initializations are permitted in C plus plus. The subsequent statements are series of C out and C in statements. I hope you recall that the C out statement of the first kind will give me a message. Give the radius and height of cylinder. And the next statement C in greater greater R greater greater H is equivalent to input R and input H. So two values will have to be given at that point in time when the program starts execution. The next line says give number of tanks and again I have an input statement which takes n tanks as input. Then the next line says give me price per square meter for printing and I input the price. And in a single computational statement, I put all the computations that are required. Please verify whether the right hand side of the assignment statement that is shown here correctly represents what I want to do. Price multiplied by n tanks multiplied by 2 into pi into R into H plus pi into R into R which is pi R square. Looks like everything is correct. Finally we output the cost of printing as a message followed by cost which is the name of the location which contains the value that has been computed. Return 0 again we do not understand but we have by now realized that at the end of my algorithm I must say return 0. So just as int main signifies beginning of my algorithm return 0 or more importantly the closing brass signifies the end of my algorithm. We have still not understood what are the exact legal requirements of specifying int float are there any other types? What are the restrictions on the names that I can use? What are the restrictions on the values that I can use? We have yet to learn that. But this is the initial exposure which is adequate for you that when you see a C++ program you will be able to sort of figure out what the hell is happening. If the program implements simple algorithm. Is that alright? Okay. I had actually planned to do a whole lot of discussions on the representation of values, the rules for forming expressions, the rules for expression computations and so on. But I will discuss that in the first lecture next week. The first lab that you will be doing will be a simple lab involving execution of simple programs, editing of simple programs. So as long as you understand these things, the basics through this exposure is good enough. However, I will put all these slides on the model. I am also writing a detailed backup note because I do not use any textbook. Although there is a book prescribed by an author called Kohun. So Kohun's book is a prescribed book. You can read from Kohun's book or for that matter you can read from any C++ book. But whatever I am including in these slides here, I will just show you as a fast forward screen. How are names formed? What is there in a name? How do you decide names? Various objects in C++, types of values. Notice care, inflow, double, void, bool, wcar, underscore t. All is confusing. I have listed them here. We will not be discussing these in details even next week, but we will be discussing some of the details which pertain to handling of numerical values, declaration of various names. How do you handle integer values? How do you handle floating point values? What are the floating point objects? What are the character objects? What is an assignment operation? How expressions are evaluated? The expression evaluation rules, very rigorous rules. Operands and objects, if they are of different types, what happens? What happens if you add one integer value to a floating point value? How exactly does C++ handle it? All those rules are there. The notion of type conversion. The notion of parenthesis, all of you are familiar with it. So, parenthesis will override any priority that you might have to any operation. But even all with this, how do you write an expression for this complicated mathematical formulation that is written at the bottom of this slide? 1 upon x plus 1 upon x plus 1. How do you write it correctly? So, this is something that you need to practice. None of these are complicated things. Those of you are interested can read the detailed notes which I will circulate in tomorrow's lectures or read any other book that you wish. However, we will be discussing these specifically in the next week along with other things. So, let me quickly conclude this because I have a written quiz that you have to finish and give it to me right now. This is not a quiz. This is a survey actually trying to collect information about you so that we can organize ourselves better. But this is how this year's 101 will run. There will be two lecture sessions and two live hours. Additionally, I would expect each one of you to work for three to four hours extra per week. Reading something, problem solving, practicing, discussing with someone, doing some home assignments or preparing reports or diving, whatever it is required. This is the standard in IIT. Any course which has so many hours, which are prescribed, contact hours, you roughly have so many hours of extra hours. That is how the whole timetable is designed so that you have that much of available time. There will be a course homepage that homepage is accessible from anywhere in the world. There is a course Moodle. All of you have registered for the Moodle. All of you know how to login to the Moodle. But I saw most of you have accessed Moodle. How was that possible? You registered for Moodle perhaps. Sorry? That's all. So that tells me that the first lab I should handle such that you should be able to look at the Moodle in greater details. We'll do that. And point is there will be very few physical handouts that ever will be given. And there will be very few physical submissions that will be collected. Most of your submissions will be on the Moodle. And most of my distribution will also be on the Moodle. Barring the first few weeks and a few occasions later where I'll be circulating hard copies. So otherwise we will not be dealing with paper. We'll be dealing with digital information either way. This is something that would interest you most because that's the rat race from which you have come, right? Marks, grades. So this is the distribution of marks. The total evaluation will be for 100 marks. We'll have lab assignments amounting to 10 marks. We'll have quizzes amounting to 15 marks. We'll have a mid-sem examination amounting to 20 marks. We'll have a course project where a team of students will work on that project together. That's a major component of the course where you will actually learn to write large programs. That will have 25 marks. A novel aspect of my course is out of these 25 marks, there are 15 marks for the project which the entire group gets. So five of you do a project and suppose that entire project is evaluated to be equivalent to 11 out of 15 marks. Each one of the five people will get 11 marks. The remaining 10 marks are to be assigned on the individual contribution. Out of these 10 marks, five will be decided by a Viva process and five will be decided by you yourself. Based on your own judgment, how much you have worked, relative to the other people in your team, except that you are not free to say, I have worked maximally so five out of five. Your marks will have to be vetted by the other team members and that is called a peer review process. So you'll have to convince your colleagues in the team that look, I have really worked more. Usually I have found that it is easier to convince a teacher during a small Viva interaction or how great I am. But it is not very easy to convince my own colleagues who are also equally great. So that's a good experience. I've been doing this for last two times. We'll be stopping here. Of course, I have another slide. I don't think there is a need to show that, but I might as well. The course will run, by the way, in absolutely free, fearless fashion. We'll have extra discussion sessions, extra lab sessions that I will explain tomorrow. You need not at all worry for approaching either me or anyone of my tears. If you have any problem whatsoever, if you want to make an observation about something that is not going well in the course, you're most welcome to come. Give me gullies if you want. I will take them without any bias on yourself. However, using any unfair means will mean an immediate fail grade in the course. This is something that at least I don't tolerate. The IIT Bombay does not tolerate. They're all smart kids, but I'll tell you what happens. When you're giving an exam and when there are marks, there are temptations. So particularly if my neighbor's notebook is very easily visible and I'm not able to get an answer quickly, it is not unnatural to be tempted to see what that neighbor is writing. That temptation has to be avoided at all costs. Any kind of copying anywhere in a home assignment, in a lab assignment, even if it is a half mark assignment, even if it is a zero mark assignment. So the assignment has no marks, but you have been asked to submit it. You're not supposed to copy unless you're told that this is a common assignment which you have to discuss and submit. Is that very clear? Except that everything else is okay here.