Oop Introduction ND CPP
Oop Introduction ND CPP
On the other hand, object oriented languages are based on entities known as
Objects, their actions known as Methods and forms a group known as A Class.
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
Example: C++, C#, java.
OOP treats data as a critical element in the program development. It ties data more
closely to the functions that operate on it, and protects it from accidental modification
from outside functions.
OOP allows decomposition of a problem into a number of entities called objects and
then builds data and functions around these objects.
1. Objects: Objects are the basic run-time entities in an object-oriented system. They
may represent a person, a place, a bank account, a table of data or any item that the
program has to handle. Object = data + method.
2. Classes: A class is a collection of objects of similar type. For example, mango, apple
and orange are members of the class fruit.
Classes are user-defined data types and behave like the built-in types of a
programming language.
The wrapping up of data and functions into a single unit (called class) is known as
encapsulation. With Encapsulation, The data is not accessible to the outside world.
Only those functions which are wrapped in the class can access it.
Abstraction refers to the act of representing essential features without including the
background details or explanations.
4. Inheritance: In OOP, the concept of inheritance provides the idea of reusability.
Inheritance is the process defining a new class (sub) from Existing class (super).
It supports the concept of hierarchical classification. For example, the bird 'duck’,
‘cuckoo’ and ‘ostrich’ are part of the class ‘bird'.
5. Polymorphism:
Polymorphism, a Greek term, means the ability to take more than one form.
An operation may exhibit different behaviours in different instances. The behaviour
depends upon the types of data used in the operation.
For example, consider an object shape. A shape may have many forms such as Line,
Triangle, Rectangle, and Circle...etc.
6. Dynamic Binding:
Binding refers to the linking of a procedure call to the code to be executed in response
to the call. Dynamic binding (also known as late 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.
7. Message Passing: Objects communicate with one another by sending and receiving
information.
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).
History of CPP:
The C programming language was devised in the early 1970s by Dennis M. Ritchie an
employee from Bell Labs (AT&T).
Many other programming languages are derived from the C language.
The languages Objective-C and C++ for instance are derived from the C language.
Both languages add the “object oriented” element to the language C. One of the most
recent languages, that used much of the C language, is Java.
The programming language C++ (originally named “C with Classes”) was devised by
Bjarne Stroustrup also an employee from Bell Labs (AT&T). Stroustrup started working
on C with Classes in 1979.
The idea of creating a new language originated from a wish, to do things that were not
possible with other languages. He had experience with the language Simula and BCPL.
Simula, short for "simulation language," was the first programming language in the
late 1960s.
So he chose to enhance the C language with Simula-like features, because the C
language was fast and portable. Stroustrup did not only use features from Simula but
also borrowed features from the languages Ada, CLU, ALGOL 68 and ML.
In 1983, the name of the language was changed from C with Classes to C++.
(The ++ indicates increment as in C language ).
The first commercial release of the C++ language was in October of 1985.
In 1989, version 2.0 was released of the C++ language.
In 1990, “The Annotated C++ Reference Manual” was published. This work became the
basis for the future standard.
In 1998, a joint ANSI-ISO committee standardized the C++ language.
A simple C+ + program:
// Simple C++ program to display "Hello World"
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello World";
return 0;
}
Output:
Let us now understand every line and the terminologies of the above
program:
2. #include<iostream> :
4. int main():
5. { and }:
6. cout<<“Hello World”;:
This line tells the compiler to display the message “Hello World” on
the screen.
7. return 0; :
8. Indentation:
As you can see the cout and the return statement have been indented
or moved to the right side. This is done to make the code more
readable.
Explain the basic structure of C++:
Basic Structure of a C++ program:
The general structure of C++ program can be shown in following diagram.