R19 OOPS Unit 1 (Ref-2)
R19 OOPS Unit 1 (Ref-2)
www.Jntufastupdates.com 1
UNIT – 1
Introduction to C++ , Difference between C and C++- Evolution of C++- The Object
Oriented Technology- Disadvantage of Conventional Programming- Key Concepts
of Object Oriented Programming- Advantage of OOP- Object Oriented Language.
In 1983, "C with Classes" was renamed to "C++" . The thought of C++ came from the C
increment operator ++. Rick Mascitti coined the term C++ in 1983. C++ is superset of C.
All the concepts of C are applicable to C++ also. For developing complicated
applications, Object Oriented language such as C++is the most convenient and easy.
C SIMULA 67
C++
C C++
It is Procedure Oriented Programming It is Object Oriented Programming
language language
C was developed by Dennis Ritchie C++ was developed by Bjarne
between 1969 . Stroustrup in 1979 .
C is a subset of C++. C++ is a superset of C. C++ can run
most of C code while C cannot run C++
code.
www.Jntufastupdates.com 2
Data is not protected in C Data is secured in C++ using data
hiding concept
C uses stdio.h file for input and output C++ uses iostream.h for these functions
functions
Nature is composed of different objects. Living beings can be categorized into different
objects. For eg, An institute is divided into different departments such as class room,
laboratory , library etc. Each one perform its own activities in association with other
departments. Each department may be considered as a module and it contains classes
and objects in C++ language. These classes and objects can be extended in life .
Generally, objects are in terms of entities. In OOP, objects of a program interact by
sending messages to each other.
Each Department has its own work. It is comfortable to accomplish goals and objectives.
The activities are carried out smoothly. The burden of one particular department has to
be shared among different departments with personnel. The staff in the department is
controlled properly and act according to the instructions laid down by the management.
The faculty performs activities related to the teaching. If the higher authority needs to
know the details regarding theory, laboratory, seminar and project loads of individual
faculty, then a person from the department accesses the data and provides the higher
authority with the requisite information. It is also good to think that no unconnected
person from another department reads the data or attempts to make any alteration that
might corrupt the data.
www.Jntufastupdates.com 3
Computer Lab
Class Room
Library
www.Jntufastupdates.com 5
Disadvantages:
1. Large programs are divided into smaller programs known as functions. These
functions can call one another. Hence security is not provided.
2. No importance is given to security of data and importance is given to doing things.
3. Data move openly around the system from function to function.
4. Most functions accesses global data, what happens to the data is not known.
1) Objects
Objects are the basic run time entities of real world. They are instances of class, which
have data members and uses various member functions to perform tasks. Objects may
represent a person, a place, a bank account.
When a program is executed, the objects interact by sending messages to one another.
For example, if “customer” and “account” are to objects in a program, then the customer
object may send a message to the account object requesting for the bank balance. Each
object contain data, and code to manipulate data. Objects can interact without having to
know details of each other’s data or code.
www.Jntufastupdates.com 6
2) Class:
It is similar to structures in C language. The collection of similar objects is called a class.
Class binds the data and its related functions together. Class is a user-defined data type
but behaves as a built-in type. For eg, fruit is a class. Mango and apple are objects.
3) Data Abstraction
Abstraction refers to the act of representing essential features without including
background details or explanations. i.e Abstraction refers to showing only the essential
features of the application and hiding the details. In C++, classes provide methods to the
outside world to access & use the data variables, but the variables are hidden from
direct access. Abstraction is the procedure of identifying properties and methods
related to a specific entity. Classes use the theory of abstraction, they are known as
Abstract Data Types (ADT).
4) Encapsulation
The wrapping up of data and functions into a single unit is known as Encapsulation. i.e
a class is provides Encapsulation, because it groups data and its related functions
together into single unit. The data is not accessible by outside functions. The functions
that are defined in class can access the data. These functions prepare interface between
objects data and the program. Protecting the data from direct access by program is
called data hiding.
5) Inheritance:
It is the process by which objects of one class acquires the properties of objects of
another class. Inheritance is a way to reuse once written code again and again. The class
which is inherited is called base class & the class which inherits is called derived class.
So when, a derived class inherits a base class, the derived class can use all the functions
which are defined in base class, hence making code reusable. The programmer can add
the new properties to the existing class without changing it. This can be done by
deriving a new class from the existing class. The newclass will possess the features of
both the classes.
6) Polymorphism
It is the ability to take more than one form. Polymorphism makes the code more
readable. It is a feature, which will create functions with same name but different
arguments, which will perform differently. That is function with same name,
www.Jntufastupdates.com 7
functioning in different. Function overloading and operator overloading are the
examples of Polymorphism. Using a single function name to perform different type of
task is known as function overloading. The process of making an operator to exhibit
different behaviors in different instances is known as operator overloading.
Shape
Draw
7) Dynamic binding:
Binding refers to the linking of a procedure call to the code to be executed in response
to the call. Dynamic binding means that the code associated with a given procedure call
is not known until the time of the call at run time. It is associated with polymorphism
and inheritance. A function call associated with a polymorphic reference depends on
the dynamic type of that reference.
Consider the procedure “draw” in the above fig. by inheritance, every object will have
this procedure. Its algorithm is, however, unique to each object and so the draw
procedure will be redefined in each class that defines the object. At run-time, the code
matching the object under current reference will be called.
8) Message Passing:
An object-oriented program consists of a set of objects that communicate with each
other. The process of programming in an object-oriented language, involves the
following basic steps:
Objects communicate with one another by sending and receiving information much the
same way as people pass messages to one another. The concept of message passing
makes it easier to talk about building systems that directly model or simulate their real-
world counterparts. A Message for an object is a request for execution of a procedure,
and therefore will invoke a function (procedure) in the receiving object that generates
www.Jntufastupdates.com 8
the desired results. Message passing involves specifying the name of object, the name of
the function (message) and the information to be sent. Example:
Applications of OOP:
1. Real-time system
2. Simulation and modeling
3. Object-oriented data bases
4. Hypertext, Hypermedia, and expertext
5. AI and expert systems
6. Neural networks and parallel programming
7. Decision support and office automation systems
8. CIM/CAM/CAD systems
Advantages of OOP:
Disadvantage of OOP:
www.Jntufastupdates.com 9
Object based Vs Object Oriented Programming Languages:
The languages should support several of the OOP concepts to claim that they are object-
oriented. Depending upon the features they support, they can be classified into the
following two categories:
Languages that support programming with objects are said to the objects-based
programming languages. They do not support inheritance and dynamic binding. Ada is
a typical object-based programming language. Object-oriented programming language
incorporates all of object-based programming features along with two additional
features, namely, inheritance and dynamic binding. Object- oriented programming can
therefore be characterized by the following statements: Object-based features +
inheritance + dynamic binding.
www.Jntufastupdates.com 10
2) Class Declaration section
For example:
This section contains declaration section class Demo
of Class. You can declare a class and then {
declare data members and member int a, b;
functions inside that class. You can also public:
inherit one class from another existing void input();
class in this section. void output();
};
In above C++ structure the class declaration section and member function definition
section both together works as a server and main () function section works as a client.
www.Jntufastupdates.com 11
Because in main () function section we create an object of the class and then using that
object we make a call to the function declared in the class.
There are many languages which supports object oriented programming. The
following table describes OOP languages and features supported by them.
www.Jntufastupdates.com 12
Important Questions
8. How data and functions are organized in Object Oriented Program? Explain with
an example.
9. How does object oriented approach differ from object based approach? Give the
applications of OOP.
www.Jntufastupdates.com 13
10. What are the drawbacks of monolithic, procedural & structural programming
languages?
Structured Programming languages: These are based on the top down methodology in
which a system is further divided into compositional subsystem. The structured
programming concept was formalized in the year 1966 by Corrado Böhm and Giuseppe
Jacopini. They showed the theoretical computer program design with the aid of loops,
sequences and decisions.
Structured programming is not only limited to the top down approach. It employs
methods using:-
1. Top down analysis for problem solving: It focuses on dividing the problem into sub
parts and hence simplifies the problem solving.
3. Structured code for the individual modules: Control structures are used to
determine the exact order in which the set of instructions are to be executed. Therefore,
a structured code does not involve GOTO statement as it represents no certain order of
execution.
Object oriented Languages: Object oriented program languages are based on the
‘objects’ rather than ‘actions’. This language gives more preference to data rather than
logic. An object can be defined as the pairing of a piece of data with the operations that
can be performed on it. It is one of the latest and powerful types. Objects are capable of
storing information and they can also interact with other objects.
www.Jntufastupdates.com 14
The three major concepts defined by a object programming language are:-
1. Improved software
development productivity
1.Simple, easy due to modularity,
implementation of extensibility and
compilers and interpreters reusability.
1. Programs are more
2. The ability to re-use the 2. Software Maintenance is
easily and more quickly
same code at different improved
written
places in the program
without copying it. 3. Reusability helps in
2. Programs are reliable
faster development of
as fewer organizational
3. An easier way to keep programs, as the language
and logical errors occur
track of program flow. comes worth rich library of
during the initial stages
objects
of program development.
4. The ability to be strongly
modular or structured. 4. Lower cost of
Development
5. Needs only less memory.
5. Higher quality of
software can be ensured
Assignment Questions
3. How does object oriented approach differ from object based approach? Give the
applications of OOP.
www.Jntufastupdates.com 15