 Now, so far this is important so you better pay attention because we will not have sufficient time to solve many problems specifically in object oriented programming. Although there will have to be some questions in the ENSEM, so you should understand a little bit about objects in the context of programming. First, let me quickly describe what do we mean by objects in classes in a generic sense. Then we will look at the notion of properties of a class as we define in the context of object oriented programming which is what C++ is all about. I will in the process also distinguish between the classical procedure languages and the object oriented programming languages. We have not been using the object oriented features of C++ exclusively and that is because at the beginning it was important so as I was saying it was important for us to understand the conditional procedure programming for us and that is what we concentrated in most of the course. However, C++ is a true object oriented programming language and we must understand what exactly object orientation means independent from the procedure oriented programming. So we shall have a brief first look today and we will continue that tomorrow and in the last lecture. Then there will be some announcements regarding the submissions just as a reminder as well as some new information. So here is a general observation this was made not now but in the context of programming it was made many many years almost at the beginning of the programming except that the notion of looking at programming through an object oriented wing was not very fashionable in the early years. That was the time when people wrote programs in machine language or assembly language and the higher level languages were just coming of age. Most of the higher level programming languages concentrate on providing features for which you would ordinarily write programs in machine language and therefore straightforward computational procedures, conditional execution, iteration and some simple data structures and data types was effectively the focus of attention of all programming language designers. However, when people started looking at large programs they found out that the programming language became rather unwieldy and difficult and in order to make it manageable several paradigms were introduced. The first one was called structured programming where you structured your programming to different modules. Then came the notion of functions where you could create independent function libraries and which could be used by many other people as well. To this day all these features of course survived and they have become more and more important and crucial. However, a completely independent way of programming was introduced when people tried to relate programming to the general manner in which we view the world. Essentially the observation was that we view the world in terms of objects. The objects could be inanimate objects such as fish, person, student, a blood cell, dog, tiger, whatever. These are living organisms. They could be inanimate objects such as a light bulb or a phone or a car. They could also be abstract objects, astring, question, syllables. These are abstract objects. What is so big about looking at something as an object? First of all, all the objects which share similar attributes, they can be grouped together in a class. Each object by the way has a set of attributes and each object has a set of behavior. Behavior effectively means the functionality that the object exhibits. Like for example a fish can swim, a car can travel on a road, a string can contain name or address or any series of alphabets. A syllabus will contain topics to be covered in a course, etc. So these are attributes. A student for example would have a whole list of attributes. Each element is possible for any object to list out thousands of attributes. But what we do usually is we concentrate on those attributes of an object with which we are concerned. Not all attributes will be meaningful for the kind of activities that we envisage. And therefore we limit the number of attributes which describe an object. The point is when we read the word as a set of objects, the objects can be classified in terms of common attributes and common behavior. For example all light bulbs will have some powered wattage associated with it. All light bulbs will have a voltage specification. They will work at 12 volts, 9 volts, 220 volts, 110 volts, etc. etc. That could also be distinguished based on the filament that it has. But all light bulbs will share these attributes and therefore all light bulbs can be set to form a class. The behavior of light bulbs is simply described as we are concerned by the ability of switching on a light bulb or switching it off. So obviously we assume that the light bulb is connected to some electric power supply. And when we switch it on, the typical light bulb that we see, the filament gets hot and it emits light. That's the characteristics. So the behavior of a light bulb is very simple. It can either switch on or switch off. There could be more complex behavior that could be observed in other objects. But effectively all objects which have the same attributes and which exhibit the same functionality or same behavior are clubbed together as a single object class. And consequently we deal with the external world perpetually in terms of object classes and individual members of each class. From a programming perspective we will be looking mostly at abstract classes and the objects belonging to those abstract classes. But consider something which is well known to us. It's actually an alienate object. A student is a person. A student could be considered to have the following relevant attributes. Name, role, number, the program that the student is studying. The B.Tech, MSC, M.Tech, Ph.D. whatever. The current year in which the student is studying. The current semester in which the student is studying. The courses registered. This will be a list of courses. Hostile in which the student stays. The rule number in which the student stays. Hobbies of a student, height, weight, date of birth, fingerprint, photograph, SPI, CPR. And I'm sure you can list n number of additional attributes. Whatever, whatever. There could be 100 attributes that one could easily write if you consider a student as a person and therefore names of friends for example. You limit the number of attributes that you wish to describe in the context of programming languages or in the context of writing programs. You constrain the number of attributes to those which are relevant. For example, if you are considering the academic career of a student in IIT, many of these attributes will be valid but some will be irrelevant. For example, height and weight may have nothing to do with academic characteristics of a person. So you might want to limit it from the description of a student object using those attributes. On the other hand, if you are choosing an athletic team, then perhaps the list of hobbies, height, weight, date of birth, in case there is a qualification or a certain minimum age to participate, etc., those things will become important. There will be attributes which will be relevant in many applications. There will be some attributes which will be relevant only for specific applications. But essentially every student in the class of students will share all these attributes. The behaviour of the student is not being stated here in terms of social sense of a behaviour of a person. But we are talking about the ability of the object to change the values of some of the attributes. The entire behaviour, the state of a student or the state of an object is always represented by values of the attribute. For example, the state of light bulb is either switched off or switched off, as we have defined it here. And therefore anything else is irrelevant. But the attribute values which the light bulb will have could say a particular light bulb is 40 watt bulb, another light bulb is 25 watt bulb. Notice that while wattage is an attribute of a light bulb, there is no behaviour known by which the light bulb can change the wattage. Once the bulb is manufactured, the wattage will be fixed. It will be either 40 watts or 25 watt. You can't change it. So what you can change? You can change the status, whether it is switched off or not switched off. Similarly take a student. Once a student joins an institution, you cannot change the date of birth of the student, for example. In fact it cannot be changed after the child is born. But a student's CPI may change, a student's program may change, a year in which student is studying may change, student's hobbies may change. These changes are affected not necessarily by external entities. These changes are affected by the object, particularly object is like a student. And therefore we attribute the behaviour of an object to the ability of the object to change some of these attributes. These attributes will not change on its own. There will be some impetus, something happening in the external world which will trigger a change. For example, students acquire grades in various courses that the student is studying during a semester. As a result of which CPI gets modified or CPI gets computed for the first time. So there is an external stimulus which is causing things to change. But what changes is the attribute of an object. Now so far in the programming context, we have always been believing that when we write a program, the program changes things. We are of course capable of writing programs to change any data value that we use in our program. But when we look at the entire program components as a set of objects in terms of their attributes and behaviour, then we would like to believe that the objects that we define in our program are capable of changing themselves. And for such changes we shall provide functional programming which can, when executed, change that particular attribute. Like for example, changing CPI. CPI is an attribute of a student. So the student objects CPI will change for which we can provide a function. That function then becomes part and parcel of the object class called student. Because every student in that object class can have the CPI undergoing a change. The change will not happen on its own. It will be triggered by some external entity. Let's say academic office declaring a new CPI. In which case I will have to update the value of the attribute CPI for a student by the new value that comes in. The student has multiple attributes of which the academic office need not be concerned with. For example, when grades are to be awarded, academic office is least concerned about which hostel and which room a student lives in. Consequently it is possible that when an object interacts with other objects in life, each interaction will remain specific to certain behaviour that needs to be exchanged or behavioural information that needs to be exchanged between these two objects. All other information can remain buried inside the object itself. The most important aspect of object oriented programming is to consider that everything about an object class or everything about the individual attributes of an object or everything about the behaviour of every object in that object class need not necessarily be known outside that object class. What needs to be known however is that if something else in the world has to interact with that object, what exactly will be that interaction mechanism and if that mechanism is provided that is considered quite adequate. So here is the definition of a class. All objects which have same attributes and behaviour belong to a single class and all objects of the class share commonly defined attributes as also the methods through which they exhibit their behaviour. So their behaviour once again I will describe the behaviour we are talking about not in the social sense. A bell has no social behaviour but the bell has a behaviour of emitting light or keeping shut and there is a method that method is called switching it on. So if there is an external stimulus which switches on the bell, the bell will lit otherwise it will be dark. These two states are changed by an external interaction which is limited to somebody switching on or switching off a switch. The external entity which performs this action is actually sending a message to the bell. By switching it on you are telling the bell, please let the current pass through your filament, let it be heated and let light be emitted. But how exactly the current will pass? How exactly the light will be, the heat will be generated? All these things we need not at all worry about. The object knows what to do. And the important part therefore is that when objects interact with other objects either in the same class or other classes they interact through very specific messages. These messages define what is known as an interface. So at the interface the object understands what kind of message it is likely to receive and what kind of information it is required to give back. This is exactly what you do when you invoke a function. There is a function name which is like a message name and there are parameters. What exactly that function is supposed to do is known to the object but you get only these three parameters. How exactly you compute things using those three parameters and evaluate the function need not be known to the external agency at all. It just says these are the three parameters I am sending and you do whatever computations are required give me back a written value. That is a limited information that external entities need to have. Consequently implementation details of computations of functions can be hidden from rest of the world. And that is the most important thing that not all attributes and methods belonging to a particular class of objects need to be known to the external world. Only those which participate in interaction so which solicit desired functionality need to be known external and this permits hiding of information. Information hiding is an extremely important concept because if every piece of information in your program is required to be known to every other piece of information in your program and if your program is a million lines long then there will be chaos. Imagine the number of independent names themselves that you will have to sort of construct to give variable names, array names etc. Imagine the kind of functional behavior that will have to be written for maybe 5000 functions in your program, 10,000 functions in your program. So if you basically divide in room you say I have objects belonging to different classes, I have 100 classes. Each class has some private information and some public information. The public information is effectively the interface. How I implement that functionality of that particular object is entirely left to some other programmer who writes that function. A case in point would be sorting algorithm. If I want to sort an array of integers in ascending order I only need to know that a function called sort array for example is to be invoked to which I will pass a parameter and array pointer, an object. That is my normal way of functional definition. Instead what I will now say in the object oriented paradigm is an object called array exists somewhere as a class of arrays. It has been initialized by some methods, some marks have been or some integer values have been read into that array. Now I want that array to be sorted so that I can access that object using let's say binary search. What I will then do is I will invoke a member function of the class which I have defined that the array is an object and that member function can be invoked to say please get yourself sorted. Now if originally I have to worry about the details of sorting I will have to implement an algorithm called bubble sort or insertion sort or selections or whatever. There are 20 different kinds of sorts. We have seen one or two of them. The point here is if I am writing a larger program where I need to access a sorted array I need not worry about how that array will get sorted. That's an object and there could be a private implemented method to sort that array. The beauty is that once that method is written I can invoke it, get that array sorted. Tomorrow if a better efficient algorithm gets to be known and gets implemented for that class of objects I automatically get to use that as long as the interface is not changed. I still say Mr. R R object gets sorted and the way it gets sorted may depend upon the current implementation of the sorting algorithm. So this information hiding also permits anybody any programmer to change such hidden information from one particular functional implementation to another as long as the interface does not change the entire programming system remains intact. That's one of the great advantages of the notion of classes and objects. As an example I have chosen to give a class definition in C++ by defining a object which actually calculates and prints time in hours, minutes and seconds. Since now we are talking about object oriented programming we ought to know how exactly object classes are defined in C++. This is one way of defining an object class. So there is a time class. So I am defining class. So I have stored this definition into mytime.h a header fine and this class my time is the name of the class. So we define it exactly like we define a function and this would be equivalent of defining what we define as global let's say integer floating point variables, arrays etc etc you define a class. When you define a class like this it has public and private components. The private components are integer hour, integer minute, integer seconds. So you can see the comments indicate what exactly I wish to store. I wish to store the hours, minutes and seconds in a regular 24 hour format. We have seen this kind of thing earlier. Now you notice the public functions which are defined here. First is called mytime which is called the constructor of an object. Remember we are defining an object class. Individual objects don't exist and therefore individual variables as we understand them don't exist yet by this definition. So this definition only gives a template. All objects belonging to this type we have exactly the same properties, we have the same attributes, we have the same functions. The functions which are defined here wide set time, wide print standard these are called member functions. In fact in the case of files whenever you say my file dot open or my file dot something actually what you are doing is you are using, you are invoking a member function of the class of files. So when you invoke a member function the behavior as indicated by that member function will be executed and correspondingly any attribute values etc are to be changed or any output is to be created input has to be taken in etc will be handled. So that is the behavioral part. Notice the private part it says integer hour, integer minute, integer seconds. So these whenever I construct an object every object of the class my time will have three attributes, hour, minutes, seconds, every object. Now there could be a time at which you collected a fingerprint of a person. There could be a time at which a student went to let's say eat food. There could be a time at which a particular examination started. The time attribute in generic sense could be used by any and every activity that we undertake. So you might require several objects of this type or a class called type. Any object where it is instantiated no object exists originally only a class definition exists. In our program we create objects by constructing those objects and once the objects are created they automatically inherit all the methods that are associated with the class of objects. They also generate for themselves the attributes which are defined for every object in the class. So these are the object attributes hour, minute, second and these are the functions. Of course these functions were formed from sky. We are specifying roughly what we are specifying is something like a prototype for a function call. The actual functions will have to be written by us. So this is where we define public, private components and the class definitions mirrors in syntax exactly like a function definition does. But it does not end here. This is the beginning of the class definition and that is why it has been included in a header file. When I actually describe the class completely I will have to write many more things. So here are some things for example. So I might have include my time dot h. Then I have a constructor which initializes object to zero time. So this is the constructor definition. My time colon colon set time integer h m and s. So this is a particular set time function which is part of that object. Also we are using a question mark operator which will allocate either the value h or zero depending upon value of h here. Hour, minute and second are handled like this. You can look at this through the exercise. We have done this kind of exercise earlier. I will try to put it in a slightly different and a simpler form exhibiting the behavior of a question mark operator here. There is another thing called my time, member function called print standard. So print standard is another member function which I could use in my program once it is defined. All that it does is it takes a 24 hour standard time and prints time in AM and PM as we know it ordinarily. So for example depending upon whether the hour is between 0 to 12 or hour is beyond 12 that is between 12 and 23 it will print either 12 or hour modulo 12 depends upon whatever is the value here. And then again it will output AM or PM using this method. This is just an example. I will repeat again you don't have to use object oriented programming in the exams or in the projects that you do. But since C++ exhibits very strong object oriented features in the next three lectures we will be discussing some of them so that you are prepared to study things on your own or through some additional courses later in the subsequent classes. My colleagues have come so we will start the what you call course evaluation but I will just take two more minutes some announcements. Now this is something I had mentioned but I found some team leaders asking me questions again on this. Please remember apart from the project submissions which I suppose you are doing every deadline two deadlines are passed the last deadline will come at the end of this week. This is an additional 10 mark portion if you recall we have removed 5 marks from assignments and 5 marks from quizzes and we have said we will have a special assignment worth 10 marks. This is a group assignment so this is not an activity where individual student will get any mark. The individual student getting marks will depend entirely upon how that particular group which is a lab dash performs. There are two assignments actually the first is to set test questions which I have explained earlier simple, complex and simple, medium and complex type of hardness requiring 15, 30 and 45 minutes. Now as I said each lab dash will have to set such three questions one simple, one medium and one complex and at least three students from the lab dash must attempt that question. People have been asking me repeatedly will their roll numbers will have to be written etc that is nonsense it's a group activity. So you just call it student one student two student three but what I do not want is the same three students or in fact only one student making all the three attend for all the questions that is nonsense. So team leaders must ensure that the students of the lab dash are allocated this responsibility and they time themselves 15 minutes 30 minutes or 45 minutes. They must write down the answer to that question of whatever way they attempt and they must insert it. The comment merely say lab dash so and so student number so and so not roll number student one student two student three student four student five whatever. Additionally the lab dash will also have to construct a correct decent answer for that question with comments etc which may take much longer than 15 minutes 30 minutes 45 minutes and will have to be inserted in your submission. We have decided to reallocate marks this particular activity will have six marks instead of five which was earlier two marks per question. Additionally each lab dash will have to set two quiz questions on each allocated topic so you have to set four quiz questions. As I explained earlier there could be multiple choice quiz questions there could be course segments and you just want to see the output of that course segment. Or you could say which of these course segments will produce this output it could be even fill in the blank. The choice is entirely yours. A quiz question should not take more than one minute to three to four minutes for people to figure out. And the topics which are allocated you can't set quiz questions on any arbitrary topic. So I have given here list of quiz questions there are two sets and these are the batch numbers. So batch number zero will set quiz questions on data values batch number nine and variable names batch number eight on simple expressions etc etc. All those batch numbers are given you can read them upon the slides which will be put up. These will all be put up on the on the site. This is the elementary set and this is the advanced set. Each lab batch we have to construct two quiz questions on each of these. And this total assignment this time no it's not expected that people will actually participate in a time quiz or something. But correct answer and the reason for other answers being wrong should be listed there. This is the second submission. This submission will be due on 16th which is the last day of instructions. Both the questions and the quiz topics. I think we will close here. We will continue tomorrow morning. My request is if you can get an early breakfast tomorrow we can start the lecture sharp at 8.30. I will appreciate. Please don't leave the course evaluation will be conducted by my colleagues. I will help you leave now however. This one student has not been taking the printouts that I have been bringing here. Is he not here or something? There is somebody else right who used to take these printouts.