1. Basic Concepts of OOPs
Course Name:
Object Oriented
Programming with
C/C++
Course Code:
19008600
Computer Science
Engineering(Sem-III)
Faculty Name:
Zaiba Khan
Assistant Professor(CSE)
School of
Engineering &
Technology
2. Why do we need Object Oriented
Programming ?
Object Oriented Programming was
developed because limitations were
discovered in earlier approaches to
programming.
3. Procedure Oriented Programming(POP)
C, Pascal, Fortan and similar
languages are procedural languages.
Each statement in the language tells
the computer to do something:
◦ Get some input
◦ Add these numbers
◦ Divide by 6
◦ Display that output
A program in a procedural language is a list
of instructions.
4. Procedure Oriented Programming(POP)
Division into Functions:
◦ Procedural program is divided into
functions.
◦ Each function has clearly defined purpose
and a clearly defined interface to the other
functions in the program.
◦ It can be further extended by grouping a
number of functions together into a larger
entity called a module.
What are
functions?
6. Procedure Oriented Programming(POP)
Characteristics:
◦ Emphasis is on doing things (Algorithms)
◦ Large programs are divided into smaller
programs known as functions.
◦ Most of the functions share global data.
◦ Functions transform data from one form to
another.
◦ Top-down approach is used in program
design.
What is Top-
down
approach?
7. Procedure Oriented Programming(POP)
Top Down Approach:
◦ It is a process of breaking the overall
procedure or task into component parts
(modules) then subdivide each component
module until the lowest level of detail has
been reach.
◦ For Example: The payroll system of a
company can contain the following modules
or tasks
Master file
Earning
Deductions
Taxing
Net Earning
Print reports
8. Procedure Oriented Programming(POP)
Drawbacks:
◦ Since every function has complete access
to the global variables, the new
programmer can corrupt the data accidently
by creating functions.
◦ We can access the data of one function from
other since, there is no protection.
◦ In large data program it is very difficult to
identify what data is used by which function.
◦ Similarly, if new data is to be added, all the
function needed to be modified to access the
data.
◦ It does not model with the real world problem
very well.
9. Object Oriented
Programming(OOP)
OOP was introduced to overcome the
flaws in the procedural approach to
programming.
Such as like reusability and
maintainability.
The basic fundamental idea behind
OOP programming is to combine into
single unit both data and the functions
that operate on the data.
Such unit is called Object.
10. Object Oriented
Programming(OOP)
In OOP, problem is divided into the
number of entities called objects and
then builds data and functions around
these objects.
Data of an object can be accessed
only by the functions associated with
that object.
Communication of the objects done
through function.
12. Object Oriented
Programming(OOP)
Characteristics:
◦ Emphasis more on data rather than
procedure.
◦ Programs are divided into entities called
object.
◦ Data is hidden and cannot be accessed by
external functions.
◦ Objects communicate with each through
functions.
◦ New data and functions can be easily added
whenever necessary .
◦ Follow bottom up design in program design.
13. Object Oriented
Programming(OOP)
Bottom Up Approach:
◦ It is a reverse process of Top Down approach.
◦ Lower level task are carried out first and then
integrated to provide the solution of a single
program.
◦ Lower level structures of a program are evolved first.
◦ After that higher level structures are created.
◦ It promotes code reuse.
14. Summary:
Difference between POP & OOP
Procedural Oriented
Programming(POP)
In POP, program is divided into
small parts called functions.
In POP, Importance is not given to
data but to functions as well as
sequence of actions to be done.
POP follows Top Down approach.
POP does not have any access
specifier.
In POP, Data can move freely from
function to function in the system.
To add new data and function in
POP is not so easy.
POP does not have any proper way
for hiding data so it is less secure.
Example of POP are : C, VB,
FORTRAN, Pascal.
Object Oriented Programming(OOP)
OOP, program is divided into parts
called objects.
In OOP, Importance is given to the
data rather than procedures or
functions because it works as a real
world.
OOP follows Bottom Up approach.
OOP has access specifiers named
Public, Private, Protected, etc.
In OOP, objects can move and
communicate with each other
through member functions.
OOP provides an easy way to add
new data and function.
OOP provides Data Hiding so
provides more security.
Example of OOP are : C++, JAVA,
VB.NET, C#.NET.
15. Character Set in C++
There are four types of Character Set:
Character Set
1.Ank Letters Uppercase A-Z
Lowercase a-z
2. Digits All digits 0-9
3. Special
Characters
All symbols , : ,
;,!, !,$, &,,*,%,@,
{},[],()
4. White Spaces Blank Space,
Horizontal tab,
New Line
17. Constant in C++
It is an identifier whose value cannot be changed at the
execution time of program.
It can simply be defined as “constant “ can be used to
represent as fixed values in a C++ program. Classification is
as follows:
18. Variables in C++
Variables are used to store values.
Variable name is the name of memory location where value is
store.
It must be alphanumeric , only underscore is allowed in a
variable name.
Syntax:
Data-Type Variable Name
Examples:
int a;
float b;
char c;
Initialization of Variable:
Means assigning value to declared variable.
For example:
A= 10;
B=4.5;
C=‘a’;
Do You Know?
If no input
values are
assigned by the
user than
system will gives
a default value
called garbage
value.
19. Data Types in C++
A keyword to identify type of data. It is used for storing the
input of the program into the main memory (RAM)of the
computer.
There are three categories of data type. They are
20. Data Types in C++(Cont.)
Primitive Data Types
◦ These are the data types whose variable can hold maximum one value at a time.
Derived Data Types
◦ They are derived from fundamental data type.
◦ It allow us to store multiple values of same type in one variable BUT never allows to
store many values of different types.
Editor's Notes
Man is an intelligent specie, but still cannot perform all the task own its own. He rely on others. Like for food we rely on farmers, for groceries on food store. A computer find itself in the same situation. It cannot handle all the tasks own its own. In that case “Functions” are called
Main()
{
Message();
}
Message()
{
Printf{ “ Smile, and the world smiles with you”);
}
Top down approach which means that to solve a problem we first need to take a largest module and then it is solved so that small modules fit in that.
If any single character (alphabet or numeric or special symbol) is enclosed between single quotes ' ' known as single character constant.
If set of characters are enclosed between double quotes " " known as string character constant.