 Catch a mĶa, mĶa ā8a āVimāscis Ākāā …. So letís say a set of programs have been developed, ṣaĀsa your project develop. ἔνα learned the project word  socied string alone application ln which case any program that is ever required to do anything continent of that package itself in that case that programming package never needs to interact with any other package or any other program but that is not the case invariably any programming system will either require to invoke some additional functionality from some other programming system or will have to provide a link to itself to an external programming system so that somebody outside can invoke a desired functionality from my programming system. Such is the case that all pieces of software all over the world might need to talk to each other and talking to each other does not mean talking in a conversational sense but being able to invoke functionality from within a programming system. So suppose we have a set of programs how do I invoke one or more of these programs from my program. Every piece of software is built with interfaces so at the interface level you expose the package to the rest of the world saying look I might have 30,000 lines of code maybe 200 functions all kinds of data structures 50 files whatever whatever but there are three or four things which you might want to use which I have already coded so how would you invoke a function from my package. Observe that so far all the programs that you have been writing including n number of functions that you might write are all monolithic programs everything is contained within so you write the functions also within your program if you don't like to write the functions ahead of the main program we have seen how prototype can be declared at the beginning of the program and then the actual function code can be written later because without the prototype definition at least if I call a function from within my program the compiler won't understand what I am calling so it must know what is the prototype of that function. Of course later on when I compile my program my functions also need to be compiled but suppose somebody has compiled these functions separately he says I won't give you the source code but I have the compiled version this is the prototype of the function go ahead and call this function now if I want to do that I must make that compiled version of the function available to the compiler linker system saying that look this is my program these are my functions additionally I might be using functions such as this this this which come from somewhere else I don't have the source code so I can't give those functions for compilation to you but I have the compiled version of those program these are typically in the form of libraries they are compiled library so I say compiled libraries are available so please first compile my program after you translate it when you link pieces together also link the translated version which are pre-prepared already available of those functions and put all of them together and create an executable file that is usually what is done in real life in order to use libraries of functions but whether you are using libraries of functions which are to be linked explicitly while you compile and link your program or whether there is a completely independent system to which you want to make a function call by perhaps sending a message to that system or something like that in either case you need to know how you will interface your program with some other program or how others will interface their program to your program all such interfaces in the hands of the application program application program is people like us who write programs to implement certain applications for us such interfaces are available they are known as application programmer interfaces or simply APIs and these are APIs are essentially as we will see essentially the definition of functions which are available what kind of parameters are to be passed to the function and what kind of return value we will get let's just have a re-look at the use of functions so recall we define structure student info, care role 10 etc etc this is the definition of a student's information then we have a function prototype here it says wide print student data struct student info we are not writing the function here the function would be written somewhere else the reason I am putting a prototype here is later on I will say that even this prototype may not be written explicitly by me it might have been put somewhere else but the point is once I include this structure definition observe that this structure definition is before the int man just as the function prototype is also before the int man so these are called global declarations that means my entire program can exist any one of these in fact the top lines which will soon understand in a better fashion include IO stream, include CST delay are also considered global declarations because they are outside the main program they are available to everybody so this is the standard way in which we use that in the main program of course I might declare a variable called as with structure student info and then I can do whatever I want to do and I can invoke that function that I have written the alternate way is that the student info structure which I had defined I need not actually include it physically in that program I could put that in a separate file and let's say I call it student info dot H dot H is a standard convention in CC++ system to describe a separately created header why is it called header because it is usually it appears at the head of any program function or whatever so if I create a separate file I can tell the compiler to include it in my program that's the whole point that physically that file is separate which contains that header currently we are talking about a header which just describes the structure student info in which case I can do that by using an include macro so this is the include statement that I will write here hash include student info dot H when I say this the way the compiler is all set it first locates this file and physically put the contents of that file here then it gives everything to the compiler needless to add it must be doing exactly the same thing for the other two include statements that I have and that is exactly what is done if I have components of my program which are required for proper compilation and linking but they are not physically put in the same file then even if I put them elsewhere I could give an include command this is called a pre-processor command a pre-processor meaning even before compilation when you say C++ something before compilation the C++ system reads your entire program and resolves such references as include and whatever whatever so it collects information from other files put it all together and then sends the whole thing for compilation so these could be macros, these could be includes these could be whatever else essentially the final source code which is compiled is not just the one that you have written but an expanded version by inclusion of such files why is it written like this whereas these are written separately or differently any idea ok this means that the student info.h is to be found in the current directory what is the current directory in whichever directory you are issuing a C++ command where your program file itself is program.cpp in the same directory you have this file so when you have that you simply put that is double quote as a filename and the filename is expected to be found there of course the file could be somewhere else in which case it is possible to prescribe the whole path why don't we prescribe the path such as iostream, cstdlib etc 2 reasons one these are standard C++ libraries so when the C++ system of compiler linker etc is installed on your machine the paths are automatically set and unknown to C++ C++ knows where it will find standard Cstdlib where it will find iostream etc but there could be other libraries which as i said some package somebody else has written we are going to discuss the eased windows package but there could be any other pack so if there are other libraries i must indicate where these libraries are to be found these paths are indicated through the commands that we give for compilation and linking by saying that when you convert my program into a .o file or translated version called object file and later on when you link it please link it with this library, this library, this library because in this or this or this or this library you will find the references such as iostream, cstdlib or any other library names that we mentioned so is this understood this mechanism pretty simple and straightforward you may want to experiment with path and such things incidentally there is a variable i think i had mentioned it once there is a variable called path variable which is part of your computing environment when you log in you have a file called .bashrc which stores the initialization of all these operating system environment variables this path you can get to see the path by giving a command echo dollar path any operating system variable when you want to refer to its value you said dollar something something so when you say this you will get to see the path the path is separated out by colon so you will have for example slash usr slash bin colon slash usr slash include colon etcetera etcetera this path is nothing but identification of separate some directories and directories in the file system in which the command that you give here is to be located so when you say c++ for example where is c++ so c++ will be found either here or here or here or here or somewhere since the current directories usually not included by default in this when you say a not out nothing happens because the machine cannot figure out where the a dot out is and that is why what you are required to say dot slash a dot out when you give this command you are telling the machine that don't search through the various sub directories of path the command that I am giving you is to be found in the present sub directories itself and that is why you said dot if you don't want to do that you should include dot in the path and the easiest way is to extend the available path let me just give you that command because it's a very easy command to use at the dollar prompt you can simply say path equal to dollar path colon dot that means whatever is the value of path put a colon after that and put a dot after that and then you have to say export path after you do that you can simply give the command a dot out you don't have to say dot slash a dot out I hope you have figured out why because that dot is now explicitly included in the path if you wish you can put these commands by editing the dot bash rc file which is the file which is executed automatically and it creates all these paths and other environment variables so that is one possibility anyway incidentally many of you will find that this dollar symbol is preceded by things like machine name and directory name and such things so quite often when you go to sub directories and sub directories your prompt itself comes out here and the command that you write invariably turns out so in order to simplify the prompt you can use a simple command called ps1 equal to say dollar if you say that from this point onwards you will find the prompt to be exactly in the leftmost corner it will never be preceded by any other trash of course you won't automatically get to know which sub directory you are in etc etc but this makes for a simpler reading of the commands that you try ps1 incidentally stands for the prompt the prompt string that should appear instead of it showing you variety of things you are telling the operating system that look I am comfortable with just one character prompt and that's all you show me these are anyway some side issues let's get back to our discussion essentially then the preprocessor will take care of these things so as I was saying what if the functions themselves are written somewhere else what we saw in the previous screen was if the header file is written somewhere else the header file which was defining the struct info which was essentially a data structure now just as there is a data structure there could be also a function header such as the prototype now that is a character string exactly is to be included as it is that could be included with this idea of .h however if the functions have been compiled and kept in a library I cannot just say .h and include because they will not be header files they will be compiled version they will be object files we need to do two things essentially one is the function prototype as we said apart from the data structures that we define and we need the translated version of those functions which we wish to use but which we have not written they need to be linked with the translated version of our program and that is where we need to include library files in precisely for this reason and this method is essentially an API so the .ez windows package which we are going to discuss or an .erp package which is used in real life any number of package any package that you can think of a high precision arithmetic package somebody has written what it means is that person would have written some .50 odd functions compiled all of them and kept them in a library and then say that if you want to multiply two high precision numbers invoke this high precision multiply function so I need to know the prototype of high precision multiply function alright but I also need the translated code high precision numbers do the algorithm and calculate the result so I need to invoke it and link that function these library files in unix environment typically take the form of .a files called the archive files or .so files which are called the shared objects the shared object is effectively equivalent to what some of you might be familiar with the .dll files which are the dynamically linked libraries in the Microsoft environment they are all similar so they all permit you to create packages and use them in any programming environment what we are discussing is how to use these in cc++ environment but they could be used in any programming environment exactly the same fact all standard libraries of c++ provides such interface and that's the reason we say this hash include whatever library so now how many libraries do we include depending upon what kind of functions we are using in our program so if we are using let us say we are handling string functions string length now we know where that is that is in the c string library so we have to say include c string we are using c in c out now we know that is in the io stream library so we have to include io stream it is not uncommon to see a program of a reasonably complex software would have something like 20 include statements perfectly fine now there is one more package which we take for granted the operating system itself we never look at operating system as a package operating system is in fact the environment in which we are working but we should not forget that that is also a package of software there is also a set of functions and so on now that package is interacting with us remember when we say we execute our program what do we do we execute our program means the operating system we are trying to tell operating system please run my program so the operating system must have an api for me both for it to invoke my program and for me to use some functionality of the operating system within my program if I so desire such interface is called the system level interface and all the functions which are intrinsic functions of the operating system not of an external package intrinsic functions of the operating system these intrinsic functions are invoked using what is known as systems cause so all the OS functions they are called system cause rather than function cause so system cause means system functions which are part of the operating system they have to be used next we discuss the topic of random number generation how many of you are familiar with pseudo random numbers random numbers everybody is familiar with no not much ok everybody has played some kind of a board game where you throw a dice and you get any one of the faces 6 faces so 1 2 3 4 5 6 this next 10 ladders whatever whatever n number of place practically everybody has played that when you throw a dice dice is assumed to be a normal dice meaning that any one of the 6 numbers can come with equal probability when such is the situation the number so generator is called a random number the fact that they are equiprobable cannot be ascertaining by throwing the dice only for 1 or 2 or even 6 or 12 types for example if you assume that if I throw it 6 times one should come exactly 1 2 should come exactly 1 etc that will not happen but if you throw it 6000 times then roughly 1000 times 1 will come 1000 times 2 will come 1000 times 3 will come and that is why these numbers are known as uniformly distributed or equiprobable random numbers if you want to implement any board game or a game of chance or if you want to simulate where the events occur at random times then within your program you need to generate random numbers consider this in our simulation of large data we had arbitrarily taken serial number as roll number from 1 to 5 million but imagine if I were to actually stuff in the information some domain let's say language spoken now there are 20 languages and there are let's say 5 million participants in my portal I want to test my software so I want to create realistic data so I have to generate random numbers to allocate different languages to be spoken by the artificial students whom I have generated and that means I will have to take these 20 languages and allocate one language to this person another to this again that to this and this must be done randomly but in a uniform fashion I need therefore the mechanism to generate random numbers now any random number that we generate with an algorithm cannot strictly be a random because randomness depends upon the fact that there is no algorithm so therefore such numbers which are generated by computer algorithms are called pseudo random numbers there are articles and research papers on how such random numbers are to be generated we are not interested in that but we want to concentrate on using such numbers if they are generated fortunately there are other classes and this standard libraries of almost all programming languages will provide a function which will generate random numbers for you a function called rand which is available rand function generates random numbers between two values 0 and rand underscore max this rand underscore max is also defined in one of the header files it is typically the largest unsigned into the namb ޚප ම්ඳඇයකප දේඵත්ලරීමන්න්ත්, කසලත්න්ය එය මභෙලයක්ත්ලි,වකක්ත්යක්යක්,වකරය මභෙලේතය්නත්නන්න්රමක්මරීමදතික්ත්ර මභෙලේ්රමක්ම්න්නන� Ḙ トギ Ḝflies Thrillion times , 5 000 times 20, 000 times you will be able to demonstrate the uniformity we shall see how it can be done The point is that Okay your program is executed for your purpose you have generated some 527 random numbers they have come, you have run your job let's say simulation Tomorrow you run your program again because the algorithm is same Exactly the same sequence Sa. There is nothing random about the second execution also to be different. For this purpose most random function generated libraries will provide for you to give a what is known as a seed or a seed value or a number which is the starting point of a sequence of random . genuinely if you change the starting point the specific sequence that will be generated and there is a separate function పటకపెనే నావార్లిందిసిసి పతిన్ట్టాదియాల్లూతౌనాస్ పనినిమావమిండి సరిమాస్మ వెలలిద్కతినండల౪౏స్ఫ్రన ground も fill నిభాయచాయానథ౦ిస్ environmental ధైపా� సొత్రalla(?)ft ఠూండానacam ! వ్యచినండపగ్యడ దిమ్ర్నన౏ ప్ట sost�్త్స్ side nails నిత్లివం. Here is one possible simple way of doing that. I declare a dice value as an integer variable. I declare unsigned int as a seed value for the seed. I declare ik and count 6 because I want to determine how many times different digits appear when I throw a dice using this simulator. I collect an integer seed value from the user and invoke this SRAM. When I do that, I am resetting the start point for the generation of the random number sequences. I can generate any one of the 6 digits 1, 2, 3, 4, 5, 6. I want to generate thousands of them and count how many times 1 happened, how many times 2 happened, how many times 3 happened. For that purpose, I have put an array called count array. I initialize the count array to 0 and then set up an iteration say I run it 60,000 times. That means I will run 60,000 and I will generate 60,000 random numbers. How do I generate 60,000 random numbers? Very simple. Every call ran, opening bracket, closing bracket will get me a random number. Of course, this is between 0 and very large number. So what I do? I take a module of 6 value of this. Whatever be the random number, this value will be either 0, 1, 2, 3, 4 or 5. I add 1 to it and what I get is a dice value, a proper dice value. So I can simulate a dice throw because as a result of this calculation, I will get a dice value which will be between 1 and 6. I can use this value so generated for either simulating a board game like snacks and ladders or doing whatever. Here the objective of this segment of the code is to find out how many times different values occur. As I told you, if you just throw it 10 or 20 times and conclude that it is uniformly not distributed, that will be wrong but if you do this and every time a number happens, use the associative array principle, subtract 1 from it, this will be between 0 and 5 and you increment that particular element of that array. So if you get 5, you increment 5th element, you get 4, you increment 4th element, you get 0 meaning 1 minus 1 so you increment 0th element etc. At the end of this iteration, the various counts that you will print should roughly be how much? Well, I am conducting this iteration 60,000 times. So every digit should happen about 10,000. Now it will not happen exactly 10,000. You can try running this code. Some digit will happen say 9,854 times. Something will happen 10,400 and something like that. And that is real so there is no problem there but these are truly uniformly distributed random. The problem with this approach is that every time you run a program, suppose you are simulating a game of snakes and ladders, now you don't want both the players to go through exactly the same process randomly and still arrive at the same result. You would like randomness to be different. On the other hand, you have written a simulator. Why should user be asked to give a number? Can't I do that automatically? So what I want? I want a number which will be different every time I run a program. What could be such a number? The suggestion is I can use the random number generator to generate a seed. Good point but sadly it will not work. I generate a random number S-rand. Remember every time I run the program it will generate the same random number. So that I put it as seed again it will generate the same signal. I need a number which is guaranteed different every time I physically run the program. So one of the things which is used universally is time because time is a one-way street. No instance comes back after it goes away. So today at whatever 10-15 is different than yesterday night 7 o'clock. It will be different tomorrow morning. In fact it will be different 5 seconds later. It will be different even 1 millisecond later. The trouble is the time is available with our watch. And that will again mean I will have to feed something. Fortunately the operating system of almost all computers maintain a time internal. And there is an operating system called which permits us to get time. There is a function called time. It has variety of types of parameters but a particular parameter 0 if you give time 0. Then time 0 will go to the operating system. It will ask operating system to look up its own watch internally at that instance of time. And so return me what value is returned. It returns the number of seconds that have elapsed since an artificial date 111970. Starting from the greenwich mean time. Midnight of greenwich mean time. Large number of seconds. But every second that value will be different. So if instead of collecting some seed from you if I simply say srand time 0 as the first instruction in my program. I would be necessarily setting a seed which is different for every execution. And then when I generate my random numbers I will get explicitly different things. Incidentally I would like you to look at the time function. For example the time function returns a value which is an integral type but not a normal unsigned int. It is actually type which has been defined there called time underscore t. You will find in the C++ libraries variety of types get defined for specific usage. So this time underscore t is actually a type which is of the integral type. It is alright because by the normal common sense whenever an integer value is required and the type is an integral type but not exactly unsigned integer the compiler will issue instructions to convert it automatically. So this type will be converted into unsigned int which is required as a parameter for time. However if you wanted you could explicitly invoke that casting. So if I say in bracket unsigned int in front of time 0 this means that whatever is the value of type returned by time it should be converted to unsigned int before calling the next function. This explicit declaration explicit casting is often very useful. Let me just digress a bit for a minute and show you how explicit change explicit casting is almost mandated. Consider this let's say I have n number of students and let's say I have bought a large number of apples so I have mapples and I want to distribute these apples to students. What I want to calculate at the gross level is what is the average number of apples per student? Average will be naturally float but these will be int. So if I say in my program average is equal to n upon m. What will I get? Integer divided by integer and obviously there should be more apples than students the average number of apples will be 0 which is not the correct result. I could do one of the two things. I could say that look I want to avoid this. So let me declare instead of this int let me declare this as float. Even declaring one of the values as float will solve the problem because when I have an operation between float and int then int is converted to float. However this will solve my problem but programming coding standard wise this is wrong. I use float strictly when I am likely to have fractional values. I am very unlikely to have 27.5 students. In exactly the same fashion I am unlikely to have 4 and 3 fourth apples. These are natural integers and therefore they must be represented as integers which is the correct way. So the right way of writing this expression will be I return this integer but I say average is equal to this putting float in brackets actually forces a casting forces a conversion temporary conversion the value of n remains integer but it is converted to float before it is divided by m. If I wanted I could do this as well although the second part is not required that will be implicitly done if one of the things is float. So is that clear? This is called the casting and the casting operation is used very often in programs. Lastly I want to discuss the assert micro. There is a library called assert library and it is extremely useful to simplify error checking and what should I say any sad termination of my program if there is an error. Recall that in our discussion on the file processing we have come across such a code. We had said in file is equal to f open whatever whatever file name but if the file could not be opened for some reason we were checking whether the pointer returned by that open statement was null and if it was null we are saying error in opening file and return one. Terminate the program. This is often required to be done. The more external functions that you call the more will be such code in your program. Why? Because you are expected to test every time whether that external function work properly or not. So C++ provides a simpler mechanism called assertion checking. So basically what you say is I assert that the file opened properly but if the assertion has backfired then please do something What is to be done? Well what is to be done is give an appropriate error message. I don't waste my time writing error messages for every now and then in my program and I call this function. I will just tell you what condition is to be checked. That is called assert checking and the way it is done is by writing this. So for example this particular code is more simply written as assert in file not equal to null. So my assertion is I have opened a file. File has properly opened. That is my assertion. I am assuming that is so. So I say assert this. If however file has not been opened for any reason this condition will be false. If this condition is false the assert library system does the following. It gives you an error message. This error message is given on stderr which incidentally is a file connected automatically to your terminal only so there is no problem. And it will tell you assert failure and it will say why. Maybe it will say in file or whatever something. And it will also give you the source file name in which this program code was there. So it is sufficient for you to decipher what exactly happened. Additionally after giving that message on stderr it will terminate the program abnormal. So you don't have to worry about it. Again it is exactly the same thing as you are doing here. But remember in a large program such as the one which you will be writing for your project it will not be uncommon where you will need maybe 30 such statements there. And once you are writing your own statement you will naturally think of writing different error messages. So instead this assertion is an extremely simple way of ensuring exactly the same thing. With this we begin our discussion on the object oriented program. I am not suggesting that we have discussed all possible features of CC++ which are procedural in nature. There will be some more which we will come to as and when we proceed. However the features that we have discussed so far in this course are actually adequate for you to write programs for practically solving any problem. But if we look at programming in an object oriented way the programming task becomes further easier. And that is what we are going to see now. So far what we have seen in the CC++ programming language features is the set of procedural aspects of that programming language. But there are strong object oriented aspects which we shall be examining over the next 2 or 3 weeks. And you may be able to use some of them very quickly in your projects further simplifying the course that you write. Objects occur very naturally and object classes are almost a natural division or classification that we are able to do. We discussed when we modeled information system we said students, student is an object and all students form a class. We call that an entity class. An entity is nothing but an object because an object has certain properties. A student has certain properties as we saw. What we forgot to mention because we are modeling only the property or the data part about that object called student. But that student also has certain behavioral aspect in the context of the problem that we have seen. For example, a student's hostel number and room number may change. A student's marks may get updated. The hostel number, room number and marks are the property or the description of that student. The fact that these can be changed is the behavioral aspect of that object. The way I am trying to illustrate it is the closest equivalent and much stronger equivalent to the object oriented notion in programming that we find in real world. Namely a cell, a biological cell in any living species. That cell is an object. Those of you have studied some basic biology somewhere would remember that every cell has a nucleus. By the way, all the information about that cell is contained in the nucleus because your DNA, RNA, etc. are all part of that nucleus. This nucleus is surrounded by some fluid and then there is a membrane. The cell interacts with the rest of the world through this membrane and therefore membrane forms an interface. Do you know how these interfaces work? They actually work through messaging system. For example, if by mistake you put your hand to a flame, that portion of the skin will get very hot very quickly. Within a split second you will remove your hand. You would have felt this sometime or the other. Have you tried to analyze how this happens? Because your brain is somewhere here, the brain is not on fire, the hand is. So the information has to reach from that tip of your hand all the way to the brain. Because the motor functions of the muscles which cause your hand to be withdrawn are controlled by the brain. Only when brain takes those muscles to contract and move, then they will move. So messages have to pass across from that tip travelling fairly large distance if you look at the sizes of the cells which are taking this message across. And how will they take the message across? Because each cell is a completely independent self-contained unit. So the cells actually interact with each other and this interaction happens through some kind of a message passing. It is known for example that in the nervous system the neurons which pass messages across actually generate some sort of a chemical which creates some voltage difference between two points and that voltage difference corresponds to information. The plethora of research on that will not go into those details. The point is that the actual properties of a cell are contained within the cell itself. Now when a particular message has to pass that look something has happened in that corner, please inform the brain. At that point in time the 250 odd properties which are part of this cell are not relevant. We want to know whether this cell can transmit this message or not. Or whether it can generate something else. The behavior therefore is restricted to what the external world can cause that behavior to happen or what the cell can cause the behavior to happen in other cells. This encapsulation, the private property of the cell need not be known to the rest of the world. I only need to know how to invoke it. Take students as objects. There is a project to be done. Now there are individual properties in each lab batch. If I take lab batch as an object, batch as an object and the class of all batches as the class. Now each batch has certain properties. Those properties are known to those batch members. External person who is interacting with that batch will only say alright this is the problem that you have chosen. Okay work on this project. And at the end of 20 days, 15 days whatever you will come up with those program. So your behavior includes ability to write programs, ability to compile programs, ability to discuss etc. I am not invoking any one of these. I am saying do this project and submit weekly reports. Interaction between different objects can be extremely simplified. If the interaction is limited to one object invoking some behavior or some action on part of the other object. Further the internal information about the object need not be exposed to the rest of the world. It is not required. The internal information will be used by the object itself while displaying that behavior. Now this beauty of encapsulation and this beauty of interaction between different objects through messages is what has given rise to a rethinking on programming. And therefore programming systems evolved which said that why can't I instead of calling my values as variables and my operations as multiply, divide etc. Why can't I classify all this plethora of features into an object oriented philosophy. And therefore if I could define a class of objects. Where a class would be equivalent to the complexity associated with the structure and its behavior. So if I say student as a class for example. It will have every student will have same properties and every student will have the same behavior. In the context of what we discussed the other day in terms of modeling. We say that if we have a student class then the properties of all students will be same. What were the properties that we said student as role number, student as mark, student as hostel number, student as room number. Amongst thousand properties we said these properties are relevant to us. And in terms of the behavior or action what is possible with this information. As I said a student may change room number from ground floor to fourth floor. Students marks may get updated. Now if there is a class of students for which I define functions which will change the marks. I define another function which will change or update the hostel room. Then I don't care how exactly this information about hostel room etc. is maintained inside the student class. Somebody may be writing it on a piece of paper. Some student may be putting it on a computer. I don't care as long as I can tell student to change the marks or tell student to change the hostel room. Or the student can tell another class called modern class to do something. Now that behavior is what we are trying to incorporate in our program. Very crudely whatever we have discussed as variables, arrays, different types, data structures. They all form the basis for describing properties of class. And whatever we have discussed in terms of coding, actual computations, reading, writing, input, output, assignment, calculations etc. That will be modeling our behavior. And the way we model the behavior is instead of writing these instructions in an aphazard fashion we identify what are the behavioral patterns which are most important from a programming perspective and write functions specifically for that. These functions in the context of a class are called member functions of the class. And the properties are called data members for the class. So the behavior of an object essentially is invoked by sending a message and message is nothing but the set of parameters that you will send along with a function. So when you call a function and set of parameters you are basically asking that class that please invoke this behavior of yours, that means execute this function and these are the parameters using which you have to execute that function. So in a nutshell this programming paradigm which is different from a conventional procedural programming paradigm by the way I have tried to significantly simplify the notion. The object oriented programming in depth when you read there is a lot more to it. Just trying to give you a very very crude overview. So we are saying that we have the ability to define a class of objects. For a class I can define properties through what we call data elements. For a class I can define the behavior through member functions which are also called methods sometimes. And once I define methods and the data elements for a class then those methods and data elements are available for every member of the class. And I can invoke these functions for any member at any point in time. So whenever we wish to invoke specific behavior we pass a message that we are essentially parameters to a function. We shall see some examples of a class called graphic objects class. So let us very quickly look at some aspects of graphics. We frequently use graphics for displaying information such as windows, rectangles, circles, lines, text strings, bitmap images. We in fact spend some time in analyzing what would be an histogram of an image and normalization of histogram and so on. We did not see how exactly we would plot an image on that paper. In my screen when I press some key you saw an image coming there, an image of the original photograph, an image of the modified photograph. How exactly is that photograph being shown there? So there are pixels we know that pixels but who draws those pixels? How are those pixels drawn? Suppose I want to draw those pixels myself. I want to draw one point here, one point here, one point here to draw a line. I want to draw a rectangle. I want to draw a circle. How do I do that? I can either do that by getting a function to draw one point with given color at a position and then do the rest of the hardware of writing an algorithm to draw a line, writing an algorithm to draw a circle, etc., etc. But instead of each one doing it, if someone has developed a library and I can use that library and that is why we say that in real life programming the less programming that you do, the better will be your program. Never reinvent the wheel. Use somebody else's work. The graphic library that we are going to discuss called EZ windows. This is an object-oriented library. It has several classes and we shall see how exactly the objects can be declared in those classes and how exactly we can do graphics. Now as I said, every such library has an API. This particular graphics library also has an API but to invoke that API, the library demands that you don't write your program as main. You write your program as API main. That is because the EZ windows actually sits between the operating system and you. So for curious reason, this particular functionality is to be invoke by saying API main and therefore the way I will write my program will change slightly in syntax. These are the classes available in EZ windows. There is a class called simple window. It permits us to define windows. Windows which will appear on the screen. These windows have simple properties. They have a text panel at the top, title. So I can give a text and that text will be written in that title. Then these windows are height and width. That's it. It also has. So these are the properties. That means if I describe that I need a window with title some cs101 let's say and I need it by 5 cm by 8 cm then this class has behavioral member functions which can permit me to open such a window then do some work on it display other objects etc and at the end close that window. So if I have declared W to be an object of this type look at the similarity between the declaration of ordinary variable types that you do int x float y similarly simple window W that will define an object W of the class simple window. The point is just as when you say int and float the moment you say int and float all the arithmetic operations etc etc are available to you in exactly the same way once I define W to be an object then all the operations which are available as member functions of the class are available to me also. Additionally I can give the initial values of the property parameter of this object the property first property parameter is the title or the title that will appear on top of that window it is given as a string. The next one is width and the next one is height so I say 8 cm wide 5 cm should be the height Incidentally all these values for these graphic objects are given in cm and the coordinate system is slightly okay the coordinate 0 0 is at the top left corner as I move to the right x is moving forward so larger x from 0 onwards but when y increases it comes down because that is exactly you will recall how our images are stored the first row of pixels second row of pixels third row of pixels so third row of pixels is conventionally y equal to minus 3 so that is why you have y increasing this way x increasing this way that is the coordinate system that you use once I say this I can say W dot open W dot open is a member function it will open that window it will display that window there then I can display other objects inside it and later on I can close that window we will look at one typical object a rectangle class the rectangle class is another object which can be drawn inside a window and this rectangle class has what attributes first of all the window in which it is to be drawn so it has to be connected to a window then the position in the window a color for the rectangle and the width and height but once I have defined this rectangle I have member functions which will automatically say say if I say rectangle class r if I say r dot draw it will draw that rectangle with this problem if I say r dot get color it will return the color value similarly get height get width you will notice that if somebody has written the code to implement this functionality your job is essentially to invoke these member functions and ensure that the appropriate values are set for the attributes which define individual objects I will just look at two examples very quickly in the handout that you will see on this Sunday and the link that you will see on the model in your lab on Monday you will find six sample programs like this sample 1, sample 2, sample 3, sample 4, etc install that eZ windows package it takes about 5 minutes to install it all ubuntu machines run this package and we have ensured that all old software lab machines run ubuntu now so it won't take much time if you have any problem your TS will help this is a complete program to draw a window I include IO stream, I using namespace STD include rect dot h, rect dot h so this is actually a header file for recta int api main one thing you have to be very careful about ordinarily in my examples I have been writing all names of functions in small case sometimes first later is big case that is capital but in all apis and the standard practice across different packages the first later and the first later of another word if it is part of that full name they are capital so api main is capital api, capital ai if you write small m it will say function not found over same thing here simple window so s capital w capital so like we saw I am defining a simple window the title I want to appear there is my first window I am defining a object called w like a variable of this type and the w has these attributes and I said w dot open when I say w dot open mind you o is capital it will actually draw that window in fact this window will look like this so actually a window will be drawn like this if you don't give any height and width it will assume some default height and width but if you give some height and width you can experiment with that remember if you had only the very basic functionality available namely drawing a particular point in a color at defined position it would have taken hello a lot of work to just do this it is not easy to write text my first window all of this is now made part of the life observe that in this program there is a statement here which says type control c to remove the display and exit then I say care any care and I say see in any care only when you give me that character I am saying w close why I have to do all this what will happen if I said w close here what will happen is even before I see the window it will disappear I want to see it and as long as I want to see it I want to keep it there but then if I keep it there it will not automatically vanish so I have to create this artificial interrupt or an event later on we shall see when we discuss more on the e-z windows how variety of events can be actually taken care of by event tracking mechanism so when I move my mouse and mouse comes to a particular the cursor comes to a particular point that's an event I can actually track that position and I can say if I have drawn this diagram here if the mouse comes here do the following so event-based action is possible in object oriented programming in an extremely simple fashion because events can be reacted to so this is one program and this the second one notice here I am using c-azert so azert library is included by saying c-azert I have simple window whose name is not w this time it is hello window hello window is the title that will appear in the diagram that I showed now that hello window will have this title and its size will be 10 by 10 and its position is 1,1 that means starting from the left corner of the screen 1 centimeter here 1 centimeter here will be the position of the top left corner of this window so now I am being very specific where I want that window of what size okay then I say hello window dot open I might have goofed up in giving these values so I want to sure that the window actually open note the azert the azert says hello window dot gate status now gate status is another property of the simple window class this gate status is able to tell you whether the window is open or not so I am azerting it is open if it is not if it is not window open this fellow will send a message and terminate automatically so I got my window now exactly instead of my first window it will say hello is there windows now I am doing something different I am finding the center of that window again there is a member function hello window dot gate center it will tell me the center point coordinates and that I am assigning to position center so position is another type position is another class I am defining just like int x I am saying position center so I am saying center equal to all of this I get that value and then I define an upper left and lower right corner in which I want to write some text that definition is center plus position this center plus position this notice what I am doing when I get that position earlier the center position I say minus 1 minus 1 and 1 1 that means I am defining left of the center and right of the center and I am defining some kind of a bounding box this bounding box is required to be defined whenever you want to write any text in that shape that you have any window if you want to write a text you have to define a bounding box of course this is artificial because even if your text extends beyond that bounding box the system does not create it will write the text however what is important is how easily the text is written you just say hello window dot render text so render text is another member function render text means whatever string I give you write it in that window where do you write it how do you write it well write it from the upper left and lower right which is the bounding box and what is the text I want it to write well namaste CS101 students and I want to write it in red color just this single call to member function called render text will write all this in that window and later on you can do the same thing if you want wait for a character input and close if you don't if you just say return 0 your program will terminate but the window will still remain on the screen you may of course delete that window from by other means and so on this is a rudimentary graphics library but this is very good to illustrate the power of looking at things from the point of view of classes and objects fundamentally there is no difference I would have done the same thing if I had written my functions and assume that these functions were part of this library so I was having these function libraries here this is the upper left and this is the lower right so upper left and lower right are something like x and y I am giving values to x and y which are not simple integer values but these are attributes these are coordinates so the upper left and lower right define an artificial rectangle within which the text is supposed to appear there is no physical rectangle that is drawn there is just position of the upper left corner of that artificial rectangle and lower right corner of that artificial rectangle so it is in fact if we were to see this here suppose this is my thing I want my text say let's say I just want to write namaste now I can write namaste here I can write namaste here I can write anywhere where I should write so I want I am imagining as if I have a rectangle like this physically such a rectangle does not exist but I estimate where that text will appear and I have to tell the system please write my text inside this estimated rectangle so I have to give the upper left corner of the rectangle and lower right corner of the rectangle what the graphic package does is it tries to put this text centered at the center of this box of course if the text is larger it may go on this side and this side but effectively I can imagine where I want to write and I can give this so that's the requirement of that function that is how the function has been written this whole text is inside that my first window yeah of course this whole text is inside that so all operations that you do is on the window so the hierarchy is like this first you open a window then inside the window you can either write text or you can draw rectangle you can draw circles whatever what in fact the remaining sample program which as I said I will try to describe them briefly on Tuesday lecture if I can connect my ubuntu machine otherwise you can test them on your machines alright thank you