KARPAGAM ACADEMY OF HIGHER EDUCATION
CLASS: I B.Sc. CT COURSE NAME: Object Oriented Programming Using C++
COURSE CODE: 20CTU101 UNIT - I BATCH: 2020 – 2023
Unit I
Introduction -Principles of object-oriented programming: Basic concepts of object-
oriented programming –
Benefits of OOP – Applications of OOPs – Structure of C++ Program C++ Tokens –
Control Statement – Decision Making Statements- Loop Statements - Inline Functions – Friend
Function - Function Overloading.
INTRODUCTION
Programmers write instructions in various programming languages to perform their computation
tasks such as:
(i) Machine level Language
(ii) Assembly level Language
(iii) High level Language
Machine level Language :
Machine code or machine language is a set of instructions executed directly by a computer's central
processing unit (CPU). Each instruction performs a very specific task, such as a load, a jump, or an
ALU operation on a unit of data in a CPU register or memory. Every program directly executed by a
CPU is made up of a series of such instructions.
Assembly level Language :
An assembly language (or assembler language) is a low-level programming language for a computer,
or other programmable device, in which there is a very strong (generally one-to-one) correspondence
between the language and the architecture's machine code instructions. Assembly language is
converted into executable machine code by a utility program referred to as an assembler; the
conversion process is referred to as assembly, or assembling the code.
High level Language :
High-level language is any programming language that enables development of a program in much
simpler programming context and is generally independent of the computer's hardware architecture.
High-level language has a higher level of abstraction from the computer, and focuses more on the
programming logic rather than the underlying hardware components such as memory addressing and
register utilization.
The first high-level programming languages were designed in the 1950s. Now there are dozens of
P a g e 1 | 45
Prepared by Dr.B.Firdaus Begam, Asst Prof, Dept of Computer Science, KAHE
, KARPAGAM ACADEMY OF HIGHER EDUCATION
different CLASS:
languages, including
I B.Sc. CT Ada , Algol, BASIC,
COURSE COBOL,
NAME: Object C, C++, JAVA,
Oriented FORTRAN,
Programming Using LISP,
C++
COURSE CODE: 20CTU101 UNIT - I BATCH: 2020 – 2023
Pascal, and Prolog. Such languages are considered high-level because they are closer to human
languages and farther from machine languages. In contrast, assembly languages are considered
low-level because they are very close to machine languages.
The high-level programming languages are broadly categorized in to two categories:
(i) Procedure oriented programming(POP) language.
(ii) Object oriented programming(OOP) language.
Procedure Oriented Programming Language
In the procedure oriented approach, the problem is viewed as sequence of things to be done such as
reading , calculation and printing.
Procedure oriented programming basically consist of writing a list of instruction or actions for the
computer to follow and organizing these instruction into groups known as functions.
The disadvantage of the procedure oriented programming languages is:
1. Global data access
2. It does not model real word problem very well
3. No data hiding
P a g e 2 | 45
Prepared by Dr.B.Firdaus Begam, Asst Prof, Dept of Computer Science, KAHE
, KARPAGAM ACADEMY OF HIGHER EDUCATION
Local data LocalI data
CLASS: B.Sc.Local
CT data COURSE NAME: Object Oriented Programming Using C++
COURSE CODE: 20CTU101 UNIT - I BATCH: 2020 – 2023
Characteristics of procedure oriented programming:
1. Emphasis is on doing things(algorithm)
2. Large programs are divided into smaller programs known as functions.
3. Most of the functions share global data
4. Data move openly around the system from function to function
5. Function transforms data from one form to another.
6. Employs top-down approach in program design
In the procedure oriented approach, the problem is viewed as the sequence of things to
be done such as reading, calculating and printing such as cobol, fortran and c. The
primary focus is on functions. A typical structure for procedural programming is shown
in fig.1.2. The technique of hierarchical decomposition has been used to specify the tasks
to be completed for solving a problem.
Main Program
Function-1 Function-2 Function-3
Function-4
Function-5
Function-6 Function-7 Function-8
Fig. 1.2 Typical structure of procedural oriented programs
Procedure oriented programming basically consists of writing a list of instructions for the computer to follow,
and organizing these instructions into groups known as functions. We normally use flowcharts to organize these actions
and represent the flow of control from one action to another.
In a multi-function program, many important data items are placed as global so that
they may be accessed by all the functions. Each function may have its own local data.
P a g e 3 | 45
Prepared by Dr.B.Firdaus Begam, Asst Prof, Dept of Computer Science, KAHE
, KARPAGAM ACADEMY OF HIGHER EDUCATION
Global data
CLASS:areI more vulnerable to an
B.Sc. CT inadvertent
COURSE NAME:change by a function.
Object Oriented In a large
Programming Using C++
program COURSE
it is veryCODE:
difficult to identify what data
20CTU101 is used
UNIT - I by which function.
BATCH:In case– we
2020 2023
need to revise an
external data structure, we also need to revise all functions that access the data. This
provides an opportunity for bugs to creep in.
Another serious drawback with the procedural approach is that we do not model real
world problems very well. This is because functions are action-oriented and do not really
corresponding to the element of the problem.
Some Characteristics exhibited by procedure-oriented programming are:
Emphasis is on doing things (algorithms).
Large programs are divided into smaller programs known as functions.
Most of the functions share global data.
Data move openly around the system from function to function.
Functions transform data from one form to another.
Employs top-down approach in program design.
Object Oriented Paradigm
The major motivating factor in the invention of object-oriented approach is to remove
some of the flaws encountered in the procedural approach. OOP treats data as a critical
element in the program development and does not allow it to flow freely around the
system. It ties data more closely to the function that operate on it, and protects it from
accidental modification from outside function. OOP allows decomposition of a problem
into a number of entities called objects and then builds data and function around these
objects. The organization of data and function in object-oriented programs is shown in
fig.1.3. The data of an object can be accessed only by the function associated with that
object. However, function of one object can access the function of other objects.
Organization of data and function in OOP
P a g e 4 | 45
Prepared by Dr.B.Firdaus Begam, Asst Prof, Dept of Computer Science, KAHE
CLASS: I B.Sc. CT COURSE NAME: Object Oriented Programming Using C++
COURSE CODE: 20CTU101 UNIT - I BATCH: 2020 – 2023
Unit I
Introduction -Principles of object-oriented programming: Basic concepts of object-
oriented programming –
Benefits of OOP – Applications of OOPs – Structure of C++ Program C++ Tokens –
Control Statement – Decision Making Statements- Loop Statements - Inline Functions – Friend
Function - Function Overloading.
INTRODUCTION
Programmers write instructions in various programming languages to perform their computation
tasks such as:
(i) Machine level Language
(ii) Assembly level Language
(iii) High level Language
Machine level Language :
Machine code or machine language is a set of instructions executed directly by a computer's central
processing unit (CPU). Each instruction performs a very specific task, such as a load, a jump, or an
ALU operation on a unit of data in a CPU register or memory. Every program directly executed by a
CPU is made up of a series of such instructions.
Assembly level Language :
An assembly language (or assembler language) is a low-level programming language for a computer,
or other programmable device, in which there is a very strong (generally one-to-one) correspondence
between the language and the architecture's machine code instructions. Assembly language is
converted into executable machine code by a utility program referred to as an assembler; the
conversion process is referred to as assembly, or assembling the code.
High level Language :
High-level language is any programming language that enables development of a program in much
simpler programming context and is generally independent of the computer's hardware architecture.
High-level language has a higher level of abstraction from the computer, and focuses more on the
programming logic rather than the underlying hardware components such as memory addressing and
register utilization.
The first high-level programming languages were designed in the 1950s. Now there are dozens of
P a g e 1 | 45
Prepared by Dr.B.Firdaus Begam, Asst Prof, Dept of Computer Science, KAHE
, KARPAGAM ACADEMY OF HIGHER EDUCATION
different CLASS:
languages, including
I B.Sc. CT Ada , Algol, BASIC,
COURSE COBOL,
NAME: Object C, C++, JAVA,
Oriented FORTRAN,
Programming Using LISP,
C++
COURSE CODE: 20CTU101 UNIT - I BATCH: 2020 – 2023
Pascal, and Prolog. Such languages are considered high-level because they are closer to human
languages and farther from machine languages. In contrast, assembly languages are considered
low-level because they are very close to machine languages.
The high-level programming languages are broadly categorized in to two categories:
(i) Procedure oriented programming(POP) language.
(ii) Object oriented programming(OOP) language.
Procedure Oriented Programming Language
In the procedure oriented approach, the problem is viewed as sequence of things to be done such as
reading , calculation and printing.
Procedure oriented programming basically consist of writing a list of instruction or actions for the
computer to follow and organizing these instruction into groups known as functions.
The disadvantage of the procedure oriented programming languages is:
1. Global data access
2. It does not model real word problem very well
3. No data hiding
P a g e 2 | 45
Prepared by Dr.B.Firdaus Begam, Asst Prof, Dept of Computer Science, KAHE
, KARPAGAM ACADEMY OF HIGHER EDUCATION
Local data LocalI data
CLASS: B.Sc.Local
CT data COURSE NAME: Object Oriented Programming Using C++
COURSE CODE: 20CTU101 UNIT - I BATCH: 2020 – 2023
Characteristics of procedure oriented programming:
1. Emphasis is on doing things(algorithm)
2. Large programs are divided into smaller programs known as functions.
3. Most of the functions share global data
4. Data move openly around the system from function to function
5. Function transforms data from one form to another.
6. Employs top-down approach in program design
In the procedure oriented approach, the problem is viewed as the sequence of things to
be done such as reading, calculating and printing such as cobol, fortran and c. The
primary focus is on functions. A typical structure for procedural programming is shown
in fig.1.2. The technique of hierarchical decomposition has been used to specify the tasks
to be completed for solving a problem.
Main Program
Function-1 Function-2 Function-3
Function-4
Function-5
Function-6 Function-7 Function-8
Fig. 1.2 Typical structure of procedural oriented programs
Procedure oriented programming basically consists of writing a list of instructions for the computer to follow,
and organizing these instructions into groups known as functions. We normally use flowcharts to organize these actions
and represent the flow of control from one action to another.
In a multi-function program, many important data items are placed as global so that
they may be accessed by all the functions. Each function may have its own local data.
P a g e 3 | 45
Prepared by Dr.B.Firdaus Begam, Asst Prof, Dept of Computer Science, KAHE
, KARPAGAM ACADEMY OF HIGHER EDUCATION
Global data
CLASS:areI more vulnerable to an
B.Sc. CT inadvertent
COURSE NAME:change by a function.
Object Oriented In a large
Programming Using C++
program COURSE
it is veryCODE:
difficult to identify what data
20CTU101 is used
UNIT - I by which function.
BATCH:In case– we
2020 2023
need to revise an
external data structure, we also need to revise all functions that access the data. This
provides an opportunity for bugs to creep in.
Another serious drawback with the procedural approach is that we do not model real
world problems very well. This is because functions are action-oriented and do not really
corresponding to the element of the problem.
Some Characteristics exhibited by procedure-oriented programming are:
Emphasis is on doing things (algorithms).
Large programs are divided into smaller programs known as functions.
Most of the functions share global data.
Data move openly around the system from function to function.
Functions transform data from one form to another.
Employs top-down approach in program design.
Object Oriented Paradigm
The major motivating factor in the invention of object-oriented approach is to remove
some of the flaws encountered in the procedural approach. OOP treats data as a critical
element in the program development and does not allow it to flow freely around the
system. It ties data more closely to the function that operate on it, and protects it from
accidental modification from outside function. OOP allows decomposition of a problem
into a number of entities called objects and then builds data and function around these
objects. The organization of data and function in object-oriented programs is shown in
fig.1.3. The data of an object can be accessed only by the function associated with that
object. However, function of one object can access the function of other objects.
Organization of data and function in OOP
P a g e 4 | 45
Prepared by Dr.B.Firdaus Begam, Asst Prof, Dept of Computer Science, KAHE