 So, as I said last time, we will very quickly review some basic programming concepts. We will take a running problem, we will keep expanding that problem till it becomes a problem worthy of a full-scale project or even a large-scale application system. But we will start with some small segment of that problem. Basically, we are going to review the data representation issues, the computational issues and the controlled execution of all statements in terms of decision making and looping and we will introduce the array structures. We will also introduce the notion of files. So, this is a very speedy, what should I say, review of everything that we have done so far in the earlier part. The problem that we consider, so this is a simple computational problem. There is a house, all houses have roofs, but let us say we need to put some spatial tiles on the roof, maybe to prevent rainwater from leaking or whatever. And the objective is that putting tiles costs some money. We want to figure out how much money it costs given the dimensions of the roof. We note that any tiling work will require calculation of the area that is to be tiled because usually tiles will be costed on a per square feet or per square meter or per square something basis. So, this is actually straight forward and we note that in C plus plus a program would be written something of this type. Is this correct? No, everybody knows why it is incorrect. Cost given is per square meter, I have to calculate the area which is L into W and that has to be multiplied by cost. So, this is wrong. The correct statement will be the cost will be L into W into C. This has to be assigned to some variable whose value will print. So, let us say we define that variable to be simply cost is equal to this. We have to put a semicolon below after this statement. This is very straight forward. What are the data types of L, W and C? Suppose I write here as int L, W, C. Will that be correct? Why it will not be correct? Generally, the dimensions of any house roof need not be exact integer unless you measure in nanometers or something. So, you measure in meters or feet or whatever the normal scale, it will be a fractional number. We will get to see this the moment we write down some sample data values which we will be giving as input for this program. Imagine that the sample values are that length is equal to let us say 5.8 meters, width is equal to 2.6 meters and let us say the cost of the roof per square meter is something like 284 rupees 50 paisa, some arbitrary value. Why I do this is it is not uncommon for people to just assume all the values to be integer unless you think about it like all of you did that no these cannot be integer. The best way is to write some representative data values that will be used in the problem. While writing these data values you will suddenly find out that if you write L is equal to 5 meters, W is equal to 2 meters then you know immediately that there is something wrong all values cannot be such nice integers. So, writing down some sample data is very useful in correctly writing down statements in your problem. And therefore, we note that this cannot be int and this will have to be float. We need one more thing which is what the cost. So, this cannot be semicolon this has to be a comma and then I have to add cost. The minimum that I must do is read the value of values of the variables that has been given. So, I will have to have a input statement here which will say C in L, W and C. It is after reading these values I can do these computations and I can output. So, this is the gist of my program. Should a well written program be like this? First of all is this program correct or wrong? It will work correctly? Nobody is saying yes immediately. I thought we had incorporated all the corrections that we found out to be missing. So, is there something else that needs to be done as far as correct working of the program is concerned. So, let us quickly reexamine we have declared four variables L, W, C and cost. We are reading in values of three L, W and C. Then we are saying cost is equal to L into W into C and then we have outputting the cost value as C out. So, definition of variables input of values computations using a computational expression followed by output. That means computationally this program should work correct. The question that I am asking is this how you would like to write a C plus plus program? If not what else would you like to add to this program? The program will work correctly is verified. So, you should prompt the user to input the values because he will have no clue will be sitting there what values are to be given that is one good. Then extend the same argument if user should be prompted to give it some specific input in some specific order should user not be told what output is coming. So, input and output generally should be preceded by appropriate messages of text. So, we would like to have before this scene a C out statement and along with this C out some indication that what is being printed is or what is being shown on the terminal is cost. Something else ask the user to enter the valid digits the input will generally be valid because when you are doing C in you do not have control over individual digits or characters that the user enters. You can only examine the total value that you get in because in C in the values are read as text, but interpreted and translated into internal format automatically by C in and C in looks at individual chunks of values which are separated by white spaces blanks or more blanks. So, suppose you given a value instead of 284.50 suppose you said 28 p 0.50 there is no way you can know that there is a p character or something the C in will simply bomb it will say invalid input you do not know why it is invalid and if you are inputting in a single scene statement 3 or 4 values the error message will just show that some error occur during this input. So, you would not even know which particular value was wrong there is no way to find that out when you are using such preliminary or what should I say elementary input mechanism as C in. If you really wanted to do that later on since we know the advance form of handling characters in a text file or in a text input I can actually read individual characters then I can actually put aside the set of characters which are supposedly representing one value then examine each character whether it is digit or not or decimal point or not then convert it using A to I or A to F functions of C plus plus to convert it into floating point and if there is an error then for each individual value I can put out an error message. In fact internally C in does all of this, but is not very polite to you in the sense of telling you where what was that wrong. So, we may not be able to do that. However, his observation is correct in that if there is an upper limit then it should be checked there has to be some validation of data that is being given for example, suppose this cost now some user enters this cost as a 1 crore 25 lakh something something would you be interested in getting tiles fixed on your roof at that cost most certainly nobody would be not in India definitely. So, therefore you would know that there is something wrong with in exactly the same fashion suppose L is 5852 meters of 5 5.8 kilometer long house is generally unthinkable the point is you such very large numbers or very small numbers like 0.3 meter cannot also be length of the house at least you yourself have to be able to go in. So, that is not correct the good point that is making is that we should validate the bad point here is there is no specification of what to validate against and why I like this question is this is exactly what will happen in 95 percent of the real life problems what kind of questions do you solve in exam make sure that the value is positive the value of x is in the range 2 to 5.8 this is specified in the problem. So, you know I have to validate, but real life problems will be like this. So, you have to make some assumptions and there is nothing like correct assumption and wrong assumption 200 assumptions might be right 20 assumptions may be wrong and that describes the way you have applied your mind there is no unique answer we agree there is no unique answer. So, let us now fix some limits on these values ourselves from our common sense knowledge of the sizes or houses and our common sense knowledge of fixing tiles on the roof. Now, fixing tiles on the roof is not something that you usually do every day or something. So, you would have no clue on what is the price, but let me tell you that the prices could vary drastically depending upon the nature of the type. Some types which in Hindi we call Khaprail could be very cheap some very fancy types could be 100 times costlier than those types per square meter, but still there is some limit as you said 1 crore rupees per square meter is unthinkable is 1 lakh rupees unthinkable perhaps is 1000 rupees unthinkable perhaps not is 2 rupees per square meter unthinkable definitely so. So, you can arrive at a judgment the point is you have to apply your mind you have to think you have to think and say what should be the right values what should be the range and then decide that anything below this or after this will be incurred. So, can you think now let us have some suggestions or what should be the limits on C L and W first let us take L and W these are common sense yes L should be greater than equal to how much and less than equal to how much 5 to 15 every modest house I mean certainly not Bill Gates house or something or Narayan Murthy house may be bigger. Narayan Murthy is in a small house that is true, but not as small as this that is all. What should be the limits on W there is another angle whenever you prescribe limits on such parameters as length and width there is a deadly danger of what you call length being interpreted by someone as width and what you call width being interpreted by someone as length and therefore, it is prudent to put the same limits of check it is prudent like and if you do not like this lower limit of 5 that every house must be minimum 5 meters wide and if you say no it should be 2 it is prudent to change this also to 2. This is just a thought is this a unique answer certainly not anybody else deciding anything else is perfectly fine as long as it makes sense that is why in my question papers you will see make reasonable assumptions in case of difficulties, but state those with justification. So, you have to justify and how do you justify in a program that you write by writing commands the other thing that is missing in this program is commands and these are the commands which will precisely tell a reader all the assumptions that you are making. So, there is no need in a exam situation to write a detailed commentary in English before the questions these are my assumptions they can be incorporated right at the beginning in your program itself get a point fine anything else that more or less sums up. So, we need to modify this program we note to include what all things we include a message to the user both before input and along with output we include assumptions made on this and based on these assumptions we include checks whether the values are valid or not and if the values are invalid we give a message, but do not do any computation will that be fair suppose there is one fellow whose house is exactly 15.3 meters he has calculated it exactly and is giving input because you experts have written a program and now if your message says wrong dimensions of the house if it is my house I will be very very angry with you this is my house I have constructed it and what is your problem it is by point. So, you have to be careful about both the assumptions and you have to be very careful about the message that you give the message must not say wrong dimensions the message should say invalid specifications contrary to assumptions in my program you own up the mistake something of that sort now that English you can decide whichever way you want to use it, but a professional grade program would do this and a mature grade program will do this what you see here on the screen in an exam situation what you do the minimal that you should do is do what is done here, but this minimal will not get you full score in the exam marks because that is expected that you should do validations you should provide messages input output etcetera now those things take time to write and therefore those things should come automatically you should not have to think too much on doing those things, but that will require almost as much time to be spent on solving this question as you spent on writing these basic steps of the algorithm there is no shortcut to it. So, if this had taken say 3 minutes to write writing those things may require 4 minutes, but in 5 to 6 minutes you should be able to get an absolutely correct version of the program a professional get the point that is quickly see how long it takes to write such a program see I am writing a comment on two lines because I did not have space to write, but anybody who is reading it can understand what exactly I mean I am not writing explicit limits as extra explanation why because that will be double work it will be there in my statements anyway they notice what I am doing I am trying to think like you would in an exam how would you think when you are checking multiple conditions this and this or this or this. So, I first wrote and then I wrote or then I said and I am again constructing it to all and then I am saying let me forget it let me write down all the elements of the condition and then I will decide what I want to do. So, I continue writing it further and I leave gaps here now I come back and examine what should I write in my condition. So, can someone help if C is less than this I must get out or so this should be or this should also be or this should also be or this should also be or this should also be or any one of the conditions is true I must get out. So, you see now even if there is confusion I can revisit that confusion in correct mass it has taken about three and half minutes or four minutes to write this with some thinking it should not take longer to you now that is the kind of practice you must do even in such simple problem invariably what happens if you refer to any textbook on programming and you have such problem it will only go by giving you it will say write an expression for calculating this. Now, writing an expression for calculating a given formula is a mechanical job, but solving a problem is a non mechanical job where you have to apply your mind and writing a program is also a work of art where you construct something which is readable which is understandable and which is meaningful and you as IIT students must incorporate these habits and this way of thinking you get my point. So, that is what will be expected we go ahead and complicate our life a bit more we now say that the contractor who does this toiling work tiling work sorry he toys to tile that is ok, but he wants to earn a profit which is natural he has not opened a Dharamshala or something to keep tiling people's houses. So, he would like a profit now how much profit now he has calculated this cost imagine there is a contractor who ask us as great programmers saying please write a program for solving this problem the first problem he gave was this we said ok this is the price purpose then he says that is a good idea, but my dear friends this is the average cost that I have calculated. Now, this average cost is based upon total number of tiles that I had purchased total amount of money I have spent on labour and total houses that I have tiled like this and average cost works out to be like this, but that is my cost now I have to earn some profit in it. So, I say ok what percent profit say 20 percent profit 15 percent profit now he knows that if his profit charge is very high that will not be fair because he also has to do competitive business, but he tells you one thing that whenever he is tiling a small house then for that his people to go to that small house take the logistics etcetera etcetera relatively cost more money than in a large house because large house any like quantity discount as you say in a larger quantity when you do something your overheads are less. So, therefore he says that if the house is small I want to earn 20 percent profit if the roof is middle size I want to earn 15 percent profit and I want to earn 10 percent profit for large houses solve the problem. So, what is the first thing that you have to do suppose I am the contractor what will you ask me would you like to ask me some question what do you mean by a small large or medium I am the contractor I say what your great IIT students you do not know what small big or medium is what kind of students are coming out of IIT the correct question to ask is not this why it is not this because what you are showing is complete refusal to make assumptions that is what you are demonstrating when you ask this question I will not make assumptions the correct question to ask is first I make some assumptions and then I ask the contractor I believe small should be this medium should be this big should be this do you agree do you understand the difference do you understand the difference you are willing to take responsibility and accountability the first one says unless you specify everything I will not solve the problem second one says I believe it should be like that in real life since I am not a tiling contractor and not an expert in housing but my common sense tells me that this should be the classification do you agree which particular question do you think any contractor will like second now that is what I want you to start doing think make assumptions get them validated but don't ask specifications for any real life problem they will not be forthcoming because if you ask me the first question define what is small what is large I will think about it you know small is this much medium is this much large is this much this hands denote in his mind so many hundreds of square meters but for you what does it mean is a good da good tea cows or something like so you see in real life this is required is necessary so let us make assumptions so what is small should be less than so many square meters medium should be between this and this and large should be greater than something okay can I say anything which is less than two square meter is small no less than two square meter is not small medium no no so it is small but is it so what is it that I should check please note I made certain assumptions on length and width I cannot define something as small which is smaller than the smallest length and width and generally we said length and width to have the same parameters as two and two on the smaller side just to ensure that if somebody swaps length and width I will not get into error but in general one of these parameters will be larger and the other will be smaller in unless somebody wants to build a square house which is rather rare in India in which case what should be the parameter for small see this is where you cannot give an instance answer and you are right you cannot give an instant answer because you have never thought like that earlier anything else that you thought earlier you would be able to come back with a quick answer so start thinking like now tell me what should be a small what should be a medium what should be large width vis a vis the assumptions that you have made he is suggesting small is something which is less than 10 square meters medium would obviously be between 10 and 50 and large is greater than 50 this is one classification in general if he says this is my classification are you ok with it it is unlikely that a contractor will say no unless he says that look the housing colony where I have taken this contract is a very different kind of housing colony there could be two extremes housing colony for low income group people where the large house could be smaller than your medium the other one would be the housing colony that I am building is for very rich people then the largest in your meaning he will be the smallest so everything depends on the context and that is why it is necessary not only to make assumptions of course to show that you are able to think but also to validate them with the actual person then validate those inside your program is a difference so having done that there is not a problem for you but how will you implement it so you will have to calculate the area you will introduce one more thing so you will say somewhere in your program you will add somebody called float area then somewhere in your program you will say area is equal to L into W and you will calculate the cost separately as area into C and then you will have an if statement you will of course you will require one more variable which will be say profit and you will now say if area less than something what was the number that we agreed then we just write this as percentage right now what was the other number do you see how if then else ladder is being used do you see that there is a single statement so I need not put a curly bracket open curly bracket close after every after the condition is changed because there is a single statement so a simple if then else if solve this problem and then of course I will have to calculate another thing which is called the price there is no harm if I keep writing float something float something later on rather than inserting something the other choice in an exam kind of situation is to leave that blank and the moment you come up with a requirement of a variable name you put that name in your declaration before going forward so these are some of the tricks to save time now what will you do you will first calculate cost as equal to whatever C or that you have already calculated so what will be the price cost into 1 plus profit by 100 notice that 1.0 and 100.0 is not required because profit is a floating point variable so even if I wrote 100 here this 100 would be converted to floating point integer is converted to floating point so I will get a proper division and this one even if I write it will also be converted to floating point before being added but it is prudent as a professional programmer to automatically write constants as floating point constants if you know the result is going to be in floating although that is not true so this problem is also not a very difficult problem to solve but here again one may make mistakes in doing variety of things one the assumptions so you will have to write assumptions here additional assumptions and the second in the correct sequence in which you evaluate if then else and the or and and that you write in your if statement you could easily make a mistake for example here if I wrote this as or what would happen either this or that profit is equal to 15 either this means even if it is 10000 square meter house or less than this mean it is 0.5 meter square meter house however if it is less than 10 you would not come here at all so this in the L SIF this is unnecessary do you notice that because I have written else if I were looking at each condition separately if if if if separately then all this would be necessary but in this particular case since I am coming here with else what is redundant here can you tell me what condition is redundant in this L SIF I need not write it I would not come here at all if the area is not greater than or equal to 10 so that is imply that is the advantage of if then else ladder but you can choose which way to implement you can write completely independent if statements you can write opening curly bracket closing curly bracket whichever way you want just ensure that your logic is correctly written and I am telling you that in an exam situation in spite of your 100 percent accurate knowledge in your mind you may in a hurry make some small silly mistake here or there and that should be avoided because a professional programmer does not make mistakes or if a professional programmer makes mistake in the second reading of the program which is always done before submitting that program for compilation always not like what I have seen you doing in the lab you you write a program and say C++ and the compiler says here oh 35 oh semi colon missing 58 that is not what a professional programmer you are lucky because you can compile your program in split seconds if you have read the book madhouse which is hostel 4 students had written then you will see there a figure carrying deck of punch cards which had statements like what you write in a g edit today and you would submit the deck of punch cards today evening and go home and tomorrow evening again you come back to collect one compilation run now there you don't have a choice to say oh semi colon oh something every semi colon missing is one day so if you are not careful you may spend your entire semester only trying to compile your program the logical errors will come later as you know so that is why you have to be very careful when you write and therefore you have to read whatever you and in an exam situation whatever be the compulsion after you have completely written a program at least read it a fresh one second okay we make life more complicated now that the contractor is very happy with your programming skills he says great guys they can give me a computer program I don't have to calculate anything he says that look I am getting this contract for tiling work by all the residents of the column now I have my munim has a diary there is a house number link and wait I will ask him to give you that diet now what you do is you calculate the price that I should charge to each of the house owners so give me the house number and the price I should charge I don't need anything else the input information I am giving you is house number width and length and width of the room to solve this problem we should always first like to write a sample data always a good idea to write some sample data to get an idea of what you have to handle in the earlier case the sample data was length width the cost per square meter and the percentage profit was something which was calculated intrinsic into my program here I don't have one house only he is telling me I will give you house numbers and length and width so I will have let's say the data may be suppose I have to input input the house number length and width I will say ok first I will I will find out how many houses you have so it is a 250 houses in the colony so I will like to input 250 as the first number and then press enter then I will put say house number one length is 6 meters width is 3.8 meters house number two length is 7.3 meters width is 4.2 meters house number three say 10.0 5.6 whatever this looks reasonable assumption that the data would be given to me like this now here is the question if I want to read the data and produce the output for every house what is the trialling price then I need to do exactly what I did earlier but I need to do it repeatedly I need to do it repeatedly and I need to read one more thing called house number now which was not there earlier the first value which is being accepted is the number of houses so I will need to add integer n which is number of houses and I will call it h n to mean house number I will have a statement see in I will require to set up an iteration and in this I have to do everything that I have done except in the see out statement I will have now put out something like this so for every house number I will print the price and of course I will have the iteration come concluded for this part I need to take care of putting an end at the end of each line each line there will be one input so this is a reasonably accurate program yeah oh see out would be I he says see out should be I instead of h i because I am running the iteration for 250 times for i equal to 1 to n his thinking is not incorrect given the way we think normally in problems already you have assumed that just because somebody has said 250 is exactly data for 250 houses have you ever done writing down of values in a survey in a in a colony you want to measure the room you go to each house house number one this house number two this house number three lock on the house I do not have data house number four house number five I have taken the Moony m's library that you take and contractor has told you there are 250 houses in this colony the Moony m's library may contain data only for 245 houses and which 245 houses not necessarily 1 2 3 4 5 6 7 that is why there is a house number and that is why another important assumption that you have to make whenever you are dealing with large data that some of the data could be missing so far you had assumed validity of data or invalid now you have to assume incompleteness of it anytime you do any engineering experiment and record the experimental results you will goof up somewhere or the other some data point will be missing that is natural to happen in any human activity therefore you have to read in the house number let me ask you another question suppose all the data was absolutely available is there any need to actually read the house number at all as input no because first will be first house number second will be second house number third will be third house where we are reading it we want to make sure that in that Moony m's library whatever is written house number and dimensions are correctly captured and you will find that in a large diary something will be missing you are required to write library for every day whatever you do in your about your project the diary format has not been put up although I had discussed it here two days of this week have gone have all of you written entries for two days in your personal diary all of you know now what will happen on Friday when your team or Saturday or Sunday whatever is the week in time and your team comes the team leader tries to accumulate all the time one day is missing for this person two days is missing for that person now this is happening in an environment where you are working as professional programmers on a project would this not necessarily happen in a real life situation where Moony m is sending some clerk to go around and get some data so please don't make assumptions about either that the data is valid or the data is complete particularly when the large data this is one point the second point is more important I have set up an iteration which executes 250 times or whatever be the number written here suppose that number and the actual values available do not tally and what will happen I have only 245 sets of values but the number given is 250 what will happen remember I am inputting the data one at a time and this iteration is going on it will of course give me messages give the next house number and this the last house number is quite likely to be 250 actually the missing data would be somewhere in between which I would not but my loop goes on up to 250 times is that fair is that realistic no so therefore what I must do is I must set up a mechanism to terminate my iteration whenever I say there is no more data no question of first saying that these many data points and that is why instead of having my data organized in this fashion I will organize my data in a fashion such that this is not there the data is I will type house number length well house number length well and whenever I have no house number to type I will give you an indication to your program saying whenever I type this value please terminate the program typically such a thing would be minus one since in a single input statement you will be reading three values and you do not want the program to bomb because see in statement encountered some error you will give some values arbitrarily here this is how you will type in your input you get the point so it is it is not fair to make an assumption that the number of input values are predefined such assumption can be made only when the data to be captured by you is actually automatically captured or is captured through some other process validation has been done and this value of number of houses or whatever has been actually correctly calculated for that data and has been given to you such would be the case for example when you read data from an image file because an image file by definition contains the length and width of the image as part of the data that is the nature of the format you do not need to do any validation but in all such cases in real life computing you will have to make some so do you agree that this would be a better way but if this would be a better way how will I run my iteration now so this will not be there instead what will I say while h n the only thing is to begin with there is no h n so whenever you implement any iteration using while you will have to take care of first reading one set of input before the while and then process it inside the while and then before going for the next iteration there you again read the next value so that you always take the condition for a value which is there or not you get the point yeah okay what he is saying is you run the loop for n but if you run the loop for n you are necessarily required to read a value of n to begin with which is what is the assumption that no you cannot do that so that is why he is saying technically what he is saying is correct I can run a for loop and in that condition here I less than equal to n I can also say and h n not equal to minus 1 so combination of conditions either I have to run 250 times or I can terminate if I get a house number as minus both of that is okay the only problem is the reason we thought of minus 1 is because we do not want to exactly count how many data points are there so n will not be there okay so this is this is clear no issues on this now here is a question I have written this program and now I have read it I think it is correct now I type this program compilation is correct and I start executing the program so I give this value so what is that I input this value 1 6.0 something calculates 2 7.3 3 7.3 I suddenly find out oh there is some problem the calculation is not coming correct what will I have to do I have to go back and examine what expression I have written for l n to w n whatever I will go back there then I start typing again I re-execute now the values are coming correctly but suddenly somewhere I give let us say 128 houses I have got correctly inputted data and 128 correct results I have got 129th house that Lallu Munim has written 100 meters instead of 10 meters 100 meters is invalid as per your assumption what your program does shout shout shout return 1 program ends still another 110 houses are remaining now what will you do you say okay program ended here this was invalid correct that value on your paper again execute the program again start typing these values if on an average something goes wrong after you have typed in about 100 sets of values every time you run the program and you have to run the program let us say 5 times how much time will you be typing the data again and again and again and again and again same data which you have on the piece of paper that is the reason why we have this mechanism which ought to be revised which says I should be able to use input redirection and output redirection so I will actually create a file of data which I will call let us say house data dot txt in which I will write house number 1 2 3 4 6 let us say 7 8 12 whatever even if they are missing because they are house numbers now and the values and there is minus 1 I will prepare this file using g edit for once because I do not want to do the Godagiri of typing this data again and again and again when my program works and now suppose my program was let us say price dot cpp then when I compile it I would like to execute it by saying dot slash a dot out less than house data dot that we understand the significance and importance of this operating system feature it is not a c++ programming feature it is an operating system feature which says that instead of collecting the data from c in you can redirect c in to any text file it will read the lines from that text file as if you have been typing data on the keyboard so the keyboard gets connected to this so when you run this program like this your first c in statement will read data here there is a small problem now if you run your program like that you are getting data which you have prepared for house number, length of house width of house what happened to the cost let us go back to your program which you have been extending again and again and again you started by saying sure you will not read L and W now but you will have to read the cost where is the cost you have to therefore remember that the data file that you create will have to contain all the data for which you have seen statements in your program you are reading the cost per square meter separately somewhere in the program and therefore the first entry here should not be this the first entry here should be some cost let us say whatever 252.50 whatever in short this text file should be prepared this text file should be prepared to contain lines of data in exactly the same sequence in which your c in statement should be executed because once you say dot slash a dot out less than here there is no way a c in statement will ever collect data from your keyboard connected now for execution of that problem that keyboard is connected to that input file so you have to make sure that the input file is prepared proper is that obvious any question in this similarly the output that you produce will come on screen now you have prepared a perfect program and now you tell the contractor I have calculated all the values you will say where are the values say oh they were on my screen yesterday night when I executed that program so contractor says my dear friend is this the way you want me to run your business how do I run my business do I come to your computer you at least give me a file on a pen drive or something so you will need to create an output file as well now you are already creating an output on the text and that's the reason why you have the facility of redirecting the output as well something like price oh sorry this should not be that this should be txt and price data dot txt so this is greater than means whatever output would have come on your terminal it should go to a file nothing will appear now so please note that less than and greater than will disconnect keyboard and terminal and connect whatever input file name you have given and whatever output file name you have given these files have to be ordinary text files and they should be prepared such that various lines in that text file contain data which will be read by your c in statements the c in statement is now reading from now do you agree that this simple facility will permit you to give the data from your input collect the data from your output on a file and give that file to the contractor so when you give that file to the contractor the contractor can go through each one says thank you very much that is how you will do business you want us to write a program this you will call it you know what will you call it a billing program for your tiling activities and you say I will generate bills for you you pay me 5 rupees per bill so 250 houses he will say ok 5 rupees instead of making my munim calculate you will do all the calculation but then he will say please don't give me just the list of house numbers and the price give me a bill which will say house number 1 it will say mister or missus so and so and then it will say some text message with respect to the tiling work that I have done in your house I beg to submit my bill total area tiled so much price so much you are sincerely please pay the bill within 10 days and one page bill you can imagine the contractor going with a list and tiling of papers in one small slip saying house number 2 house number 3 house number 4 that doesn't work how will you create such output well you can create it using your see out statements what you have to do is you print the house number you print the text that he wants you print the price how do you go to the next page what is the equivalent of page you have never printed anything on a printed paper you have outputted everything onto terminal what is the notion of a page a computer page you would have printed some documents which are stored in computer files on printers using maybe a word processor like a microsoft word or adobe reader or something like that you do get multiple pages right how many lines are there in a page nobody has noticed nobody is curious but I will ask you a harder question after printing 20 lines you have printed the information about one fellow's bill the next bill you want to come on to the next page how do you ensure that you come on to the next page I will leave it to you I will explain this next time in all word processors there is a notion called page break when you say insert a page break the next line will appear on the next page go to that text file and find out at the point where you have inserted a page break what is the character that is stored inside it will have an ASCII code that ASCII code is an instruction to the printer to go to the next page it is part of the printer's escape sequences will not go into those details but it is possible to do so what I would like to discuss in 5 minutes and leave the thought to you is as follows you are working as professional programmers group and want to make money by writing programs you approach that contractor and told him I will prepare a billing system for you the contractor says 5 but there are two stages first there are houses so I have details about house numbers and the owner of the house the name of the owner of the house then I will give you all that data for all the houses that data will not contain length width anything because this is the contractor I am taking from that colony my munim will first go and take names of the people who live in those houses so he says I will get you one diary of that munim which has house number name of the house and some other details what could be the nature of the details there from a business perspective can you imagine some very creative details normal details could be dimensions could be put there itself but there could be several other parameters every household may say out of the 5 or 6 different types of tiles available I want to put this type of type would you not like to decide that for your house so you will ask the contractor how many different tiles you have he will say this tile madam 1000 rupees this tile 2000 rupees square meter whatever whatever whether it is roof or flooring so the decision by the household on which type of tile he wants to put on now this data is available separately the next data is completed tiling on this house number this length and this width that is in another poti so there are two potis now you have now you have a problem you say see in you are expected to read the first poti which you say house number this and the name of the person is this why it is required because for all house numbers you may have the details of who stays where but for all house numbers you may not have the tiling details because you may not have completed the tiling now the contractor will say look Baba I do 20 houses per week I will give you data for those 20 houses give me those 20 bills you cannot say that complete all 250 because that is how I have written my program and come after 3 months now the contractor will say after 3 months if I prepare the bills and if I give to my clients when will I get my money back I must build them the moment I finish my what I am hinting at is that reading all the data in one stage and solving the problem is not feasible in real life second it is not therefore feasible to have all data in a single file even if you want to use redirection so you will be required to say I will read data which is prepared in one file which is about the owner of the house and the type of tiles he wants I will have another file in which there is data about house number size of the tiling that is required and the date on which I completed the tiling work because if I am giving a bill I should write that date on which the tiling work and there would be a third file or a small notebook in which sundry details like categories of tiles I have pricing or cost for each tile the pricing information that I want etc etc would be given it is very clear that C in statement alone cannot be used because C in will read from one source that source can be either your keyboard or that source can be your terminal but cannot be this file that file that file later on when we consider files in an object oriented environment we will see that files declared as objects can actually use a C in operator in each of those files separately but what is clear to us is input will have to be read from different files and at different positions and I may not write a single program for the billing system I may write one program which will collect all the data about the owners of the houses may be another program which will collect data about the sizes of the roof and a third program which will only collect the date on which the tiling was done and will produce the base so you see what we started with a simple expression evaluation but such expression evaluations always happen in the context of a larger problem and as an important aspect of this course you ought to learn to worry about those larger problems and you ought to be able to solve those larger problems that is why what project you are doing for example taking a larger problem and solving we will stop here but I would like you to read the you remember we had discussion on files there is one more thing which I will just mention here but we will discuss it in the next class on Friday and that is about use of arrays we have not done anything with arrays so far in this revision but you will appreciate that if I am reading data about 200 300 500 houses then it is better to keep that data in arrays for example if I have two files in which house number and name of the house owner then it is best to keep the array of the names of character arrays of two dimensional array and house number then later on when I read the data from another file about the dimension it is better to keep that in some other since house numbers are one to something it is perfectly right if I do not use my array index to start with 0 I will write that 0th element be there without using it so that I am logically doing what the house numbers are done the house numbers therefore becomes an index form that is how you would use arrays we will see how this problem is extended to be solved using multiple files but text files still you still each one of these are text files so they can you can use either 16 statements to read from different files or the equivalent open file statement which is what we shall see in the next class thank you so much