 Today we are going to look at C++ number more closely and introduce a new concept called arrays. We had already seen last time functions and how functions permit us to write a common piece of code or program instructions separately which could be invoked from wherever we wanted. So today this is mostly a revision because all of this you should have understood in the first lab, I will quickly go over it, putting it in the perspective of our abstraction model for our Dumbo, abstraction model for the computer. So how does Dumbo appear to us? What is the memory model, an extended memory model? We have seen how variables are stored etc and how Dumbo interacts with us. But the main topic of the day's lecture is putting multiple data items together. So we will discuss the notion of arrays, we will discuss input-output of values and we will see how array elements are manipulated. Essentially our abstract model of a computer is that of a Dumbo who appears to us through two pieces of equipment. One is a keyboard, one is a monitor. That is what you see when you sit in the lab. The keyboard is one which we use to command Dumbo to do various things and supply data when Dumbo is running our programs. A terminal is one of which Dumbo displays results of various actions, values, whatever. So when we start work on a computer there is a process called booting which we will take for granted today. When you switch on the machine or switch on the terminal or something you will see a login prompt where you enter your login ID and password. Through this our abstract model of the computer Mr. Dumbo responds by showing a command prompt which is a dollar sign. So this is called a command prompt that means Dumbo is ready to receive commands from us. So when we type a command and press enter Dumbo executes that command and usually returns back with the same prompt. This is well known so I am just quickly repeating this. Now the activity which we just described is not carried out by our C++ Dumbo. This activity is carried out by another Dumbo who is actually the main Dumbo. We will call him the OS Dumbo or Operating System Dumbo. This is a new terminology so we will abstract it as a Dumbo saying that there is a thing called Operating System. Some of the names which you would be familiar with for example Microsoft Windows, Unix, Linux the specific version of Linux which we use in our labs is called Ubuntu. The OS Dumbo essentially does all the supervisory work, all the housekeeping functions for the computer for us. For example authorizing and permitting access to the computer we get access only through the OS Dumbo. OS Dumbo also manages files for users. What are files? Well files are things which contain either text material which could be your programs or data or they could also contain what we call executable code. So there are files of various kind. We have not come across this as a data type in our programs yet. Our programs which we write in C++ usually manipulate integer values, double values, float values and so on. But file itself is an object of interest because that is what you create when you write a program. That is what you submit to C++ Dumbo asking him to compile it. That is what you execute the executable version or the translated version etc. These files are not managed by C++ these files are managed by OS Dumbo. And the OS Dumbo manages these files using spatial cabinets which are in real life. They are all familiar with disk drives but as far as we are concerned the abstract model is some kind of a filing cabinet and this cabinet is organized in terms of one or more directories and within each directory there are one or more files. So you can imagine a large filing cabinet. Each cabinet may contain directories which means 4 or 5 drivers and within each cabinet directory there would be multiple files. What kind of files? These files are recognized by Dumbo through a file name and an extension. These two are separated by a dot. You would be familiar with files for example sample dot cpp. So this would be a file which will contain a C++ program. A dot out. You would be familiar with this many times you say dot slash A dot out. A dot out is actually a default file which is generated by C++ Dumbo when he compiles our program. This is called an executable file. So when we give this at the command prompt to the OS Dumbo, OS Dumbo executes that program. At that time C++ is not in picture at all. Operating system is directly taking that executable file and executing it. So this is created by C++ by translating our program etc. There could be multiple files, there could be text files as we shall see today. The commands given to Ubuntu Dumbo which is the OS Dumbo for us are called shell commands. So the dollar symbol is actually the representation of a shell within which the OS Dumbo operates for us. Why is it called a shell? Well as you have seen large number of users are simultaneously accessing the computer. So for each individual user a shell is created and that shell belongs to you or you or you. Within that shell whatever commands you give Ubuntu OS will execute it. The shell commands are often given at the dollar prompt. In the first drop you would have executed commands such as change directory to Cpp or present working directory. So whatever is the current directory you are in. At any point in time in that big cabinet which I described you are within some directory that is called your current directory. You can change that directory by moving around the cabinets but any time you refer to files you take a list of files or whatever you are essentially referring to current directory. The OS Dumbo could execute a command like this g-headed myprog.cpp. Familiar with this all of you would have executed this. What happens in response to this command the Dumbo opens another window. So you have one window in which you have logged in and you have the dollar prompt. Now another window is opened and in that window our Dumbo runs the editor. Using that editor you can change the contents of a file typically your program files or data files or whatever and when we edit and save our program you have to come back to the original window to give commands. This command c++ myprog.cpp minus or myprog. This command will actually tells OS Dumbo to bring in the compiler Dumbo who is another assistant Dumbo to the main Dumbo who compiles our programs, creates the translated file and instead of giving it a default name a.out it gives the name myprog because that is the name we have given. We could have given any name of our choice. Eventually we give the same name as the program name without the .cpp extension. All this is I think familiar. This is just a quick repetition of our abstract model of the computer. As I promised eventually we will look at the computers in details including the hardware including the memory including the disk and so on but for the time being this abstraction is good enough for us. But this clarity was lacking so far so I thought I will include this. So the OS Dumbo is actually the main Dumbo. There are several assistant Dumbo's. These are variously called as editor Dumbo, compiler Dumbo, database Dumbo. Amongst compiler Dumbo we have seen c++ Dumbo but there could be a full-run Dumbo, cDumbo whatever. There are assistants who are basically multiple compilers. Most of these functions are called software functions because these are nothing but programs written by some other people made available to us as a part of the entire computer abstraction. So the assistant Dumbo which we use most often to compile our programs is c++ that's it. I hope that brings the clarity in the conceptual model at least. Let's go over to motivate ourselves on the need for what we call a new data structure. Here I have written a program which is a simple program. All of you would be familiar with that. This essentially says find out the largest of three given values. So we represent three given values by some arbitrary variable names v1, v2, v3, v4. Let's assume they are all integer numbers. We want to calculate the maximum of these three. So we define another variable an object called max which will contain the largest value. And you can see very clearly the algorithm is very simple. You start with assigning one value v1 to max. And then keep checking that max value with other value. So if any other value is greater than max, for example if v2 is greater than max, you will assign v2 to max. You will also check it with v3. If v3 is greater than max, you will assign v3 to max. You will agree that at the end of these three steps, whenever I come out, max will contain the largest of three values, very obvious algorithm, no confusion there. Please notice that I have not used open brasses, closed brasses after the if statement. And that is because there is only one statement to be executed after if. So I don't need the brasses, although that's not a good programming practice. How do you find the largest of four numbers? Extend the same logic. Instead of v1, v2, v3, you say v1, v2, v3, v4. Exactly the same sequence of statements, one more statement added, you get the maximum. How will you find out the largest of 25 numbers? v1, v2, v3, v4, v25. How many statements? Max is equal to v1, then if max greater than v2, etc., 24 comparisons. You still have to do 24 comparisons anyway, but you have to write down instruction for each comparison. How do you find out the maximum of 2500 numbers? You have v2, v3, v2500. How long will it take to write the program? Instead of writing the program, you can find out the maximum directly by looking at the values. And what will you do if there are one million numbers? Obviously, this is inadequate. You cannot get anywhere using this model. And therefore we need some representation of collection of large number of values which we can deal with more effectively and efficiently. So we construct an additional abstraction which most of the programming languages provide for. We shall see that abstraction. That abstraction is called arrays. So just like you have data types which are simple variables and data types which are integer, float, etc., so far we have seen you have declared integer one variable x, y. These can hold one value. Array is a notion which can collect, which can collectively use multiple values. So this is in brief, this is the need for handling multiple values where situations where we need to handle multiple values of a similar kind, the key is similar kind. Not saying one value is integer, one value is somebody's name, another value is somebody's address, third value is a floating point number, etc. We are saying value is the same kind. We cannot define and use different variable names for each of these values. Firstly it is inconvenient as I said v1, v2, v3, v4, how long will you go, 2500, whatever. Secondly it may not be possible for us to write exactly the number of values. Suppose we know that there are maximum 100 values, but today I want to find out maximum of only 25 values. Now I might define in my program v1 to v100, but I should not use anything beyond 25. Imagine the program which I had written to find out maximum of 100 values by defining variables v1, v2, v3 up to v100 and then I am required to read value n which says number of values. Suppose n is 25, what will I have to do? I will read only v1 to v25. But in my statements what will I say? See in greater greater v1, see in greater greater v2, how will it stop after v25? So after each see in I will have to say if n is some count and if count is greater than n, get out. And I have to do it after every read, after every comparison which is nonsense. I cannot write so many instructions by hand. Additionally we may wish to manipulate matrices. All of you are familiar with matrices? It is part of your syllabus in 10th, 11th, 12th, whatever. So you know how to multiply 2, 3 by 3 matrices for example. You know how to find inverse of a matrix? Wow! That is advanced maths. But if we want to manipulate matrices, how do we store matrices? 50 by 100 matrix. How do we store it? We have no mechanism. So we need a mechanism which is called arrays. We begin with a one-dimensional array. A one-dimensional array is an abstraction say of 100 integer numbers containing some n numbers. Let's say n is equal to 6. I have tried to show what would happen if I gave variable names as we normally do. A1, A2, A3, A4, etc., etc. And let's say A1 is 53, A2 is 79, whatever. I have only 6 numbers today. But I might want to deal with 100 numbers. So in my normal parlance I would declare 100 variables and use only 6 of them today. Tomorrow if I have to use 25, use 25. How exactly I will write my program? It is unclear. Because as we saw we require a lot of statements with different after each variable name usage and so on. We don't want to do that. So instead of these variables I want to declare A as an array which is collection of 100 elements of similar type. In C++ the way we do it is we define an array name. Let's say A. And we use an index to refer to a particular element of an array. Very much like you do to refer element of a matrix. So usually you would say xij to mean i th row j th column element. If there is no column then the row xi. In a vector that is what you would say. Xi means i th element of that vector. So one dimensional array is nothing but a vector. Or a one dimensional matrix. There are some peculiarities with C++ unfortunately. The peculiarities are that ordinarily when referring to a matrix or a vector we start indexing from 1, 2, 3, 4. So if there are 6 elements A1 to A6. C++ starts the indexing from 0. So the first element is called A0. Obviously if there is a 100 element array the last element will have index A99. Additionally so the way you refer to any element of array is by saying A0 or A5 or AI. Now that is something which is unique and very important. So the index of an array element need not be a constant value. That is what permits us to use our favorite iteration to move around different elements of an array. You can see for example that whenever I make a reference to AI. For example I say input AI. Or calculate x is equal to y multiplied by AI. What will be the value of AI? That will depend upon the value of AI. As one it will be second element of AI. If AI is 0 it will be first element of AI. If AI is 25 it will be 26th element of the array and so on. So whatever is the value of AI that particular element in the array is what is being treated as if that is the variable value which I am using in whichever expression. It need not be a simple index like AI. Obviously the index should be integer. It doesn't make sense to have A2.5. You agree? There is no 2.5th element or something like that. There is a 0th element, first, second, third and so on. I can say A j minus 5. So whatever is the current value of j, let's say j is 37. So c plus plus number will calculate 37 minus 5. We will arrive at a value 32 and we will go linearly element 0, 1, 2, 3, 33rd element. So we will pick up that element and operate upon it in whichever way you use it in the function. What happens if index value is less than 0 or greater than 100? Remember we said we have an array with 100 elements. In fact, I should say not greater than 100 but greater than 99. Please correct that in your notes. What will happen? Any idea? Any guess? What should logically c plus plus dumbo do? C plus plus dumbo should tell us that you declared an array of 100 elements. You are asking me to access minus 5th element or you are asking me to access 113th element which I can't do. Unfortunately, dumbo is real dumbo. It does not say sorry. What it does is very peculiar. If the value of i here or j minus 5 or for that matter any index is negative. Let's say it's minus 1. What dumbo does is whatever memory locations dumbo is using for this array from here to here, dumbo will simply go to this location if index is minus 1. It will go to previous location if index is minus 2. It will go to still previous location if index is minus 3. If index is 125 it will go further and it will go to subsequent locations. What would the previous locations and subsequent locations in dumbo's memory contain any idea? We don't know because we do not know that if we have declared 25 variables and 2 arrays how exactly dumbo is going to allocate memory drivers to these many variables. For all you know I might have the value n as a variable which is assigned just before beginning of this array. In fact, as we shall later on see my program itself when it is compiled and converted into what we call binary executable instructions. These instructions are also stored in the same memory drivers whether earlier or later we don't know. Potentially then by making an assignment to an index value which is arbitrary and wrong you could destroy the memory space of dumbo and you will have what is known as a program crash. Because even the operating system won't figure out what is this dumbo doing. Going somewhere else, opening some drawer, putting some value. Not intended. This is a lacuna which sadly remains in C++. What it means for us is that we have to be careful. When we write our program we must not allow the index value to fall below 0 or to go beyond whatever has been the limiting value that you have declared. So if you have declared an array of size 100 then the index must be between 0 and 99. Is that clear? That's our response. Using the array now I find the maximum of n numbers. So here is the solution to our v1, v2, v3, v2, 2500, whatever. I have assumed that I have at most 100 numbers at any time. The actual number of numbers which I have to compare to find out the maximum is given by let's say some value n. So look at the declaration in the int main which is the main program. Int a100, max, n, i. A100 is the array a of 100 elements starting from 0th element to 99th element. And each element is in its own right an equivalent to a variable which is an integer variable. The program begins by reading in the value of n. You can of course jazz it up by saying c out, give the value of n, whatever, whatever. Then I am setting up a loop. An iteration which says for i equal to 0, i less than n, i plus plus. Everybody familiar with this iteration? It will execute the following instruction effectively n times. It will start with 0 and it will go up to n minus 1. Because I have said i less than n and not less than equal to n. This is important to remember in the context of arrays. Once again I will repeat the array index will range from 0 to 99 if the array size is 100. And therefore every value that I read into an array element, the array element must have an index between 0 and 99. The for loop essentially does that. C in greater greater a i. Instead of a variable name I can say c a i. Remember the great advantage of using this simple abstraction. Instead of n different instructions, where n must be known to me precisely, 25, 37, 2000, whatever. Instead of writing 2500 instruction to read values, I write only one instruction and ensure that Dumbo reads a value and keeps it in a different drawer. And all these drawers are adjacent and all of them are collectively called the array. So this simple mechanism permits us to read the array. Having read the array I have to find out the maximum. And I use exactly the same logic that I used in finding out maximum of 3 numbers or 4 numbers. Namely, I assign the value of the first element of the array to max, which is supposedly my maximum number. So I assume that the first element is maximum. And I successfully compare this max value with the second, third, fourth subsequent elements of the array. Because I am using an array, I can refer to subsequent elements through an index, which itself I can iterate through an iteration loop. So I have another form loop. What does it say? For i equal to 1, i less than n, i plus plus. Same iteration? Please note that I am starting with i equal to 1 and not i equal to 0. Why? The 0th element I have already accounted for and assumed that it is the maximum. So I need to compare that element with first, second, third and nth element. That's what I am doing. I compare if ai is greater than max. I said max is equal to ai. That's it. When I come out, maximum value is max and yeah. He has caught a programming error. It's not a programming error, but it's not a program. The question I will repeat is saying what if n is greater than 100? Then we will have fun. So what should we do? See in greater greater n, follow it immediately by saying if n greater than 100, see out, shout, shout, shout and terminate. Else do all this. Very good point made because we have already said that it is our responsibility to ensure that array bounds are not exceeded. Yeah. He is saying that if I want to have an array of n elements only, then why I can't define it a n instead of 100. Is that right? The answer to that question is the compiler has to know how many drivers to reserve for that array. Please note that only when the program is executed, I am reading the value of n. N could be 25 today, 300 tomorrow, not 300, 99 tomorrow, 28 day after tomorrow. I do not know that value in advance. And there is a mechanism which we shall study later which is called dynamic memory allocation. But as far as C++ arrays are concerned, they have to be declared having a fixed size, having a constant value. In some books you might see a reference to something which appears like a variable name. It will say integer int a n max. But n max would not have been declared as an ordinary variable. It would have been declared as a constant value and would have been assigned within the program before you declare this array. We will go through those niceties separately. Suffice it to say at this stage that array sizes have to be frozen at the compiled time as far as we are concerned. And the reason we understand logically that the C++ dumbo while compiling this program has to allocate those many drivers for the array elements. And if it doesn't know how many drivers to allocate, it will get confused. We do not permit that. So the array sizes must be given fixed. Yeah. Another question. If I have an array as a, can we use the same name as a variable? What is your name, young man? Ketav. Sorry? Ketav. Ketav. How would you like if there are 45 ketavs around? And if I say ketav, nobody really knows who should do what. So the fact of life is that we should never even think in those terms. In fact, if we have used one name, it should be cyclosand. It should be meant for only that purpose. You would have seen that in several different functions or even within a same program, we use the same name differently. If you ask me, that's very bad programming practice. Unless that segment is physically separated out. And C++ knows that this name means this only here. So technically correct answer is that if I have used an array a as int a 100, I can use the name a elsewhere, but within the scope of this particular program. It must be in some other scope. Where another assistant Lambo who executes that function knows that that name means something different. However, the best way would be to avoid using such names. We can have a one hour debate on the intricacies of C++ compilers. How it could have confusion? Because any name that I use as a variable will not have an opening bracket, closing bracket and an index there. That is his observation. So as I said, we can have a one hour debate on this. For that time being, our Lambo, let's stipulate that it doesn't permit such nonsense. So as far as this course is concerned, we shall not do that. As far as C++ is concerned, you and I together will discover what happens when we do that. In fact, in one of the lab sessions, you might try to do that and see what happens. It will be worthwhile. This debate is interesting, but it also should tell us something. We should not do something just to check whether that is legally correct or not. It should also be ethically morally correct. It is bad ethics in programming to use the same name for any purpose other than what it is intended. Bad programming practice, period. So likewise, when we have human names, you don't have human names as ABCD, right? What will happen if your name was 2k instead of ketam? Sky will not fall, but your parents won't like it, your friends won't like it. Similarly here, the other readers of the programs that you write will not like that at all. So remember, we write programs not only for C++ Lambo, but also for our colleagues who will probably read those programs and use them. And it is important to be decent to other human readers of the program. I think that's a good deal of explanation. Fine. I introduced the notion of a file of records. You will notice that on a piece of paper, I will often write roll number, name, hostel number, room number. And I have this piece of information. So roll number here, marks here, name, hostel, room. I would like some mechanism inside my C++ to represent such records in a file. What I mean by record is actually one line of this file. This is a text file. You can use g-edit to create a file, right? You need not write the header columns which are written at the top. Actually the top header columns are called attributes, and they represent metadata for this file. Metadata means data about data. So if you read this particular row, the first number is roll number. The second number is marks. The third string is a character string representing the name of the person. The fourth number is hostel number. The fifth number is room. This ordering, first, second, third, fourth, fifth are these, these, these, these. This is called metadata. You will agree that this metadata which is written at the top describing various attributes is identical for all the records in the file. No matter if there are a thousand records or five thousand records. You can see now that thousand such records are good candidates for us to use in an array of records. But right now we do not know how to handle array of records. We do not even know how to handle a record. A record in C++ is called a structure or a struct. We shall look at it in due course of time. This is just to introduce the notion that multiple values need not be one value, one value, one value and multiplicity of them. There could be multiple records of this kind. Where each record has multiple values in some ordered sense. Of this, we pick up only a part which is roll number and marks. These are not our roll numbers. We assume some Bombay University or Pune University roll. 1001, 1002, 1003, 1004, 1006, five is missing, whatever. And let's say these are marks in a class test. Now I want to do something more complicated than what I did earlier. Earlier I read n values in an array and find out the maximum. Now I don't want to give values by sitting at the terminal. You will agree that if I have to give thousand values. And if I make a mistake in the program, I correct it and again I have to run it. Again I have to give thousand values. That is madness. I would rather prerecord these thousand values somewhere and let the computer read these values automatically from that somewhere. That somewhere is a file. We are all familiar with file. Our programs are written in a file. So let's say I use g-edit to create a file like this, which I have arbitrarily called roll marks.txt. So it's a file which contains, which is actually containing text, various lines. Roughly each line is a record. For us, each record contains two integer values. First integer value is roll number. Second integer value is marks. You will agree that it would be very nice if I had such a file and I could make my CPP Dumbo read all the values from this file and put them into two arrays. Let's say one array called roll number, another array called marks. If I could get this, then I could find out maximum. I could do this, I could do that, whatever. Let's say I've got information inside my arrays, which is inside computer memory, that is fine. The file, however, is not inside computer's memory. It is in those cabinets, in one of the directories. The file name is roll marks.txt. I will now show you a program briefly to read this data into arrays. I include iostream and I include fstream. That's a new include statement. Actually C++ Dumbo is very clever. It has an assistant which handles streams or files, external files. We will not go into the details of what fstream means, etc. We are just going to take things for granted. So there are certain statements that will appear in this program which we will not understand at all as to what they are doing at this juncture. But we will take them as given to use them for our purpose. Look at the int main here. I have declared r and m as two variables. Obviously, these are the variables in which I will read one value at a time from one record. And I have declared an array roll 100, array marks 100, and n students as number of students. This particular statement, if stream my file roll marks.txt. This is actually a command to C++ Dumbo saying in my cabinet, in the current directory, please locate a file called roll marks.txt which I have created using GAID and open it for reading values in. If my file dot is underscore open, very cryptic. But I think you can guess what it means. If the file is open, then do the following. But if the file is not open, then get out. Why would file not be open? File could not be open. For example, because in my current directory, there is no file called roll marks.txt. I have sadly stored it somewhere else. So C++ can't find that file. Or let's say that file is obliterated. It has crashed somewhere. So it can't open the file. You can't open the file, you can't do anything with it. So you test it here. However, if it is open, then do the following. Set i equal to zero. Check if file has ended. E OF means end of file. Again, we don't know what exactly it means. But we know that when I'm reading from a file, I don't know in advance how many records that file has. It could have 28, it could have 30, it could have 45. But I know that when Dumbo tries to read records from that file, sometimes the records will end. When the records end, the file manipulator which is the OS Dumbo tells my C++, sorry, no more records. File has ended, that is called end of file. And fortunately, Dumbo can sense when the file has ended. So while file has not ended, do the following. My file greater, greater, larger, greater, greater. Look at the syntax. Isn't it very similar to CN? Instead of CN, which reads from your terminal and keyboard, you say my file greater, greater, larger, greater. It will read these two values from a single line, R and M. Notice that the values were exactly ordered like that. First row numbers and marks. I will now check, again, has the file ended. Funny thing about C++ is, even after the file ends, it will give me some junk values. But it will set some flag saying file has ended, ignore these values. I'm using if statement to do that. So if the file has not ended, that means I have legitimate values for R and M, I will assign them to row and marks R and M. Row line is equal to R, marks I equal to M. And now I will say C out, I, row line, marks I, ended. So in one iteration, I have read one pair of values, assigned it to two respective elements of row and marks, and I prepare for the next iteration by saying I plus equal to 1. Which means increment I. And after incrementing, I go back to the file. Keep doing this again and again and again. No matter how long it takes, as long as the file does not end. Of course, I have to make sure that the file does not contain more than 100 elements, otherwise there are chaos. At the end, when I come out, when the file has ended, I use a command called myFile.close. It's basically telling the operating system Dumbo, I'm done with this marks, row, marks, text file. Please close that file and close that cabinet. Now I know N students is equal to I. Whatever is the last value of I is N student. Remember, I started from 0. So the last element, if I had 25 values, would have been 24. But I would have incremented I for the next iteration. I would have become 25 when I would have come out. And there are exactly 25 students from 0 to 24. So this is how I assign N students. If the if statement at the beginning does not work, I say else see out less less unable to open 5. I return 0. Is that clear? The file handling may not be clear at all. So don't bother if you don't understand how file is being handled. It is adequate for you to understand that there is a function which can open a file, read data and put it in two arrays. In the next program, I have to show, okay, this is one when I execute readRollMarkz.cpp. So I give a command C++ readRollMarkz.cpp. It will compile the program. I say dot slash A dot out. And this is what will give. And I roll number Markz. And at the end it will say number of students in these arrays is 7. So this is the mechanism very simply created for you to have a collection of values which you don't have to stupidly keep in putting every time you execute a program. But you can write those values in a text file and make the CPP. Don't read that file any time you want to fill up there. Here is a program to find maximum Markz. You can notice include IO stream, include f stream, et cetera, et cetera. Here is something I am defining. Int getData int R int m. What is this? This is a function. I am going to use this function which are the two parameters of this function. There are two arrays called R and m. No sizes are given here. They are not required when I pass array as a function parameter. This thing returns a value int. It returns an integer value. We shall see how we will use this integer value later. In the main program to find out maximum Markz in a class test. Suppose those were the Markz in the class test. Int roll 100, Markz 100, N students. This is my program. Int max i. Now this is a very, very vital step. N students equal to getData in brackets roll comma Markz. I mentioned to you that getData is the function. In fact, the previous program which we wrote to read all the Markz can be written as getData function. There we are reading the Markz in two arrays. These are the two arrays roll and markz. We are passing to getData these two arrays which are currently blank. They don't contain anything. We expect getData to read the file, fill up these. But wait, it is actually returning a value which I am assigning to N students. So obviously that program I must modify. Where I was just printing the last value of i as N student. I must now return that value as the value of the function. And the value of the function is now being assigned to N students. We shall see multiple ways of doing these things. Suffice it to say at this stage is I could convert all reading, writing, Ghoragiri into a separate function. Let that function to that task. Prepare my data file 1, 2, 5 as many as I want. And write this program. The program is maximum marks are marks equal to 0. For i equal to 1 to less than, if there are N students, then the last element will be N student minus 1. If marks are greater than max, max is equal to max i. And I find out c maximum score is max marks. One quick question and we'll end this class. How do you find out the roll number who scored the maximum marks? These are the statements. Here I have put an opening brass here. If max i is greater than max, not only I assign max i to max, but I also assign roll i to max row. I am presuming that there is only one student who has got maximum marks. The program runs chaotically if there are five students who have got the same marks. We shall see how to handle that in one of the labs or tutorials. And now I can print out maximum score, max, marks, score by so and so. If I execute this program, this is my function get data. I will not go through it. If I execute, which program I call, find max roll marks. So please note that this is the output which is generated by the reading function. It has read all these values, says number of students in these arrays is 7. And maximum score is 91 marks. Here score by 1003. So this in a nutshell is the notion of an array and how to use those arrays and how to manipulate those indices. Thank you.