Dr. T. Ratna Reddy
Evolution of various
languages.
Initially, when the computers were invented, the
binary language was used to write the programs.
‘As the programs grew in size, it became dificult
to write programs using binary language. Then
the assembly language was invented to write
large programs which was also not user friendly,
‘Then high level languages such as BASIC and
FORTRAN were developed. But these languages
tre unstructured programs. In unstructured
programming paradigm, all the instructions of 2
program were writen one after the other in 8
ingle function and hence, was suitable for writing
only small and simple programs. For large and
complex programs, it became dificult to trace and
debug errors. To overcome the limitations of
unstructured programming paradigm, other
programming paradigms such as procedural,
functional, modular, object oriented were
developed. Among these the procedural and
Object oriented are the most commonly used
programs.
Procedural programming paradigm
Structured programming also. known as
procedural programming was a powerful and eas
Approach of writing complex programs in
procedural programming, programs ere divided
into different procedures (also known a8
functions, routines or subroutines) and each
procedure contains a set of instructions that
perform a specific task. This approach folows the
top-down approach for designing the program.
rammins
‘Main program
aneton 3
OOP with C++ (PARTI)
2018-19
‘The emphasis is on the software rather than the data
used by the functions.
Procedural programming allows data to move freely
from one function to another function without any
ie the data to be shared among many
globally so that all the functions
Due to this corruption of data
seourit
functions is dectared
can easily access it
may be possible.
‘The procedural programming approach does not
represent realworld models very well 35 real-world
sntity is characterized not only by the functions it
performs but also the properties or dale it posses.
Pethaver, in procedural approach the data and the
esociated functions are loosely related.
‘Te large programs developed using this approach
re difficult to maintain, debug and extend.
‘The object oriented paradigm
To overcome the limitations of procedural
programming, ‘object-oriented programming paradigm
eewipoen developed which has revolutionized the
process of software development. It includes the best
Features of structured programming but also some
new and powerful features. These new OOP features
have tremendously helped in the development of
well-designed high-quality software.
‘OOP emphasizes on data rather than the functions or
the procedures
‘OOP models the real world very well by binding the
data and associated functions together under a single
unit and thus, prevents the free movement of data
from one function to another.
The data of one object can be accessed by the
associated functions of that object only. Other
functions are not allowed to access that ata. In other
words, data is hidden from the outside world.
However , the functions of one object can access the
functions of other object.
The objects of entire system can interact with each
other by sending messages to each other.
The programs written in OOP are easy to maintain
and extend as new objects can be easily added to the
existing system whenever required without modifying
the other objects.
Di, RATNA REDDY Associate Professor, CBIT. Mobile: 9985 666 778 Page 1Dr.T. Ratna Reddy OOP with C++ (PART-I) 2018-19
COP follows the bottom-up approach for
designing the programs. That is, first objects are
designed and then these objects are combined to
form the entire program.
Basic concepts of OOP
To understand the concept of object-oriented
programming, it is necessary to know the
fundamental terms and concepts of this approach.
These include objects, classes, data abstraction,
encapsulation, inheritance, polymorphism,
message passing and dynamic binding.
Object: Objects are the small, self-contained
modular units. An object consists of a state and
behavior. The state of an object is one of the
possible conditions that an object can exist in and
is represented by its characteristics or attributes
or data, The behavior of an object determines
how an object acts or behaves and is represented
by the variables and the operations are
represented by the functions.
= date
rt 4
a SS
rn
Class: A class is defined as a user defined data
type, which contains the entire set of data and
the functions that the objects possesses. A class
serves as a blueprint or template for its objects.
‘Once a class has been defined, any number of
objects belonging to that class can be created.
The objects of a class are also known as the
instances or the variables of that class and the
process of creating objects a class is known as
instantiation. Note that a class does not represent
an object, rather than it represents the data and
functions that an object should have.
Dr. T.RATNAREDDY Associate Professor , CBIT. Mobile:
Abstraction: abstraction is a mechanism to hide
irrelevant details and represent only the essential
features so that one can focus on important things at
a time. For example, while driving a car, a driver
knows the essential features to drive a car such as
how to use clutch, brake, accelerator, gears etc, and
least bothers about the internal details of the car like
engine, wiring etc.
‘Abstraction is of two types namely Data abstraction
and control abstraction. Data abstraction means
hiding the details about the data and control
abstraction means hiding the implementation details.
Encapsulation: encapsulation is the technique of
binding or keeping together the data and the
functions that operate on them, in a single unit called
a class. Encapsulation is the way to implement data
abstraction. A well-encapsulated object acts as a
‘black box’ for other parts of the program. That is, it
provides services to the extemal functions or other
objects that interact with it, However these external
functions or objects do not need to know its internal
details.
Inheritance: Inheritance can be defined as the
process whereby an object of a class acquires
characteristics from the object of the other class. As
stated earlier, all the objects of a similar kind are
grouped together to form a class. However,
sometimes a situation arises when different objects
cannot be combines together under a single group as
they share only some common characteristics. In this
situation, the classes are defined in such a way that
the common features are combined to form a
generalized class and the specific features are
combined to form a specialized class. The specialized
class is defined in such a way that in addition to the
individual characteristics and function, it also inherits
all the properties and the functions of its generalized
class.
9985 666778 Page 2OOP with C++ (PART-1)
2018-19
Dr. T. Ratna Reddy
Vehicles
“Automobiles Palledwehicles
a scooter | [Richa | [ Bicycle
Polymorphism: It allows single
nameloperator to be associated with different
operations depending on the type of data passed
to it. In C+* it is achieved by function over
loading, operator over loading and dynamic
bindingjvirtual functions).
Message Passing: The process of invoking an
operation on an object. In response to a message,
the corresponding method (function) is executed
in the object.
Procedure oriented | Object Oriented
T. | Programs ‘are | Programs care
divided into smaller | divides into objects
sub-programs & classes
known as functions
2, | Here global data is | Objects are easily
shared by most of | communicated
the functions with each other
through function.
3, |It is a Top-Down | It is a Bottom-Up
‘Approach ‘Approach
4, {Data cannot be|Data can be
secured and | secured and can
available to all the | be available in the
function lass in which it is
declared
Here, the | Here, we can reuse
5, | reusability is not|the exising one
| possible, hence | using the
redundant code | Inheritance
cannot be | concept
avoided.
Dr. T.RATNAREDDY Associate Professor , CBIT. Mobi
|. Tokens
‘Atoken is the smallest element of a C++ program
that is meaningful to the compiler. The C++ parser
recognizes these kinds of tokens: Identifiers,
Keywords, Literals, Operators, Punctuators, and
Other Separators. A stream of these tokens
makes up a transtation unit.
. Comments
‘A comment is text that the compiler ignores but
that is useful for programmers. Comments are
normally used to annotate code for future
reference.
‘A C++ comment is written in one of the following
ways:
v The / (slash, asterisk) characters, followed by
any sequence of characters (including new
lines), followed by the */ characters.
The II (two slashes) characters, followed by
any sequence of characters. A new line not
immediately preceded by a backslash
terminates this form of comment. Therefore, it
is commonly called a *single-line comment.”
This is an example of
comments in a program */
FileName = String( "hello.dat" ); // Initialize
file string
‘An identifier is a sequence of characters used to
denote one of the following:
Object or variable name
Class, structure, or union name
Enumerated type name
Member of a class, structure, union, or
enumeration
¥ Function or class-member function
typedef name
¥ Label name
The first character of an identifier must be an
alphabetic character, either uppercase oF
lowercase, or an underscore ( _ ). Because
C+ identifiers are case sensitive, fleName is
different from FileName.
SA848
: 9985 666 778 Page 3