Lecture 1 Introduction to object oriented programming  





The C++ primitive data types (int, float, double, char, etc) can be used by declaring a variable and assigning a value to it. Consider creating your own data type, a variable of which can hold multiple data items each of different or same data types. o E.g. writing a program to handle student’s record composed of, lets say  Registration number  Name  CGPA  Age o This can be done using  char [15] regNum  char [50] name  float cgpa  int age o This can represent one student’s record. o What if you are to handle 100 or 1000 students? What will you do?  C++ offers the facility of packaging/grouping several variables of different variables into one unit and then creating multiple copies of that unit.  Each copy will have all those variables and can work independent of other copies. Consider 100 people are given a bag having a sandwich, a drink and a pack of fries. o Whatever is inside your bag, belongs to you.  Whatever you choose to do with your bag, won’t affect any other’s bag. Imagine packaging the following into one collection and naming it “student.” o o o o



char [15] regNum char [50] name float cgpa int age

Now, if we create 100 or 1000 copies of this collection, each will have these 4 data items. o Each copy can have its own values for each of the data items. o One copy of this collection will have a set of values stored in it, just like one variable of int type has one integer stored in it. o This is how you can create a data type of your own having, a variable of which can hold multiple data items each of different or same data types.





 



If you could do the above mentioned collection technique, you’ll be doing OOP (object oriented programming). o This is the fundamental concept of OOP. In technical terminology of OOP o The “student” collection we packaged everything in is known as a class. o The variables and arrays we packaged are called data members. o Each copy of the collection we’ll create will be called one object. A class is also called a “user defined data type” or an “abstract data type.” An object is said to be an instance of a class. That’s same as saying Honda Civic is an instance of a four-door passenger car.

You must have used structures in C++ o Structures are object oriented programming. o A structure and a class are almost absolutely the same thing. Some tiny differences though.

Code to declare student structure struct Student { char regNumber[15]; char name[50]; float cgpa; int age; };



You can declare an object of student structure and access the data members through the dot operator like o student s1; o s1.cgpa = 3.5; // for example

Code to declare student class: exact equivalent of the student structure class Student { public: char regNumber[15]; char name[50]; float cgpa; int age; };





You can again declare an object of the student class and access the data members through the dot operator like o Student s1; o s1.cgpa = 3; // for example “public” is a keyword. It’s an access specifier which indicates, everything written below it can be accessed through an object using the dot operator.

Difference between a class and a structure  

The default access level of a structure is public: you can declare an object and access any member through the dot operator The default access level of a class is private: if you remove the keyword “public” from the class above, you cannot access the members through the object using the dot operator.

Data hiding   



 

A car’s internal working is hidden under it body. The user doesn’t know and doesn’t want to know what happens inside the car. There’s a very clean and clear exposed set of equipment and procedures using which the user can drive the car without knowing what happens in there. The manufacturer of the car might want to hide the internal working of the car to o Not overwhelm the user with unwanted details. o Keep the internal working of the car a secret. OOP states that the internal working of a class and the data it holds must be hidden. o Reasons are exactly the same as discussed above about the car manufacturer. o But there must also be a clean and clear set of tools and procedures that let the user use a class. This is known as data hiding. You can hide the internal working of the class and its data members using the “private” access specifier. o Anything written under “private” cannot be accessed through the object using the dot operator.

Encapsulation  



The internal working of the car and the set of clean and clear equipment and procedures that allow a user to use the car are all combined into one unit: the car. OOP says that the data of the class, its internal working and the tools and procedures that allow its usage should all be combined into the class itself, so that every object is self sufficient and independent of others. o Every object is one complete unit having all what it needs. Add a function to the class and explain interface of the class: why functions need to be public and data private. Functions are also called behavior of the object.

Lecture 1

Introduction to object oriented programming. • The C++ primitive data types (int, float, double, char, etc) can be used by declaring a variable and assigning a value to it. • Consider creating your own data type, a variable of which can hold multiple data items each of different or same data types. o E.g. writing a program to ...

357KB Sizes 0 Downloads 312 Views

Recommend Documents

Lecture 1 - GitHub
Jan 9, 2018 - We will put special emphasis on learning to use certain tools common to companies which actually do data ... Class time will consist of a combination of lecture, discussion, questions and answers, and problem solving, .... After this da

Lecture - 1.pdf
There was a problem loading this page. Retrying... Lecture - 1.pdf. Lecture - 1.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying Lecture - 1.pdf.

Lecture note 1: Introduction
Jan 12, 2015 - A typical appoarch to this question is to require that social preference relations (or decision rules) have the same consistency properties as the preference relations of individuals are assumed to have. In particular, the starting poi

1 Lecture December 2011 final.pmd
(2011) who observed improved soil status of organic carbon, and availability of K, S and micro nutrients due to application of enriched compost and vermi. Table 1. Growth, yield attributes, yield and economics of black gram in rabi, 2007-08. Table 2.

1 Lecture December 2011 final.pmd
into a crop stand is not only important component of ... greatest amount of solar heat also get trapped inside ... Since solar radiation and temperature inside the ...

C101-Lecture Notes 1.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. C101-Lecture ...

1 Lecture December 2011 final.pmd
mays) and cowpea (Vigna unguiculata) inter cropping under rainfed conditions. Indian J. Agron.,. 50: 184-186. Mukherjee, A.K., Malti, S. and Nanda, M.R. 1998. Strategy for maximization of forage production. Proc. National. Seminar on Strategy for max

1 Lecture December 2011 final.pmd
application of 250:60:25:10 and 250:76:88:7.4 kg of NPK and Zn ha-1 resulted in the highest total. Zn uptake ... The world maize cultivation area is 146 million .... Treatmental details and nutrient levels for field experiment in Palavidudhi and Pila

1 Lecture December 2011 final.pmd
Tamil Nadu Agricultural University, Coimbatore- 641 003, Tamil Nadu, India. 2Department of Plant ..... Davis, G.N. and Reddy, C.S. 1932. A seeding blight ... Colorado. Plant Disesase, 69: 878-882. Flori, P. and Roberti, R. 1993. Treatment of ...

1 Lecture December 2011 final.pmd
*1Corresponding author email: [email protected] ... retention. Noni has been shown to be a better antioxidant which supports body's system against.

lecture 5-1 wp.pdf
The AR bandwidth is the frequency bandwidth in which the AR of an antenna changes less than. 3-dB from its minimum value. The AR beamwidth is the angle span over which the AR of an antenna. changes less than 3-dB from its minimum value. Fig. 26: AR b

1 Lecture December 2011 final.pmd
of maize crop. The improved nutritional status of AM fungus-inoculated plants resulted in higher grain yields by 20% in comparison to uninoculated treatments.

1 Lecture December 2011 final.pmd
from the viewpoint of food security in India. The sustainability and ..... basket and questioning the food security in the state. ... Battese, G.E. and Corra G.S. 1977.

1 Lecture December 2011 final.pmd
Dec 28, 2011 - 1Former Head, Division of Soil Science and Agricultural Chemistry, IARI and Project .... attained, of course, depends on relative economics.

1 Lecture December 2011 final.pmd
potential in India. The fungus is soil borne inflicting disease on the crop at any growth stage from seedling to pod ... of disease in two tolerant and three susceptible cultivars of pigeonpea in combination with resistant variety .... Tropical Pest

Lecture 1 - Pre-History.pdf
Manuscripts written on birch bark and palm leaves. ◦ Vedas, Ramayana, Mahabharata, Puranas, Upanishads etc. ◦ Buddhist texts, Jaina texts. ◦ Arthashastra. ◦ Plays and stories. ◦ Sangam Literature. ○ Foreign Accounts. ◦ Megasthenes, Ptol

1 Lecture December 2011 final.pmd
First Report of Four Species of Fairyflies from India, Key to. Indian Species of Four ..... rendered by Ms. G. Revathi of IWST in the field collection of parasitoids ...

lecture 6-1 wp.pdf
The effect. A maximu. direction. 1.5 Co. e impedence b. Effective A. easure of the . tive aperture. ge power PL. ent electroma. av( , ) of tha. tive aperture ... For a dire. t W e. where Dt: Not all of. that, we n. Thus the r. Pr A. But. So. Trans

1 Lecture December 2011 final.pmd
brownish-purplish dye for batik making (cloth painting). Root knot nematode, Meloidogyne incognita. Cofoid and White is a serious pest of noni causing.

Week 1 Lecture Material.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Week 1 Lecture Material.pdf. Week 1 Lecture Material.pdf. Open. Extract. Open with. Sign In. Main menu.

phys570-lecture-1.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item.

1 Lecture December 2011 final.pmd
A long term field experiment on different doses of graded fertilizers with and without FYM under finger millet-maize cropping sequence is in progress at the Tamil Nadu Agricultural. University, Coimbatore, since 1972. The effect of continuous fertili

1 Lecture December 2011 final.pmd
J., 98 (10-12): 321-326, December 2011. Stability Analysis of ... Eberhart and Russell model (1966) of stability analysis was carried out to study the genotype.

Lecture 7
Nov 22, 2016 - Faculty of Computer and Information Sciences. Ain Shams University ... A into two subsequences A0 and A1 such that all the elements in A0 are ... In this example, once the list has been partitioned around the pivot, each sublist .....