Chapter 1
Chapter 1
with C++
Chapter One
Introduction to Object
Oriented Programming
INTRODUCTION
• A programming language is a language specifically designed
to express computations that can be performed by the
computer.
• Programming languages are used to create programs that
control the behaviour of a system, to express algorithms, or
can be used as a mode of human communication.
• The term ‘programming language’ usually refers to high-level
languages such as BASIC, C, C++, COBOL, FORTRAN,
ADA, and PASCAL, to name a few.
• While high-level programming languages are easy for us to
read and understand, the computer understands the machine
language that consists only of numbers.
INTRODUCTION
• The determination of the language is dependent on the
following factors:
• The type of computer (microcontroller, microprocessor, etc.)
on which the program has to be executed.
• The type of program (system program, application program,
etc.).
• The expertise of the programmer. That is, the proficiency level
of a programmer in a particular language.
INTRODUCTION
• If the source code contains errors, then the compiler will not
be able to do its intended task. Errors that limit the compiler in
understanding a program are called syntax errors.
• Examples of syntax errors are spelling mistakes, typing
mistakes, illegal characters, and use of undefined variables.
The other type of error is the logical error, which occurs when
the program does not function accurately.
• Logical errors are much harder to locate and correct than
syntax errors.
• Whenever errors are detected in the source code, the compiler
generates a list of error messages indicating the type of error
and the line in which the error has occurred.
Interpreter
• The interpreter executes instructions written in a high-level
language.
• A program written in a high-level language can be executed in
any of the two ways—by compiling the program or by passing
the program through an interpreter.
• Interpreter translates the instructions into an intermediate
form, which it then executes. The interpreter takes one
statement of high-level code, translates it into the machine
level code, executes it, and then takes the next statement and
repeats the process until the entire program is translated.
Compiler vs Interpreter
Linker
Disadvantages
• Writing programs is complex.
• No concept of reusability.
• Requires more time and effort to write
programs.
• Programs are difficult to maintain.
• Global data is shared and therefore may
get altered (mistakenly).
Structured Programming
• Not data-centered
• Global data is shared and
therefore may get inadvertently
modified
• Main focus on functions
Object Oriented
Programming
• It treats data as a critical element in the
program development and restricts its flow
freely around the system.
• The object oriented paradigm is task based
(as it considers operations) as well as data-
based (as these operations are grouped with
the relevant data).
• Every object contains some data and the
operations, methods, or functions that
operate on that data. While some objects
Object Oriented Programming contd.
• May contain only basic data types such as characters, integers,
floating types, the other object, the other objects on the other
hand may incorporate complex data types such as trees or
graphs.
• Programs that need the object will access the object’s methods
through a specific interface. The interface specifies how to
send a message to the object, that is, a request for a certain
operation to be performed.
• The programs are data centered.
• Programs are divided in terms of objects and not procedures.
• Functions that operate on data are tied together with the data.
Object Oriented Programming contd.
• Parallel programming
• Decision control systems
• Office automation systems
• Networks for programming routers, firewalls, and other
devices
• Computer-aided design (CAD) systems
• Computer-aided manufacturing (CAM) systems
• Computer animation
• Developing computer games
• Hypertext and hypermedia
Differences between C and C++