 We will continue our discussions. First I would like to do a quick review of last lecture, look at matrix multiplication problem and we will look at one problem which I call file indexing. Then I will just present a program to you and ask you to figure out what exactly is being done and how. To begin with I would like to revisit time complexity. There was a syntax error in the notation that I used in the original slide which I have corrected. If you recall we had said that we compare algorithms on the basis of their behavior when the size of the problem increases to infinity. So as n tends to infinity we said some programs can be compared, not some, all programs can be compared on the basis of order of magnitude of computations that the program would require and if n is the size we said a program is order n square we write it as o n square. The difference is in this notation by mistake I had used a small o here but you have to use a big o because technically small o and big o are different things. They are not the same. Mathematically when you compare algorithms there is a small o notation which means something different. What we shall be using is what is called the big o notation. For all practical purposes what we mean is that we are talking about order of complexity. So order of complexity of the algorithm is big o n square. Another program may be order n. Some other program may be order log n. It is important to specify the basis of the logarithm because ordinarily log would mean natural log. Typically in computer algorithms you would have log n to the base 2 for obvious reasons. Clearly an algorithm with order log n is much superior to an algorithm with order n which in turn is much superior to algorithm n square. What would be a worse algorithm? Order n cube. Another order n raise to 4, order n raise to 5. This n square n cube n raise to 4, n raise to 5 you will recall are all polynomial terms. So in general n raise to k where k is a very large integer will be a very time consuming algorithm. But still that algorithm will be said to be bound as polynomial time algorithm. So polynomial time algorithm is algorithm which can complete its execution with some order of polynomial of the size n n square n cube n raise to 4 n raise to k whatever. Can there be anything worse than that? What could be worse than n raise to k? What is worse than polynomial in terms of increasing the number of computations or increasing the number in some sense? n raise to k where k is some high value. In general when you have a polynomial of that type n raise to k plus let us say b naught or b k n raise to k plus b k minus 1 n raise to k minus 1 etcetera, etcetera up to some b 1 n plus constant b naught. So this would be the time complexity of an algorithm which can be represented in polynomial time. Such algorithms although they become costlier as power of n increases they are all said to be bound by a polynomial time execution because the expression representing the time complexity is a polynomial expression. I ask what could be worse than polynomial? So what about a raise to n in general? Would you agree that this function increases more rapidly? Yes or no? So exponential functions are generally faster generally increase faster than polynomial and these would take you to the realm of impossible computational problems. So polynomial time and non-polynomial time are too very fundamental distinguishing features used and people have been trying to prove that in the worst case both could be safe very cruelly speaking. We will not go into those details. What is important for us however is that every algorithm that we write we generally understand the complexity. We are unlikely to write algorithms which will go beyond polynomial time complexity. If ever we come across one we shall point that out. Those will be impossible to solve problems kind. However within the polynomial time as I said order n is preferable to order n square, order log n to the base 2 is preferable to order n, order 1 upon something log n is still preferable etc. These things matter as I said when n tends to infinity. So for very large n these things are material. Otherwise do not forget what I said earlier that if you have an order n square algorithm and another algorithm which is order n ordinarily will require this as faster. But depending upon the actual expression of the time complexity it may turn out that for a certain value of n order n square algorithm is faster than order n. Beyond that value of n order n will be faster. Now if that value of n happens to be good enough for solving most of the practical problems in life then you would like to use that algorithm because that algorithm is faster. So whenever you are comparing algorithms even the order of complexity may be different it is still important to compare nittigrities and the detailed expression. In any case within two algorithms having the same order of complexity try to reduce the coefficients of the expression. Why I emphasize this generally when you write large programs and that is what you will all be doing in your projects you tend to forget about the efficiency of your program till the entire system is developed and when you try to run your programs later you find that the programs are not executing fast enough to meet the real life demands. In general then it is a good idea to keep the efficiency of program in mind while designing the program itself not subsequent. It is extremely difficult to tinker with the program and algorithm which is already written especially if the program is larger complex. I will very quickly repeat the redirection we have seen that ordinarily you read input from C in but if you use the input redirection then the program is capable of reading from an input file. As somebody is asking me yesterday why do I say dot txt? The file name is not important. The file name could be x dot y it is your choice entirely. What is important is what that file contains. The file must contain data which is amenable for reading by C in because redirection is a replacement for C in and nothing else. So for example yesterday somebody was asking whether I could input an image. We have not even discussed how do we represent an image but we take it for granted that the image representation will not be a text representation. In which case it is futile to try and give a file which contains an image because C in will try to make sense of the data only in the context of C in statements that you have given in your program. It cannot understand anything different. Therefore while the name of the file is not important the contents must be text contents as if you are typing them on the keyboard nothing else and that is what is read by C in statement. Typically I would give it an extension dot txt or earlier people used to call it dot d at which now has a different connotation in some operating system but the contents is what is important. Similarly you can redirect output. Again it does not matter what name you give but what will be contained in this file after the completion of execution of your algorithm or your program is exactly what you would have seen on the screen nothing else because what you produced using C out is what is being put into this file by the operating system nothing else. So keep that in mind. Names do not matter but they have to be text files available for handling by C in and C out statements. We also discussed the need for debugging and this is something I would like every student to experience and experiment during the lab sessions particularly as your programs become larger and larger. In fact even for small programs it is not uncommon to make a silly mistake somewhere and you cannot figure it out unless you put some intermediate print statement. So this is the facility where you are able to put code like this hash if something something some block of statements typically these will be output statements although they need not be outputs. For example you can even do some intermediate computation and print the result of that intermediate computation as a part of debugging. It is entirely your choice. The point is whatever statements you write in this block hash f x x x up to hash and all of that will either be completely ignored by the compiler in normal course or all of it will be compiled and then those statements will be executed in the normal course. So typically I use the name not sure because it conveys the meaning that I am not sure of what is happening. However there is no such sanctity of this name. You can use absolutely any name. You can use x x x x for example any string that you use without quotation marks that is what you write here hash f blank not sure and then these are samples C out statement. It could be any other statement or a group of statement ended by hash and so as I said ordinarily C++ compiler will ignore the block but if you compile your program with minus D option this is the way you write minus C++ blank minus capital D don't forget that blank and this is followed by the string which you have used in the hash if state and then of course a program. So these statements are compiled and are executed as part of the program. What is important to remember is they are executed not as a separate entity but they are executed exactly in the same order in which they physically appear in your program. So in fact if you want to understand how the program will behave with minus D option take your program forget the hash if and hash end if statement as if it is not there then whatever are the statements remaining they become now part of your program in the normal course they will be compiled and executed. I would like all of you to experiment this because this is what you will need when you compile when you write larger programs. I will repeat the announcements that I had made specifically the video lectures have been uploaded my team tells me that within 30 hours of a lecture they will be able to upload the lecture on the internet not on the internet but on the intranet. So you should be those of you who want to let's have missed the lecture want to go through some portion the speed is pretty fast we have tested it from multiple places and when you play it you can actually move the cursor up and down you need not listen to the whole lecture you can go to an arbitrary point in between just like you advance a movie or something like so for those of you who need to do that they can do it otherwise the resources tab which has been least explored in this course sadly I request you to explore it further more specifically there are lecture slides lecture notes and a fairly good amount of notes specifically written by professor run a day and the sample problems by run a day Sudarshan and Sony they're all there the difference is that the way they have treated this course the evolution has been slightly different for example they have discussed pointers and care type much earlier in the course we have avoided using that so far we shall do so very soon immediately after the mid say however in those notes I have a simple suggestion ignore anything that has not been discussed in the class and you should still be able to make a mean and sense out of the sample programs and the notes that have been given additionally I mentioned a beginner C plus plus it in no way reduces the importance of the poems book which have listed as a textbook although we have not been using it as a text then what is important about that book there are a whole lot of exercises I would like you to do those exercises solve those problems and that is where you can use collaborative small clubs within your own hostels everybody need not solve every problem if you distribute it sit down together and discuss where everybody explains the way one has solved one problem you can have tremendous advanced it's exactly like attending a small class where everybody is a teacher in turn this very important because we have been remember we have been going pretty slow so far and we have been going slow because there are a large number of people who either did not have any computing background or very limited exposure to computers but do not forget that that actually hampers the progress of the people who have already done a lot of programming and at the end of the course each one of you would be expected to write fairly large programs so to catch up very rapidly because from mid-sem onwards the pace will increase very quickly here are some modified announcements the mid-semester exam will be conducted as per following sitting arrangements batch 1 to 7 that is 1a1b1c1d etc 2a2b etc they will come here and they will sit in the blocks 1 2 3 4 5 6 7 the specific announcement of which segment of the block which particular batch should sit the lab batch for example 1a1b1c1d like that last time we had a lot of problem in deciphering the answer books and so on we don't want that batches 8 9 and 0 will sit in ic classrooms on the first second and third floor the ground floor ic room will be reserved for late comers if for any reason you are late don't ever go anywhere near the specific hall of your exam just go directly to ic one or whatever it is called the ground floor room we start that exam about 10 minutes late or 15 minutes late however if somebody for any reason is half an hour late doesn't matter he can come and join the exam there but the exam will end at the specified time at all places last time we discovered at least 35 answer books on which people had not written their batch numbers this is unacceptable so I'm thinking seriously of reducing marks if the batch number is not properly written because that's the sole sorting key for us when we try to recompile and compare it with attendance similarly last time there were several students who signed multiple attendance sheets so we had a tough time finding these things out why I'm mentioning these is that whenever we have a large group like this an absolute discipline needs to be maintained by everybody somebody rummages on the discipline the entire organization goes heaven you will learn some of it when you do the projects which is my next announcement the course projects in this course will be batch projects I call them group projects I am refining that now because every batch will do a project so that is exactly synonymous with your lab batch so 0a 0b whatever 1b 1c 1d 9a 9b each batch is a group each batch will have about five teams I have figured out that most of the batches are of the size 20 to 23 24 so that is why there will be five batches five teams ordinarily each team will have four students but one or two teams could have five students depending upon the total number of students in that and one of the students in that team would be a team leader now this choice of the team members and team leader is entirely yours I must spend some more time on this because it's very important how you form these teams in the batch somebody asked me for example that suppose the students with maximum programming experience prior to coming to IIT team up together then wouldn't that be nice and I said yes maybe for that particular team but remember there are 16 other people in that batch who will have to contribute meaningfully so if all other teams have no experienced person then the totality of the project that is delivered by the whole batch will be relatively lousy as compared to distributing your strengths within different teams of the batch why are these things important these are important because what you're learning here programming many of you will deploy this programming for developing large programming systems in your own fields some of you will actually join IIT services but some others will be building large computational libraries or large design libraries or whatever what such large systems are never ever written by one individual or by four individuals or by 10 individuals the typical team size which develops a reasonable size software these days is of the order of hundred or more people now when you develop software in of that magnitude which is what you are all destined to do in fact I expect each one of you to lead such effort somewhere or the other as a part of your activity in that case it is important to understand the organizational aspects of such a team it is not adequate to say I am a crack programmer because an individual crack programmer will crack if the burden is to write hundred thousand lines of code in six months no individual can do that 200 people can possibly do that provided they are organized I would like you to learn the organizational skills the leadership skills and the communication skills which are required in the modern programming teams to develop something substantial and to be proud of whatever you have developed so that's the reason why I'm introducing these batch projects I have done this experiment successfully at some other level in the information system course and some very excellent projects have been developed just to give you an example when I taught this not this course another course and data processing in 1984 or 85 I think I took a single problem for the whole batch and that problem was the salary system for the Institute for IIT Bombay we had a very small micro control kind of machine then which was getting out of commissioning within three months and the Institute wanted a new payroll system we had a 8-bit micro computer which ran an operating system called CPF there are no desks there were two floppy drives and it had a compiler for a programming language called cobalt so I use cobalt programming language to teach data processing and the whole batch the course project was developed IIT Bombay salary system they were I think about 20 or students in the computer science batch then as a part of one course they developed that system which for next five years actually paid the salaries of all IIT employees so they could construct something which was extremely meaningful in fact they did not have much time to test the programs they tested it to whatever extent they could and I still remember when the March salary which is paid in April was produced using new programs there are two errors one professor in those days professors who did consultancy would get their annual disbursement of consultancy in the March salary which is paid in the April so somebody was supposed to get 18,500 rupees got 8,500 rupees and another person who was supposed to get 21,900 got 1,900 and that is what was printed on their sheets on the salary slips and of course they came crying foul you know what was the problem when you format the output the student was responsible for producing those salary slips decided that since the president of India gets 10,000 rupees per month as the salary no Indian could get more salary than that so he printed the salary as four digit numbers so out of the five digits the first digit was lost that is how cobalt works and only four digits were printed but apart from that there was no error in fact the professionals in Mumbai from LNT and TCS complimented IIT Bombay because no salary system has ever been put to live usage without two months of parallel testing one of the teachers of this course was a million Sony was one of the leading students of that batch by the way I'm telling you this is that you are capable of doing astounding things provided you put your mind not only to programming but the aspects associated with designing organizing documenting and testing programs and that is what I want you to learn when you do the projects so in conclusion please form the teams immediately and while you form the teams of course you will come closer those three or four or five people who have sort of worked together know each other but keep the interest of the entire batch in mind each team will have a team leader and leaders from all the teams in the batch will constitute the batch coordination committee so there will be five sort of people who will coordinate all the activities please do not forget that the project has 30% evaluation weightage that means I'm responsible for allocating marks out of 30% weightage to each one of you the group projects are evaluated in the following way 20 out of 30 marks are reserved for the group work the amount of work done the quality of work done the quality of documentation and testing out of 20 marks the marks will be allocated for the entire batch every student in that batch out of 20 marks gets exactly the same doesn't matter if you are the crack programmer or you're the most useless program that's the advantage and disadvantage of belonging to a team however the remaining 10 marks will be for individual contributions now there are multiple mechanisms of evaluating individual contributions the one which I favor most is to ask for individual evaluation from the batch itself have you ever done that exercise self-evaluation in a group no somebody else has always given you marks right there's a very interesting exercise very important exercise because in professional lives you will be doing that you'll be evaluating yourself the idea here is the whole batch sits together and you have to grade everybody on the basis of contribution on a scale of 1 to 10 and the team leaders and the group coordinators shall ultimately resolve this if no consensus is formed I as the instructor in charge has the right to decide using means available at my disposal ordinarily I will honor the marks that you so give or the evaluation that you so give after some sample checks the sample check will consist of a one-to-one Viva with one or two arbitrarily selected members from that team based on of course the evaluation that you present and if my evaluation of those two individuals does not tally with your evaluation if it is substantially higher then everybody in the team loses marks out of those care now I will elaborate this process this process has worked successfully far more important than the evaluation marks I believe this process will teach you a lot about professional self-evaluation in a group we'll discuss this more later on when we go to the group projects the last but not the least many of you have already done a lot of programming not only in their 10th and 1112 standard I met someone from Bihar who has been programming from six standard I think he knows about six programming languages now such people are perhaps better placed than most others to suggest problems for the batch project even others who haven't handled programming per se of large magnitude can imagine problems which perhaps can be tackled by a batch or a sort of bunch of 20 25 people so what I would like you to do between now and Thursday is to submit some kind of your proposals problem proposals and submit these proposals on your moodle TAs will be instructed to collect these during the next week of mid semester we will work at the back end to define the problems for the batches which of course we'll allocate later but do suggest problems one more announcement in this regard the next lecture Thursday lecture I will not teach anything new but I will devote that entire class to solving problems any problem that you are faced in any program but I need a feedback from you as to which problems you would like to discuss so please send a mail to me specifically this is not you can additionally post it on the moodle but I must receive a mail independently and that mail message must have the following title this is important I get about 300 emails per day I try to read all CS 101 related emails although I am not able to respond to everyone but it is hell unless the subject line contains something very specific this should be the exact title CS 101 underscore problem all small letters sorry CS 101 blank problem you can understand if I have about 16,000 mails in my mailbox then searching on the subject if it is exactly written I'll be able to get all the mails immediately just to help me sort it out faster below this you can state your problem in the mail itself whatever is the problem you can make a reference to a particular slide number of a lecture saying that this problem is not clear or you can state a problem saying I could not do it you can give piece of code which you have written and which you can say I don't understand what is the problem in this piece of code absolutely any problem that you have in the course because I'm using this mechanism to collect all the problem areas that you have what I will try and do is on this Thursday and then at the bottom you must write your roll number name and badge do not forget to identify yourself completely so I would expect this email latest by tomorrow night Wednesday night so that I can work Wednesday night whole night to dissect some of the problems which I would like to discuss here so that is what we'll do on Thursday incidentally the mid-sem question paper will not contain any multiple choice questions in retrospect I think it was wrong to put that question in a regular quiz with five marks there because you either get zero or five and that is not a good idea because a whole lot of people who would have actually worked out the logic almost correctly would not get any credit for that logic so we'll correct that situation subsequently of course as I said our clicker devices are getting ready and after mid-sem I'll be conducting online quizzes without losing much of time in evaluation now this is the last but most important announcement and this concerns the fact that the materials from this course will be released in open source currently what you see on the intranet on the CS 101 home page will in some edited form go out and will be accessible to anybody and everybody in the country and in the world we're going to use the creative commons license as I mentioned now it will be very useful if most of you at least those of you who have let's say mark mastered the art of programming either in this course or because the earlier experience and even others who are the first timers could give sample programs or any other useful material if you have written notes if you submit that I will be designing a submission form which will be putting up around the mid-sem if you submit that that matter will be included in what IIT Bombay will release with of course your name and credentials for you more than the credentials you will be contributing to lakhs of other students who are learning programming and who might benefit from whatever you contribute this is of course provided you believe in the open source the open source retains your credit retains your copyright but it permits anybody has to copy use modify mutilate whatever that's the purpose of this additionally transcription of the audio lectures the audio video lectures are put there the transcription in English we are trying to get it done through some staff but I noticed that there are several students here who at least in the first few weeks had tremendous problem understanding English you will agree that there will be lakhs of such students all across the country so if anyone or more of you are interested in transcribing these lectures or even preparing the notes in other Indian languages you're most welcome to contribute I would expect at least an email for positive intent in which case I could organize some additional support for such people because when we do this material release in open source we would like it to be commensurate with the stature of the institution like IIT Bombay is putting something out it must have some added value as compared to other things that come out on the web okay we now go over to the matrix multiplication continuing from where we left off yesterday unlike the solution of simultaneous equations where I have a square matrix to deal with because I have n equations and n unknowns please remember that even in the solution of linear equation system it is not uncommon to have more equations than number of variables such a system is called over determined equation set so there could be an over determined equation set there may be for example ten equations then you have only five unknowns and if all ten are independent in some sense then it is possible for you to use any five of those however if you have ten equations and over determined set permits you to deal with numerical inaccuracies in a much better way however in general you would be dealing with n by n matrices now if you are two matrices one is r by m and the other is m by c which results in a matrix R R by c how would you do the matrix multiplication well each element R i j of the product matrix is a dot product of i th row and j th call yesterday we had discussed the dot product is a simple code which implements the dot product so for i equal to 0 to R and j equal to 0 to c so R and c are the two dimensions of the resultant matrix I am calculating the sum which I am accumulating in R i j itself by multiplying a i k by b k j varying k from 0 to m that is the standard matrix multiplication formula now this is the gist of the program but the way you would write the program and that is very important the way you will write the program should be such that the program is self documented so I have given some examples earlier here is an example for it so after include i o stream f stream whatever whatever whatever I write the whole lot of commands in fact any program that is submitted as a part of a worthwhile software system is considered completely useless if it is not documented in line in line documentation means within the program comments of this type as a matter of fact standard software development often mandates that the comment shall be of the following form although we don't have any such mandate but our programming standards or coding standards shall stipulate some minimal documentation now ordinarily when you have only two hours in a lab or when you are hurry in a hurry to write answers to your mid-sem question papers and so on the last thing on your mind is to write comments you would like to get your program right it is not a good practice to do that when you are developing software in fact the standard software development practices first you shall write comments in the entire program and then you shall write code which is commensurate with those comments that is considered the professional way of developing an algorithm there is much more to it in terms of analysis and design which precedes any line of coding for example for large systems which let's say are developed by 150 people you are 150 programmers you would expect that the problem is mentioned to them and each one of them starts writing programs that is absolutely sheer nonsense if it is a 10 month project let's say for developing that large program for first two months not a single line of code is written by anyone not a single line for the first two months you study the problem you analyze the problem then you design the software you decide how many functions will there be what main program will do which fights there will be what kind of data will be represented where all of that done then there is a review of the entire design the design is broken into function design modules etc etc only when the entire design is ready then people are said okay now you implement this design using whatever programming language that is been decided upon that is an important practice which you don't get used to there is something you will know during the project but this is just an exam here I say program for multiplying two matrices the authors are written the credentials are important to include your organization name like department of CSE IIT Bombay now this is a sample program for CS1 also is a purpose where the program file is written here so matrix multiplication dot CPP this is the name of the file itself sample input data file matrix dot text sample output file out matrix dot text you can see the immediate relevance of writing all this anybody who reads this program will know how to look for this file to look at the sample look for this file for the program it's wrong it is not uncommon either here or elsewhere to prescribe the entire directory path where that file is here is the use of if not sure so if I am going to use the if not sure thing at all I will use this if not sure here this is a sample so for example if I have used the minus D flag for compiling then the first line I will get will be debugging statements it will sort of tell me that either part of the output or all of the output that I will see on the screen is part of my debugging state in the absence of this line I will assume that the output produce is the normal output again this is not a standard convention this is how I would like to use it at the beginning of the program I put such a statement and then wherever I am not sure I will use the same structure to put some additional out here is an example of using compile time constants to declare the sizes of the array you remember we have said that I can say int mat a 10 or 100 or 50 or something please remember I can't in general say mat a n some people have made that mistake in the exam you cannot use a variable to define the size of an array because the size of the array must be known to see plus plus compiler to allocate so many locations you can't say size a and this is very important to understand because many people have made that mistake what would such a statement do you might think that since I am reading the value of n that value can be used to define the size of the area but remember the time difference the allocation of elements to this array has to be done by the compiler much before the execution starts the value of n will be supplied by you only when the execution starts so you can't say that use that to size the array size has to be fixed at what is known as the compile time that is whenever the compiler number c plus plus compiler looks at your program whatever it looks at it should be able to infer the size now going back to this particular example I have used here a variable size a by size m are these variables yes and no before this is declared I am giving a value which is a constant value not a variable value this is for this is for this is to when compiler reads this statement it has actually the knowledge that this variable has a value for this variable as a value for this variable as a value to so these are constant values as far as compiler is concerned and it will use these values here as a matter of fact there is a c plus plus syntax which permits you to define integer constant with variable names what is the advantage of doing such things here why why do I say 444 later on we shall see that such definitions are useful because by recompiling it without changing the program code I can change the array sizes remember I will not use it only for array sizes all my loops might run from 0 to size r i minus 1 0 to size m minus 1 etc. so they they automatically solve the purpose of n which is ordinarily variable is just one way of doing things not necessarily the best way is just to illustrate that variables are ordinarily not permitted to declare the sizes of the array however when the variables have been given constant values in the same program so that compiler understands how many locations to reserve then and only then such a thing is permitted here is a program part which reads from the in matrix file the in matrix file is matrix loss test there is a test if in mat file dot is open we have not understood because we have not studied the file declaration file handling at all we shall do that later but this is just to give an exposure that instead of using c in you can actually invoke a file please remember that c in requires you to give data from one stream typically it is keyboard and if you use redirection it could be one file however in larger programs in larger programming systems it might be required to read data from six different sources simultaneously for that program to execute take for example your academic grade processing system there is a file which maintains data about whether you have paid the fees or not that is with the account's office there is a file which says whether you have registered for the courses or not there is another file in the hostel which says you are inmate of this hostel you have paid the mess bill or not whatever what now these all will not never ever be kept at a single location in a single file so obviously if you are writing a program which does something comprehensive on all this information in that program you will be required to read data from multiple sources these multiple sources are different files and consequently it is important for you to understand how I can open a file read data from it close a file or write data on to a file I might be wanting to write data similarly not only on c out but on 20 different files so that is the reason why these files are important currently you take it only as a exposure value so I am reading this file and I print matrix A from 0 to size i and from 0 to size m because the first matrix is r i by m in exactly the similar way I read matrix B which is from size m to size r j so I am using r i for fixing the number of rows of the first matrix I am fixing r j to mention the number of columns in the second matter that is what is important I close these files if I can't open this file this else corresponds to let me go to the previous slide if in mat file is open then I do all this that means I have found a file and I have been able to open however suppose you run this program from a directory which does not contain that file then the operating system when it attempts to open a file because c plus plus wants that file operating system says sorry I can't find the file if that happens then this if statement will turn out to be false and you will come out here and when you come to else you'll say c out endl unable to open file this else statement closes here what else should be written here any suggestion is this adequate please remember that whether the file is open or not if the file is openable I will read the matrix if the file is not openable I will produce this unable to open file but in any case I seem to be going ahead with the matrix multiplication does it make sense to multiply matrices which I have not read at all so that means I should not go here unless I do something here so what is that something I should do else whatever see how return 1 ordinarily I say return 0 why I can't I say return 0 will it be wrong if I said return 0 first of all you agree that a return statement should be there that means my entire program should now be terminated because if I have not been able to open the file there's no merit in my trying to do matrix multiplication the question that I am asking is that return statement has to be there ordinarily we understand we write return 0 here I have written return 1 why is that so the reason is as follows in fact you will recall our discussion on writing functions we had written a function which was reading a file containing student marks etc and that function was returning a value which was equal to the value of the number of students actually every function is capable of returning a value of the type which is defined for that function so like if you define the function to be in it will return integer value float it will return a float value etc etc the main program that we write is also a function but it is not a function which you call it is a function which the operating system Lambo calls consequently just like any function within your program the returns of value to some other place in your program itself our return from the main will return a value to the operating system ordinarily operating system would not be concerned with the value that you return because it only understand that you have finished your job it will kick you out take somebody else's program or whatever else will show you the dollar symbol however it is often important for the operating system to understand whether your program executed correctly or your program executed wrongly the return value is often used by the operating system to determine that so if you return a value zero the operating system considers that your return is normal any abnormal value will say your program has not worked successfully somebody asked me a question yesterday how does it matter to the operating system after all the program has finished execution with a right or wrong is the program is responsible what will operating system reduce with such an information and that is because you cannot perceive of a system beyond operating system the example that I gave him I'll quote again consider a larger software which is working for railway reservation how many of you have done internet railway reservation many of you so what you do when you log in on the web page you get the IRCTC site and let's say you find out frontier mail so much reservation you give all the data there is some operating system in the IRCTC basically sitting in Delhi server which is probably maintaining files containing different train reservations and water when it confirms that it has seats it asks you to pay money typically you would pay money using credit card and that site will say okay who is your bank let's say city bank then that system will divert you to a city bank site which is actually as a server in Chennai let's now Chennai has another operating system Chennai has other set of programs and that is where it will collect money from me from the car it is important for the Chennai operating system to know whether my program has succeeded in giving money or it has not succeeded why because that operating system has to communicate with the operating system in Delhi whether the money has been collected or not collected it is therefore always important that whenever you exit from a program some indication to some higher authority is given whether the program has executed properly or program has executed improper the rest of the program is very straightforward we have already seen that I will just show you the glimpse of a program so there are two aspects of this program let's very quickly go through the slides the first slide here contains a lot of comments I would like you to write comments on the second third fourth and fifth slide there are some comments here which says matrix multiplication some comment which says read input matrix some comments which say real output matrix ordinarily when so much of explanation and discussion has accompanied such a program this much is sufficient but if you want to read a completely fresh program out of the blue then unless you have detailed documentation it becomes very difficult to read as an example how a program is very difficult to read I have listed here this is the contents of the input file is a 4 by 2 matrix and another 2 by 4 matrix when I execute this program matrix multiplication it produces matrix and matrix B wrongly again because it is using C out but the output is contained in a matrix called out matrix dot text this will be printed out by C out like this observe again that while 13 18 23 28 etc appear to be printed in an aligned fashion six at 10 12 get compressed here because they are single digit numbers so this is a question to ponder how to create an output with values which are properly aligned for example 100 should be towards the left not exact one should not be aligned to six as in this case is just to keep you thinking we shall discuss the formatting after the mid-sem it's not relevant to the mid-sem now here is an example I will just quickly grasp through the slides there's no time to look at it I don't want to explain it I want you to read this program to figure out what it is doing the title says file indexing look at this can you make sense out of this there is some indication of what this program might be doing from this page because it has roll number assignment marks file index there is a in marks file what I'm going to do is after this slide is uploaded I will also upload the example dot cpp along with the input file and the exercise is to figure out what this program is doing and what why it is doing this will be useful exercise this is the complete program and I will also put that input file which is actually input file containing roll numbers quiz marks assignment marks exam marks etc etc you have to figure out what this program is doing you take that as a homework for Thursday lecture thank you very much