0% found this document useful (0 votes)
147 views10 pages

UNIT-1 Principle of OOP - Lecture - Notes - 212 - 4320702

The document discusses the principles of object-oriented programming including concepts like classes, objects, encapsulation, inheritance, polymorphism and more. It also covers basics of C++ programming including data types, operators, input/output and program structure.

Uploaded by

hiralbhavana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views10 pages

UNIT-1 Principle of OOP - Lecture - Notes - 212 - 4320702

The document discusses the principles of object-oriented programming including concepts like classes, objects, encapsulation, inheritance, polymorphism and more. It also covers basics of C++ programming including data types, operators, input/output and program structure.

Uploaded by

hiralbhavana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Unit 1 – Principles of OOP

1.1 Overview of Procedural/Structure Programming language

➢ This programming language is also known as Modular Programming.


➢ Medium size Programs written are more efficient and easier to understand.
➢ It use top down design model.
➢ Languages used in Procedural/structure Programming: FORTRAN, ALGOL, COBOL, BASIC, Pascal and C.
➢ Least importance given to data in this programming language.
➢ The primary focus is on functions :

1.2 The object-oriented Approach

➢ 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 Dept: CE BOOP (4320702) Semester-2


Unit 1 – Principles of OOP

1.3 Basic Concept of object-oriented Programming

➢ 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.

➢ A Class is a 3-Compartment Box encapsulating Data and Functions


o Classname (or identifier): identifies the class.
o Data Members or Variables (or attributes, states, fields):
contains the static attributes of the class.
o Member Functions (or methods, behaviors, operations):
▪ contains the dynamic operations of the class. The entire set of data and code of an object
can be made a user defined data type with the help of a class.

➢ 1.3.3 Data Encapsulation


o The wrapping up of data and functions into a single unit is known as encapsulation.
o The data is not accessible to the outside world, only those function which are wrapped in the can
access it.

2 Dept: CE BOOP (4320702) Semester-2


Unit 1 – Principles of OOP

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.4 Data Abstraction


o Abstraction refers to the act of representing essential features without including the background
details or explanations.
o Since classes use the concept of data abstraction, they are known as Abstract Data Types (ADT)

➢ 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.

➢ 1.3.7 Dynamic Binding


o Dynamic Binding means that the code associated with a given Procedure is not known until the
time of the call at run time.

➢ 1.3.8 Message Passing


o Message passing involves specifying the name of object, the name of the function and the
information to be sent.

1.4 Advantages of Object Oriented Programming

➢ 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.

3 Dept: CE BOOP (4320702) Semester-2


Unit 1 – Principles of OOP

o Software complexity can be easily managed.


o It is easy to partition the work in a project based on objects.
o The data-centered design approach enables us to capture more details of a model in
implementable form.

1.5 Usage / Applications of Object Oriented Programming

➢ The promising areas for application of OOP include:


o Real-time systems
o Simulation and modeling
o Object-oriented databases
o Hypertext, hypermedia
o Al and expert systems
o Neural networks and parallel programming
o Decision support and office automation systems
o CIM/CAM/CAD systems

1.6 Object Oriented Programming languages

➢ 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:

4 Dept: CE BOOP (4320702) Semester-2


Unit 1 – Principles of OOP

➢ Standard libraries section


o #include is a specific preprocessor command that effectively copies and pastes the entire text of
the file, specified between the angle brackets, into the source code.
o The file <iostream>, which is a standard file that should come with the C++ compiler, is short for
input-output streams. This command contains code for displaying and getting an input from the
user.
o namespace is a prefix that is applied to all the names in a certain set. iostream file defines two
names used in this program - cout and endl.
o This code is saying: Use the cout and endl tools from the std toolbox.
➢ Main function section
o The starting point of all C++ programs is the main function.
o This function is called by the operating system when your program is executed by the computer.
o { signifies the start of a block of code, and } signifies the end.
➢ Function body section
o This part contains the definition of functions. The definition of function can also be written
outside the class but before main function.

1.8 Basic Data types


➢ The table below shows the fundamental data types, their meaning, and their sizes (in bytes):

5 Dept: CE BOOP (4320702) Semester-2


Unit 1 – Principles of OOP

1.9 Input using cin


➢ The cin object is used to accept input from the standard input device i.e. keyboard. It is defined in the
iostream header file.

1.10 Overview of operators


➢ Operators are used to perform operations on variables and values.
➢ C++ divides the operators into the following groups:
1. Arithmetic operators:- +,-,*,/,%,++,-2.
2. Assignment operators:-=,+=,-=,*=,/=,%=,&=,|=,^=,>>=,<<=
3. Comparison operators:==,!=,>,<,>=,<=
4. Logical operators:&&,||,!
5. Bitwise operators:&,|,^,!
6. Scope Resolution operators:-::
1.11 Scope Resolution operator
➢ The scope resolution operator ( :: ) is used for several reasons.
➢ For example: If the global variable name is same as local variable name, the scope resolution operator
will be used to call the global variable.
➢ It is also used to define a function outside the class and used to access the static variables of class.

6 Dept: CE BOOP (4320702) Semester-2


Unit 1 – Principles of OOP

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.

7 Dept: CE BOOP (4320702) Semester-2


Unit 1 – Principles of OOP

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.

8 Dept: CE BOOP (4320702) Semester-2


Unit 1 – Principles of OOP

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};

9 Dept: CE BOOP (4320702) Semester-2


Unit 1 – Principles of OOP

1.14 Difference between POP & OOP

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.

10 Dept: CE BOOP (4320702) Semester-2

You might also like