Chap: 1: Procedural Oriented Programming (POP)
Chap: 1: Procedural Oriented Programming (POP)
The data items may be global and hence accessible by many functions
Global data are more vulnerable to change by a function in a large program. It is very
difficult to identify what data is used by which function since many function access same
data, the way the data is stored becomes critical. The arrangement of data can't be changed
without modifying all functions that access it. If new data items are added you need to
modify all function that the access so that it can access new items.
Another Drawback with the Procedural approach is that it does not model real world
problem very well. In Procedural Oriented approach there are more problems when
programs are larger and complex.
C++ is an Object Oriented Programming Language. Initially it was named "C with Classes".
C++ was developed by "BJARNE STROUPSTRAUP".
FEATURES / CHARACTERISTICS:
POP:
Objects are basic runtime entities in an Object oriented system. Object may
represent a person, a place, a bank a/c or any item that a program has to handle.
Program object should be chose such that they match closely with real world
objects. Object takes up space in the memory when the program is executed. The
objects interact by sending messages to one another.
For Example:
If Customer and account are two Objects in a program, then a customer object may
send a message to account Object requesting for the bank balance.
Each object contains data and code to manipulate the data. Objects can interact
without having to know the details of each other's data or code.
CLASS:
The entire set of data and code of an object can be made into a user-defined data-
type of a class. Objects are the variables of type class. Once a class has been defined
we can create any number of objects belonging to that class. Each object is
associated with data of type class with which they are created. A class is a collection
of object of similar type.
Example: Mango, apple, oranges etc. from class fruit. Classes are user-defined data-
types and behave like built-in data-types of programming language.
The wrapping up of data of a function into a single unit called Class is called
"Encapsulation".
The data is not accessible to outside world and only those functions which are
wrapped in class can access it. These functions provide an interface between Object
Data and Programs.
The insulation of data from direct access by the program is called as "Data Hiding".
Abstraction refers to the act of representing essential features without including the
background details or explanation.
Classes use the concept of abstraction. They are defined as a list of abstract
attributes such as size, weight, cost and function to operate on these attributes. They
encapsulate all essential properties of the object that are to be created.
Since classes use the concept of abstraction they are known as abstract data-types,
attributes are called members and functions that operate in these data are called
member functions.
INHERITANCE:
POLYMORPHISM:
Polymorphism is a Greek term which means ability to take more than one forms.
An operation may exhibit different behaviour in different instances. The behaviour
depends upon the types of data used in the operation.
For Example:
The operation of addition will generate a sum. But if then open hands are
strings then the operation will result in third string by concatenation.
DYNAMIC BINDING:
Binding refers to linking of a procedure call to the code to be executed in response to the
call. Dynamic Binding is also known as "Late Binding" means that the code associated with
given procedure call is not known until the time of the call at runtime. It is associated with
the polymorphism and inheritance.
MESSAGE PASSING:
An object oriented program consists of a set of object that communicates with each
other.
Programming in an Object Oriented Language consists of following steps:
i. Creating classes that defines object and behaviour.
A message for an object is a request for execution of a procedure and therefore will invoke a
function in the receiving object that generates the desired result. Message Passing involves
specifying the name of the function (message) and the information to be sent.
Applications Of C++:
I. Used for any real life application system editor, complier, database, communication
system.
II. Object Oriented Libraries can be built by C++.
III. C++ programs can be easily implemented maintained and expanded.
Operators in C++:
#include<iostream.h>
Void main()
{
Cout << "C with classes"; (<< - Insertion or put to operator)
Cin >> a; (>> - Extraction or get from operator)
}