UNIT-1 Principle of OOP - Lecture - Notes - 212 - 4320702
UNIT-1 Principle of OOP - Lecture - Notes - 212 - 4320702
➢ Object oriented programming can be defined as a programming model which is based upon the concept
of objects and class.
➢ Emphasis is on data rather than procedure/functions.
➢ Programs are divided into classes and their member functions.
➢ Data is hidden and cannot be accessed by external functions.
➢ Objects may communicate with each other through functions.
➢ New data and functions can be easily added whenever necessary.
➢ Follows bottom-up approach in program design.
➢ 1.3.1 Object:-
o Objects are the basic runtime entities in an object oriented system.
o They may represent a person, a place, a bank account, a table of
o data or any item that the program has to handle.
o Real-world objects have attributes and behaviors.
➢ Examples:
o Dog
▪ – Attributes: breed, color, hungry, tired, etc.
▪ – Behaviors: eating, sleeping, etc.
o Bank Account
▪ – Attributes: account number, owner, balance
▪ – Behaviors: withdraw, deposit
➢ 1.3.2 Class:-
o A class is grouping of objects that have identical properties, common behavior and shared
relationship.
o A class binds the data and its related functions together.
o These functions provide the interface between the object’s data and the program.
o This insulation of the data from direct access by the program is called data hiding or information
hiding.
➢ 1.3.5 Inheritance
o Inheritance is the process by which objects of one class acquire the properties of objects of
another class.
o In OOP, the concept of inheritance provides the idea of reusability. This means we can add
additional features to an existing class without modifying it.
➢ 1.3.6 Polymorphism
o Polymorphism, a Greek term means to ability to take more than one form.
o An operation may exhibits different behaviors in different instances. The behavior depends upon
the type of data used in the operation.
o For example consider the operation of addition for two numbers; the operation will generate a
sum. If the operands are string then the operation would produce a third string by concatenation.
o The process of making an operator to exhibit different behavior in different instances is known
operator overloading.
➢ OOP offers several benefits to both the program designer & the user
o Through inheritance, we can eliminate redundant code and extend the use of existing class
o We can build programs from the standard working module the communicate with one another,
rather than having to start writing code from scratch. This leads to saving of development time &
higher productivity.
o The principle of data hiding helps the programmer to build & secure programs.
o It is possible to map objects in the problem domain to those in the program Object-oriented
systems can be easily upgraded from small to large systems.
o Message passing techniques for communication between objects makes the interface
descriptions with external systems much simpler.
➢ Depending upon the features of OOP the language supports, they can be classified into the following two
categories:
o 1. Object based programming language:- It supports features like data encapsulation, data hiding,
automatic initialization of object and operator overloading.
o 2. Object oriented programming language:- It supports Object based features + inheritance +
dynamic binding
1.7 Structure of c++ Program
➢ C++ program is structured in a specific and particular manner. In C++, a program is divided into the
following three sections:
1. Standard Libraries Section
2. Main Function Section
3. Function Body Section
➢ For example, let’s look at the implementation of the Hello World program:
1.12 Manipulators
➢ Manipulators are operators used in C++ for formatting output.
➢ The data is manipulated by the programmer’s choice of display.
1. endl Manipulator:
o This manipulator has the same functionality as the ‘\n’ newline character.
o For example:
1. cout << "Exforsys" << endl;
2. cout << "Training";
2. setw Manipulator:
o This manipulator sets the minimum field width on output.
o Syntax: setw(x)
o Here setw causes the number or string that follows it to be printed within a field of x characters
wide and x is the argument set in setw manipulator.
o The header file that must be included while using setw manipulator is.
3. setprecision Manipulator:
o The setprecision Manipulator is used with floating point numbers.
o It is used to set the number of digits printed to the right of the decimal point.
o This may be used in two forms:
• fixed
• Scientific
o These two forms are used when the keywords fixed or scientific are appropriately used before the
setprecision manipulator.
o The keyword fixed before the setprecision manipulator prints the floating point number in fixed
notation.
o The keyword scientific, before the setprecision manipulator, prints the floating point number in
scientific notation.
1.13 Enumeration
➢ Enumeration is a user defined data type in C/C++ language. It is used to assign names to the integral
constants which makes a program easy to read and maintain.
➢ The keyword “enum” is used to declare an enumeration.
➢ The following is the syntax of enums.
o enum enum_name{const1, const2, ........ };Here,
➢ enum_name - Any name given by user.
➢ const1, const2 - These are values of type flag.
➢ The enum keyword is also used to define the variables of enum type. There are two ways to define the
variables of enum type as follows -
o enum colors{red, black};
o enum suit{heart, diamond=8, spade=3, club};
1.15 ASSIGNMENT-1
1. Define POP and OOP. Write difference between POP and OOP.
2. Explain basic features of object oriented programming language.
3. Write advantages of OOP.
4. Explain scope resolution operator with example.
5. Write a short note on manipulators and enumeration.
6. Explain structure of C++ Program.
7. List application of OOP.