 Good morning everybody. So in today's lecture we will be discussing the course organization for CS101. So look at the model of computing for a program. We will have a caricature called Dumbo and we will try to emulate the characteristics as exhibited by our C++ compiler in the form of Dumbo. We will see exactly how Dumbo's memory is organized. We will see how Dumbo interacts with us and how Dumbo computes. And finally we will see some sample C++ programs. So this course, again all of you I have mentioned some things briefly, is a course on computer programming emphasizing problem solving. We may incidentally use some programming languages. We shall be using C and C++. Because we shall be using C, C++ combinations sort of thing. Let me clarify that later on we will understand that amongst the three major paradigms of programming, namely the procedural programming, object-oriented programming and functional programming, these two languages C and C++ represent two paradigms. The procedural programming is represented by C and the object-oriented programming is represented by C++. Conceptually there are a lot many differences between the two. However, since C++ has evolved from C, there are a lot of similarities in syntax and grammar. Now in the first course it is our opinion that we should not be burdened with object-oriented concepts unless some simple procedural programming is understood. And therefore we shall be using a combination. We shall be using C++ compiler to compile our programs. We will be using some simple constructs of C++ in the early part of the course. And subsequently after the mid-sem we will discuss some object-oriented concepts. But as a consequence of this strategy, there is not a single textbook which is directly relevant for the course. Now that is a pain. We will try to compensate for it by giving you access to a whole lot of online resources plus a whole lot of problems that we will have compiled and which will make it accessible, make those accessible. We will always discuss a problem first and any program will be discussed only in the context of that problem. If we discuss segments of programs, we will discuss those segments in the context of a full program. Lastly, lab assignments will generally have readymade programs because it is stupid to expect people, even the best typists or the fastest typists, to type, let's say, 500 lines of code in two-hours lab. The 500 lines of code, if at all is required, would be made available as a structure and you would be required to apply your mind to understand it and to make modifications to that program to meet the specific requirements of functionality which would be given in the assignments. There will be a course project. Students will be forming teams to do this project. I shall describe these projects in a short while. The course has two lecture sessions and two lab hours per week. Lecture sessions, as you know, are one-and-a-half hours each. We typically use one hour, one hour, ten minutes for the lecture and remaining half an hour for problem solving or discussions. We can treat that as a sort of semi-tutorial hour. Each of you will be required to work at least four additional hours per week for the course. This could include general reading. This could include problem solving, programming practice, home assignments. Some of the home assignments will specifically require you to apply your mind individually, in which case you are not supposed to discuss that home assignment with anybody and submit the assignment yourself. Some assignments will expect you to do discuss things with your friends and colleagues. So discussions with other students and teaching assistants is a required part of the work that you will do additionally. And, of course, preparing reports or diaries as required, mostly during the project phase, which will happen after the mid-sem. There will be a course homepage. The course homepage URL is given here, http colon www.cse.itb.ac.in. Don't have to write it. All these rights printed will be available to you. You can take them. Currently, this is a muddled interface, but it will be active from Monday onwards. I will try to make it active as early as possible, maybe Sunday. All relevant information will be posted on this page, because I am not still comfortable with Moodle. The issued Moodle still does not reflect all of you having registered for the course. So I have a problem there. All of you have to score marks and I have to award you grades at the end. So the evaluation pattern for this course is as follows. There will be lab assignments which will carry 10 marks or 10 percent weightage. Absolute marks are irrelevant, whatever be the absolute marks for any one particular activity. Total of that activity will be reduced to this much percentage in 100 percent. There will be quizzes, which will get you 5 marks. There are quiz timings declared in the Institute timetable, but as I told you, we will not be using those quiz timetables. We will instead be conducting quizzes online. Each one of you will be given a device which we have designed and developed called a clicker device, and you will be answering questions directly using those. We will be receiving all your answers. There will be a mid-semester examination of two hours duration. All my examinations are open notes examinations, but no books are permitted. Your handwritten notes or any print out that has been supplied to you as part of the course, including sample programs that are given in the labs, et cetera, et cetera, are permitted to be carried with you. There is a course project of 30 marks. Notice a large part of the evaluation is on the project. This is what will tell you how to work in groups to solve really large problems. As I mentioned, programming is no more an individual effort, particularly when you are trying to solve complex problems of real life. So you must learn to solve problems together. Typically, about 20 students will form a group, a project group, and those 20 students will be divided into five teams of four students each. So each team will have a sort of team leader. The group will have a group coordinator, and all of you will work on a specific project. We will give you options which you can select from. Out of these 30 marks, 15 marks are reserved for the actual project work that you carried out and the report that you produced. Qualitatively and quantitatively, it will be evaluated. 15 marks are to be... So these first 15 marks will be common to all students of that group. There is a 20 student group. Everybody in that group gets same marks out of 50. So if you have done a lot of work, if the group gets 10 marks, you still get 10 out of 15. If I have done no work, I still get 10 out of you. However, the remaining 15 marks are reserved for self-evaluation. So each one of you will evaluate, both quantitatively and qualitatively, how much work you have done. This is a longer period, so there will be two stages. However, a person like me who has not worked at all would be tempted to give 15 on 50, okay, naturally. Because in my opinion, I have worked a lot, two minutes in the entire semester, whatever. But this will have to be peer reviewed. So all 20 people in the group must agree that I have worked. If they don't agree, then whatever is the conscientious will be the marks awarded to. I've been using this in my postgraduate courses for the first time in CS 101 last year. I used it and statistically, it was an excellent idea. It was proven because some students got even zero marks. And how did they get zero marks? Or how were people so careful in giving marks? That is because of the traditional caveat, which is as follows. For any group of 20 students, whatever marks are given by you after peer review will ordinarily be accepted. However, I reserve the right to take out any two students as sample from every group and evaluate them rigorously. Each student will be submitting diaries, progress, and the work done, etc. Suppose these two students have been given marks, respectively, 8 and 5 out of 15. And I determine that they should not be given more than zero marks. Then every student's individual marks in that group will be reduced by 8 marks. Is this understood? No. So, suppose out of 15 marks for self-evaluation in a group, the group with peer review has decided that these 20 students get marks out of 15 as somebody 15, somebody 10, somebody 11, somebody 12, somebody 8, etc., etc. I pick out two sample students from that and I do a rigorous evaluation of those two students based on what work they have actually done. If I determine that those two students do not deserve the marks that the group has given them, self-evaluation followed by peer review, then whatever marks are reduced for those two, the same amount of marks will be reduced for every student of that group. When you get an authority to self-evaluate simultaneously, you must assume responsibility and accountability. This works beautifully. It has never failed. In exactly two occasions, I was required to reduce marks in my post-graduate course two years ago. Last year in CS 101, I did not have to reduce marks at all. But it only means that you have to be extremely careful. In fact, last year, I had a very funny problem where one of the students was given zero by the peer evaluation, came to me along with his coordinator of the group and said, Sir, I have been wrongly given zero. And in front of me, both were arguing. The coordinator said, but you didn't do anything at all. And then his argument was that the other fellow also did very little work. You have given him three marks. So these are the kind of arguments. But I think it is important that all of you should learn to evaluate yourselves and do it very professionally and properly. It is fun actually. Based on the total score of 100, grades will be given. Of course, I would expect a minimum score of 40 to get a passing grade. Last year, I was fortunate enough. Nobody failed in my course. I hope my fortune continues. There were only a few AP grades. So I have not prescribed it. But generally, I would expect a score of 95 plus out of 100 to deserve an AP grade. Last year, last time we had this discussion. Somebody mentioned minus two could be the marks because somebody copied. So I have been, I am making it explicit. Everything else is permitted. Any kind of altercations, arguments with me, any help that you want will be given. What will not be tolerated is unfair means. I am, I pathologically detest unfair means personally. So this course will not permit that. So there may be occasions when you may be tempted to take a shortcut. Please don't do that. Any such unfortunate incident will result in an immediate amount of fail grade. No arguments. I was asked one question. I don't know why nobody is asking. Suppose, because if I catch copying, for example, there will be two copies, which will be identical. If I give fail grade to both, one of them may be wrong fail grade, right? I will give fail grade to both because it is impossible that my assignment which I have worked has been copied verbatim by someone without my active collaboration. In any case, I will call both the students and believe me, in five minutes I can find out who is the original author of that assignment and who is the copy. So the judgment will be fair, but this is the consequence. So kindly avoid such incidences at all. I would suggest that you should avoid such incidences anywhere else because being ethical is a good practice for all human beings, but it's up to you. You are all grown-up people now. In this course, however, don't take pangas. The lab sessions, the lab slot for two-year MSc students will be Saturday from 8.30 to 10.30 hours in the morning. For all other students, since the students are divided into four divisions and D1 and D3 are registered for CS 101, all of these divisions have been further subdivided by the institute into batches. Is that right that you are divided into five practical batches? Tutorial, five, right? Basically you are D11, D12, D13 and D31, D32, D33 etc. T1 to T5, but each division is divided into five. Well, I call it D11 to indicate first tutorial batch order. Now these batches are being combined so as to evenly distribute students and the combination which will work in the five lab slots on the weekdays, the labs will start from Monday and the timing is 8.30 to 10.30 in the night. It would be advisable at least while going back from the lab to your hostels that you go in groups because occasionally there are funny enemas crawling around in the campus. So far nobody has harmed a human being but be careful. So this is the composition. D11 and D35, D12 and D34, D13 and D33, these are your dates. All that you need to remember is the dates. The lab starts from Monday. Again this slide will be available in the matter of printout. You can just note your day. It did not bother about. I will digress a bit and show you a small movie which my colleagues have made. The lab is in the maths department building. So ground floor of the maths department building, there is a long corridor. You are required to keep your umbrellas in baskets which have been specially provided for that. It is actually a long shooting. The basket should be outside, not inside. So don't take any umbrellas inside. For those of you who have not seen the machine, this is a monitor. This is a CD drive. You won't ever require that. This is a keyboard. There is a mouse here. This is the entire personal computer which is connected to some back end server. This is the lab environment where you will be working. About 108 people can sit in the lab. So the only day when it will be crowded will be Saturday. The operating system that you will be using on your front end will be called Ubuntu. Yesterday, the last lecture I showed you some screenshots. So this is what you will see when you log in. So you type your username followed by password, press return and when you log in, you will get this kind of screen. You can start in accessories or terminal. So you get this command terminal. At the dollar prompt, you can type command. So for example, he is going for editing a file. So when he says g edit, he opens a edit window. Now look at a program that he is writing. He is typing that program. He is writing a program in a programming language called C and that is why he is using the pure C syntax. We will not be using that. So instead of include stdio.h, we will have some other funny statement which we shall see in a short while in the lecture. This is the traditional first program ever written by the beginners of C programming. Hello world. You greet the world. This is a greeting saying we are all with you. Notice the funny symbol backslash n. We shall have occasion to discuss that later in the class. So as finished this program, he is now saving it, giving it a file name called helloworld.c. Once he saves it, he can exit the edit window. When he exits the edit window, he goes back to his terminal and there he will give a command to compile this program. He uses gcc helloworld.c. We shall be using c++ helloworld.cpp. Then he gives a command called ls which lists all the file. Notice a file called a.ow which is an executable machine language version. When he executes that, he sees helloworld there. So this is how you will actually be editing programs and running them. Next we will be browsing internet. Most of you would be familiar with this but we will be using this particular browser, the Firefox browser. This is the home page. As I told you, currently the home page is all wishy-washy. This will be corrected and released on Monday so you will be able to see the complete course organization, links to various resources and so on. This is last year's thing by this. So don't go by this. In the film, the only access that the student had when he was typing was to a last year page. So the contents are meaningless. This is just to show you how exactly people would typically work in the lab. Finally there is a course Moodle. So you go to the course Moodle. This is the Moodle address. You will have to use your LDAP login ID and when you login you will go to the Moodle. Now this student is going to a course CS101. You can see this is all, the contents are not very relevant. You will be seeing the contents which are relevant to you when you login on to the Moodle. I will be providing a link for this film as well as other animations on the home page. Those of you are interested can go through that again. So you can for example search for a course by theme and if that course exists they will possibly go to that course. There are a variety of things on the Moodle by the way. An extensive learning management system which IIT Bombay uses for all the courses. So that's about it and while going back don't forget to collect back your umbrella and go. But collect back only your umbrella please. So this was the lab. The lab is conducted in the old software lab. It's called OASL. Earlier it was called software lab. Now it is called old software lab because another one has been constructed in the neighboring CS department building. This one is located on the mass department. So this is one request. Please maintain silence, discipline and decorum because there is a lot of crowd there. There will be roughly five teaching assistants supervised by one senior M. Tech student available and accessible to you and eventually after a couple of weeks once you form these groups and teams we will be allocating one teaching assistant to a group of about 18 to 20 students. Detailed instructions for every lab will be issued. These will be accessible from the course home page. Well, I have shown the film beforehand so that's okay. We now come to a model of computing as exhibited by a programming language. So for us the computer is as I said a dumb fellow. So we'll use a caricature. I had drawn this first but then some colleagues suggested this one looks better. The head is like a TV monitor or a computer monitor. So we'll be using this caricature now. So what are the characteristics in Dumbo? Dumbo cannot do anything on its own but can execute given instructions correctly and it is a most obedient server. It will do exactly what is stipulated. Can do arithmetic, can do logical comparisons, it can manipulate strings. In short, it can muddle around with values, do arithmetic operations or other operations which are permitted on values and will create a certain value. Since it can compute, so it's a computer. The problem with Dumbo is cannot remember anything in its head. So the Dumbo has no memory. Dumbo instead uses a cupboard or a chest of drawers as memory. These drawers have been named arbitrarily as A, B, C, D, E, F. Most of you can suspect that these names would be like what you call the variable names, but essentially a name is one which is chosen by a programmer given or assigned a memory location in which values are kept by Mr. Dumbo. Each drawer contains some value. A drawer could contain a number like 437. It could contain a name or a string. So the location B has 437, location F has run a day. If these are indeed the values inside these drawers. So what is important is each drawer can contain exactly one value, exactly one nothing more. How does the value get into a location? Only two ways. One, we as users give some value to Dumbo. Now that is typically called an input operation. The other possibility is we have asked Dumbo to do some computations. Dumbo does those calculations, finds out a certain value which Dumbo deposits in a designated location. So either we give a value as input or some computations are done and a value is calculated in store. Those are only two ways in which a value can get inside a memory location. There is no third way, period. There is of course a third possibility. We might not have given any value or while executing our program Dumbo might not have calculated anything, but before Dumbo started executing our program there was after all there were other programs which were executing on the computer and therefore there would be some values present in the memory locations of the computer. So such values will be called unknown or undefined values because these are not supplied by us. How do we exchange values with Dumbo? Technically there is a data bus inside a computer. It is a hardware element but we will in our caricature imagine that Dumbo has a cart in which it wheels around the values to and fro. So suppose a value 58 is given by us, Dumbo can cart it in and put it inside or if we want to get a value out Dumbo can look into the memory, copy a value, put it in the cart and give it to us. Since Dumbo does anything only if instructed, we will have to instruct it for example to collect a value from us. The instruction that we use for input operation is written as C in greater greater b. Some obvious questions why do we use greater greater? Why do we say C in? Why not any other phrase such as input read get or why not something like this? S C A N F opening bracket double quote percent D closing bracket comma and B closing bracket semicolon. Funny right? C in greater greater b simpler than this. One of the reasons why we use C plus plus is to use extremely simplified and easily understandable input output operation facility which is available in the object libraries of C plus plus which is not available in the traditional C program. C programming input output is extremely difficult to comprehend initially. Later on we shall see the details but we shall be using this as to why we don't say read, why we don't say input etc etc etc is like asking why in a specific language certain thing is called by a certain name. That's a convention and since rest of the world agrees with that convention if I want to participate in conversation in that language I better learn that can be. So that's how we will treat it. Dumbo will collect a value given by us take it to its memory cupboard and we'll store it in location B and whatever was the existing value in that location will be overwritten. The fundamental aspect of any input output any input operation is whenever I ask Dumbo to get a value from me that value will be put inside the designated location but that putting inside the designated location will wipe out any existing value because the location can contain only one value at a time. Similarly Dumbo can output values from locations so Dumbo can give me let's say C out less less G exactly C out still means something as output C just as C in means something as input the less less and greater greater are called object oriented operators which operate upon what we call the byte streams which are connected to files all of that is very complicated it will not go into the details as far as we are concerned whenever we say C out less less G a location G will be looked at by Dumbo Dumbo will see what is the value there will copy a value on its card it will not remove the value so value will remain in that location a copy will be made and this value will be brought to us Dumbo is capable of outputting multiple values we can list all of these in a single instruction but each value must be preceded by a symbol less less so C out less less a less less G less less square less less root all of that is permanent all this means is that one two three four values are to be given to us notice again that the values in locations remain unchanged which is what is important a useful feature is that we can output a string like value of count is C why is this value of count as a string important otherwise we may just keep getting values in front of our terminal and we won't know in a large program which is creating a lot of output we won't know which value corresponds to what so it is useful to write a string like this for every output operation telling us what value the value pertains to what particular concept or meaning or what it is not necessary that you write only a string you can also write a constant value so you can say C out less less five then actual value five will come out any in fact any expression that gets evaluated to a value can be outputted by this we don't know what an expression is so we shall find out soon so let's try dumbo's input and output give value for b c in b so some value 437 give value for f c in f notice the use of this string since I have keyboard and a monitor to interact with dumbo on the monitor if a cursor is waiting for me to give a value I won't even know which value I have to give in input because I might have forgotten what I wrote in my program and in what sequence so it is useful for my program to contain instructions which says give value for f so this is output by dumbo it is shown to me and then I give a value which is let's say a string called run a day you'll go and sit into f if two numbers are stored in traverse a and b say 35 and 12 dumbo can add these and calculate the sum now this is the fundamental of computing we instruct dumbo by saying sum is equal to a plus b this is not an equation this is called an assignment operation basically we are telling dumbo that there are two values in a and b add them up and whatever is the resultant value please put that value in a location called sum naturally there must exist locations a b and sum a has 35 b has 12 what does somehow we don't know some may have anything some may even incidentally have the correct sum of these two numbers but that is incident so what some originally has has no consequence after this instruction is executed the sum will be calculated correct so dumbo uses some rough sheets or registers excesses the location a and copies the value into a register excesses location b copies the value into another register inside the register like a working table or working diary or working page it will add the two values and will store the result value back in the location sum the location now contain value 47 so these are the local registers like on a table he has copied these values found out 47 and finally 47 goes here into the sum how do we give instructions every machine generally takes one instruction at a time but dumbo is special as all of us know it dumbo has a capability to store a program which is nothing but a set of instructions so the collection of our instructions is called a program and dumbo has a stored program capability where does dumbo store the program dumbo has only one memory chest of drawers so what dumbo does is it allocates certain memory locations for itself where the instructions are stored we can connect it to the discussion that we had yesterday that a machine is capable of executing only machine instructions consequently it makes sense that when we say translate our program and then when we say load the program and execute it the instructions of our program in the native machine language of the computer are going somewhere inside the memory that set of memory locations will be called the instruction space where instructions are stored instructions are executed one by one each instruction may cause some data value to be manipulated so consequently there is a separate data space where data is allocated for the dumbo just to consolidate this I have two small animations one is an introduction to dumbo and the other is showing dumbo performing computations it's just one minute or half a minute each it's worthwhile to see that so this is our dumbo this is the memory cupboard or chest of drawers and dumbo can look inside copy a value put a value inside this is the way dumbo will put a value let's say there is a c in greater greater c so in location c dumbo wants to keep a value five this is how the dumbo is is going to put that value inside so this is the input operation after which the cart is driven away this is another one where dumbo is shown to add numbers just to show that how the caricature works internally inside the computer so there are three drivers a b and c c is going to be equal to a plus b so values are being put in a and b the location c is shown to have nothing it's a question mark we don't know what it is now dumbo picks up a value makes a copy of it and puts it in a working bench on a register then dumbo goes to the second location b takes out a value 12 which is a copied from that the b location continues to contain 12 this is put here now dumbo starts thinking adds 12 and 35 gets a value 7 and puts this value back in the location for c this might appear childish but it is useful to have this concept very clear that in an assignment operation a value which is computed by dumbo outside your memory locations is put back into a designated target location now we discussed some complete programs so this is a complete c program is actually a c plus plus program first line is a comment line add underscore to underscore numbers dot cpp you remember last lecture we discussed what is there in a name i could have called this program abrakad abrakad or cpp we would never have understood what exactly the program is trying to do without reading the program typically our programs will be stored in text files and generally it is expected by that looking at the file name itself i should generally be able to guess what is likely to be the activity of that program you will agree that when i say add two numbers dot cpp the meaning is abundantly clear as to what that program could be doing the program itself there is another comment which says the program reads two integer numbers and calculates the sum it says int man int a int b we don't understand what these things are we do understand that a and b must be two locations then we say c out give two numbers less less backslash n c in a greater greater b sum is equal to a plus b c out sum is less less sum less less backslash n some very funny looking symbolism in this but i think having seen our dumbo in action we can understand that this program is probably trying to take two values from us and is probably trying to compute the sum here another program which converts temperature from centigrade to degrees Fahrenheit again that title comment says convert c to f dot cpp there are two funny lines here also include i o stream we don't know what it is using namespace std we don't know what it is the next line appears to be a comment to convert temperatures from centigrade into Fahrenheit again we have int man a funny looking statement float c float f we had a funny thing called int in the last program we have a funny or thing called float in this room we don't expect our memory locations to be floating in air right so it must have some other meaning we shall see what it is the next instruction is familiar it is going to tell us to give us temperature and degree centigrade and c in greater greater c means some input value will be read and will be stored in the location for c and then there is a formula f is equal to c star 9 by 5 plus 32 this does look familiar to all of us right okay so hopefully the value of c which is temperature in degree Celsius a degree centigrade will be converted to Fahrenheit and then we are saying c out less less f familiar but less less double quote backslash n double quote funny thing we don't know what it is return zero i don't know why is dumbo returning zero to us but we'll figure that out later so this is another program you're seeing this program some of your familiar programming languages would perhaps have figured out everything here but even if you are not at all seen a computer program in your life i believe you can now figure out at least a few things that f and c represent some memory locations that input and output is being specified the value of f a value of c is being collected by dumbo as will be given by us that the formula does look sensible it appears to compute correctly the value of Fahrenheit degrees given the centigrade degrees and c out f guarantees that i'll get the value so calculated back i don't know the other funny things including backslash and at this stage which is perfectly all right so this is where we ponder and think we have discussed the programs add to numbers dot cbp and convert c to f dot cp we have noticed presence of several lines and we have no clue about what those lines mean why those lines are there however if we compile and execute the programs they will run proper well they seem to run properly stated here in the next week you will have access to the machines and in the lab all these programs will be made available you will have to download them from a link you'll have to compile them and run them to confirm for yourself that they do run correctly so as i mentioned when we have done some more programming we'll all learn the meaning of all these lines but for the time being we'll just identify these lines and take a note of the nuances that we have to face everybody's familiar the word nuance i thought everybody was then i asked five of my teaching assistants and two of them they are not aware of this word see everybody knows what a nuance is oh nuance is okay how do i explain it explaining it is a nuance something very difficult unnecessary unnecessary problem but i have to live with that problem that's called a nuance so like when i was young i would not be fed breakfast unless i have taken bath that was the rule in the family now i remember in some cold places like gwalior and we used to take bath with cold water in winter of gwalior you can imagine you are not particularly keen to take bath in early morning but when you are hungry so taking bath is a nuance well ordinarily it is not but i'm just trying to explain things which are required to be done which you don't really like and sometimes you don't understand why you are doing those things but you have to do them so it's a nuance okay so let's identify all such nuances in the in the program statement we'll look at a third problem a problem of evaluating a formula v is equal to n1 by n2 plus x simple looking formula we need to evaluate it for the following values of variables which occur on the right hand side which is n1 n2 and x so we want to evaluate this formula for n1 equal to 2 n2 equal to 5 and x equal to 3 we know that since values are specified i don't need any input statement i could actually put these values directly inside of the most program and use them so program need not have any input since all values are given so why we are doing such silly problem just to understand the nuances okay i will show you some of the thought processes that would occur to me if i was sitting amongst you and i did not have any exposure to programming in my life then what would i think i would think like this first of all my thoughts are i expect v to have a value 3.4 so i will calculate it myself okay n1 by n2 plus x is equal to 2 by 5 plus 3 2 by 5 is 0.4 plus 3 so 3.4 so i expect dumbo also to calculate it to 3.4 whenever i write a program then i am sitting amongst you mind you i am a student so my teacher gives me this program program to evaluate a formula include i o stream using namespace std slash slash evaluate underscore formula dot cpp slash slash calculating value of a formula again this funny thing int man int n1 n2 float xv n1 equal to 2 n2 equal to 5 x equal to 3 v is equal to x plus n1 by n2 see out value of v is less less v less less end l new animal earlier we had funny thing called backslash and now we have end there and then again the funnier thing returning zero i expect the program to return me the value of the formula so what is it happening i don't any so this is the program now again i imagine myself to be sitting amongst you with absolutely no exposure to programming except what has been discussed in the class in the last two days what would be my thoughts so these would be my thoughts i look at these two lines and say these lines do not make any sense perhaps they are asking the computer to include some pre-return instructions because the word include why would i include something else in my program i am writing my program but since something is being included and the meaning of that word is not clear what is being included and just guessing an intelligent guess that probably some other instructions are being indeed as we shall see later on that is the case some standard libraries which are available to our computing environment will get included whenever you such we use such include statements we don't understand why they are but we'll just follow this as a rule the next two lines now these appear to be commencement for human readers that is very obvious this can be an instruction to dumbo right this is this comment indeed in c plus plus whenever i write slash slash and write anything dumbo actually ignores that dumbo understands that these lines are meant for human readers not meant for me so these are called comments i look at the next slide seems to be something important but cannot understand the meaning perhaps it is the beginning of our main program why am i guessing that because the word main why should there be word main so perhaps it is my main program again that is indeed the case but as a student i don't know it yet i will use it blindly as a rule then look at the next few sentences int n1 n2 float xv okay what do i think now appears to define variables for the formula because n1 n2 x and v appear in my formula i don't understand the words int and float but since i know from my previous formula that n1 and n2 where integer values i guess that int probably means integer which indeed it does but then what does float mean now if means integer float could perhaps mean real numbers because ultimately the result that i will get is not an integer say real number and therefore the variable location which i am designating for the resulted value has to be able to store a real number but i do not know i know real numbers because like you i'm a good student in maths but i've never heard this word float and somebody needs to explain to me what the help float means is it indeed equal to real number what are the limitations and whatever so these are my impressions when i first look at this problem the next few lines these are clearly the instructions to solve the problem these i can relate to right n1 equal to 2 n2 equal to 5 x equal to 3 but wait the way the formula is written v is equal to x plus n1 by n2 notice that the original formula given to me was v is equal to n1 by n2 plus x that is how i calculated it to be 3.4 now i suspect x plus n1 divided by n2 after all i am told that dumbo is a total dum character so suppose dumbo actually adds x to n1 well it will add 3 and 2 giving me 5 and then divides it by n2 which was 5 i will get answer as 1 and i won't get answer as 3.4 so that is what will i will think is that the case well as we shall find out it is not the case because dumbo while being dumb follows certain rules of evaluating expressions and the expression evaluation rules prescribe what is known as precedence of operations so as many of you would have guessed if there is an expression involving multiple operands and if the operators the computational operators are add subtract multiply divide then dumbo always carries out multiplication and division before addition and subtraction this is something that even in our school days we understand and therefore dumbo will hopefully calculate it correctly we don't know that yet but we shall be studying these rules in greater details however if we execute the program we will get the correct results then i look at the remaining lines i know c out is output i have not made a comment on n l incidentally e n d l is it stands for end of line and this is same as that funny symbol backslash n both mean that when you give me this string and this value at the end go to the next line so if there are multiple output statements don't keep showing me everything on the same line keep putting things in different lines we shall see that so examples in the lab but now this returns zero so again as a student i said this is very confusing perhaps the line indicates returning value zero to someone but to whom and why a zero i don't know that okay well i am a student the teacher says this is how you write programs all right these programs i hope to understand these issues eventually do i capture some of your doubts correctly in this fine so in a nutshell when i execute the programs in the lab from given dot c p p files what is dot c p p file mean okay file names in general inside an operating system have two components one is called the name and the other is called extension and the extension is typically a three character code which signifies something to the computer system and the extension is written after a dot so name dot name is a general file name in any operating system the first name is the file name the second name is the extension so all other programs you will notice the files we are called something dot c p p c p p stands for c plus plus problem dot c would stand for c program dot f o f o r will stand for four term problem etc etc etc so when i run these programs they will work correctly collecting input values from me and return the correct computed values output except for the first program which has an error i don't know where we did not flash the first program uh sufficiently adding two numbers other programs who slightly more complex thing they will work correctly adding two numbers program if you type it exactly as it is it is likely to give you some problem we shall look at that program at the end of this slide which will be our concluding slide of the lecture today and then look at those things again so this is the important part i should understand the way variable names are defined the way computations are carried out so that i can write instructions to correctly implement the desired calculation so what i am concluding as a student i don't care if i don't understand those funny things as long as my programs work i'm okay with that and okay if these teacher tells me write this stupid thing include something here say return zero i'll return 10 i'll return 15 whatever as long as my program runs i'm comfortable however i better understand how my computations are done i better understand what are the rules which govern the conversion of values from integer to real real to integer whether i do addition first or subtraction first i must know all of those things consequently i must understand the different types of values that can be stored inside the machine i must understand how these values are manipulated what are the rules of the game that i ought to next week in the first lecture this is precisely what we'll be doing we'll be explicitly looking at all possible rules that govern dumbo's behavior while computing things so once i know these i will start writing my programs to solve computational problems at least and in the process i will learn the meaning of the other things okay so read this program do you think this program will work correctly no only few knows everybody is not convinced that this program will not work correctly will it work and i am not talking about the funny lines well one of the funny lines at least one funny line that i have in mind is this line int a semicolon int b we can guess that this line is telling dumbo to reserve two locations in two of its memory drivers one called a one called b into these locations we are going to read two numbers however when we ask dumbo to say sum is equal to a plus b we have not told dumbo to reserve a driver for some that incidentally is an error dumbo remember i told you is a obedient servant it obeys the instructions exact so while dumbo forget the execution of the program while dumbo is reading my program technically when your program is compiled by the c plus plus compiler that is when dumbo reads your program first to check whether dumbo can understand every instant so i will dumbo will understand this dumbo will understand this this this this this it will say sum is equal to a plus who is sum now it will give you an error called a syntax error the error will be displayed on your screen unfortunately the error may not be very meaningful it may say something like sum not declared effectively you will be able to figure out because that will be another nuance to understand the error messages that you get from c plus plus compiler and as we shall see later on when we write slightly larger programs it is quite possible that you have made exactly three errors in a hundred line program and you get 200 error messages because of because once dumbo starts getting confused the confusion is added every time dumbo tries to read some more instructions so it is extremely important for us to be careful what would you suggest then we should correct this program as yes we should just say here int a int b and a semicolon is a necessary nuance we have to put a semicolon after every statement now dumbo will be a happy man okay fine so i am done with my slides we will have some question answers okay his question is that after the completion of a computational operation what happens to the register and the values which are there in the register on the workbench of the dumbo actually unless something is done to them they remain there register is also like a memory location later on when we shall study a little bit more about the technology that constitutes the memory location as well as registers we will find out that both are composed of digital electronics okay which are actually memory locations the register is an extremely fast memory whereas the conventional memory location is a slow memory so if something is loaded into a register by dumbo it remains there however it is traditional that whenever a new program execution is started the registers may be flushed the memory locations may continue to have whatever even if a register is not flushed it will never be used for computation unless some new value is loaded inside so it is safer to assume that unless i do something about it a memory location or a register may continue to contain whatever trash value it had earlier and therefore this question is important because it tells us one thing it reminds us of one thing i should not use the name of a memory location in my expression unless a value has been assigned to it because then what will happen is completely unknown some trash value will be picked up from that any other query yeah sir you said about the examination pattern as open notes exam i didn't understand what the meaning of open notes exam yeah so open notes or open book exam is an examination where you are permitted to carry any notes that you have prepared for the subject any books that you have any files that you have anything that you have and you can read those notes you can read those books you can read whatever it is so that you don't have to mug up anything the exam will contain problems which you will have to solve suppose you you forget how to write one of those funny lines include less than something something greater you forget the exact syntax you would like to be correct now rather than wasting your time in remembering and recollecting how to write those funny lines if you had a note which said okay this is how you write it you write it correctly you may have 20 programs which you have pre-written you can carry all those 20 with you and then when a question comes you may say this question looks similar so i will i will look at this i may look at this the idea is that you will be able to refer to any background material that you need in order to solve the problem i must also warn you however that an open book exam is generally more difficult than a closed book exam and you will have to read far more before the exam than in closed book exams so i will give you a funny incident this happened about 25 27 years ago it was an open notes exam and one student walked in in my end semester exam with three very big files holders you know he had about 500 programs written written means not himself if he knew programming he would not have carried those files so he had probably asked his friends to write something but he had collected printouts of 500 program in all of three hours he was just trying to identify which program in those files will will apply to this problem had he read those programs earlier he would probably not be required to carry those files so open notes exam is essentially an a help an assistance to you so that you have a peace of mind that if i forget something important it is available to me but if you really need to access everything every time then there is something wrong with your preparation so this is an additional assistance so that you can write your programs in your examinations in an absolute flawless fashion there is no need to make any error because you have access to whatever material you need i hope that is that's okay i mean question will only be to check our concepts of programming you will have to solve problems there will be a problem stated you will have to write a program to solve that problem problem solving is is the basic okay in our exam there are no questions like explain what is meant by int write a short note on any two of the following five we have no such solution solve this problem solve this problem solve this problem period sir the programs that were displayed on the slides yeah that were in c or c plus plus these slides display programs which are actually c plus plus programs the textbook is kuhun and david san that is what is prescribed but it will not be followed that's the problem we have been struggling i i took this course last year and i was so surprised so i asked all my previous teachers who also had prescribed this book as kuhun's book and all of them confessed that they really don't use that book much so only thing is it was too late so i think for c s 101 course as it is offered in iit bombay we need to write a separate book so this year i will be trying to get some additional notes as we go by but what i will do is since kuhun still continues to be prescribed as a textbook and there are by the way very good books in c programming they're not c plus plus but some of the basic concepts like presidents of operators types of values there's so much similarity there the control structures if i do whatever we shall be studying those coming years so what i do is i have about a list of four or five books including some books in c i will list them and every time when we discuss some specific concept i will give you a reference to a chapter in a section in each of these books so you can refer to those in order to further clarify the concepts that's the best we can find thank you so much