C++ Unit 1
C++ Unit 1
1
SU22A
Object Oriented Programming
Concepts Using C++
UNIT: I
2
Syllabus
Unit 1:
• Introduction to C++
3
SU22A – Object Oriented Programming Concept Using C++
Introduction to C++
• C++ is a cross-platform language that can be used to create high-
performance applications.
• The basic syntax and code structure of both C and C++ are the
same.
4
SU22A – Object Oriented Programming Concept Using C++
TM
FEATURES OF C++
• Simple: It is a simple language in the sense that programs can be
broken down into logical units and parts, has a rich library support and
a variety of data-types.
• Rich library support: Has a rich library support (Both standard ~ built-
in data structures, algorithms etc.) as well 3rd party libraries (e.g. Boost
libraries) for fast and rapid development.
.
• Compiled Language: C++ is a compiled language, contributing to its
speed.
5
SEE6C/SEZ6E – Client/Server Computing
TM
6
SEE6C/SEZ6E – Client/Server Computing
APPLICATIONS OF C++
TM
7
SEE6C/SEZ6E – Client/Server Computing
TM
8
SEE6C/SEZ6E – Client/Server Computing
TM
9
SEE6C/SEZ6E – Client/Server Computing
TM
OOPs Concept:
• Class
• Objects
• Data Abstraction
• Encapsulation
• Inheritance
• Polymorphism
• Dynamic Binding
• Message Passing
10
SEE6C/SEZ6E – Client/Server Computing
TM
CLASS
A class is a user-defined data type. It consists of data members and
member functions, which can be accessed and used by creating an
instance of that class. It represents the set of properties or methods that
are common to all objects of one type. A class is like a blueprint for an
object.
For Example: Consider the Class of Cars. There may be many cars
with different names and brands but all of them will share some
common properties like all of them will have 4 wheels, Speed Limit,
Mileage range, etc. So here, Car is the class, and wheels, speed limits,
mileage are their properties.
11
SEE6C/SEZ6E – Client/Server Computing
TM
OBJECT
It is a basic unit of Object-Oriented Programming and represents
the real-life entities. An Object is an instance of a Class. When a
class is defined, no memory is allocated but when it is instantiated
(i.e. an object is created) memory is allocated. An object has an
identity, state, and behaviour. Each object contains data and code to
manipulate the data. Objects can interact without having to know
details of each other’s data or code, it is sufficient to know the type of
message accepted and type of response returned by the objects.
12
SEE6C/SEZ6E – Client/Server Computing
DATA ABSTRACTION TM
ENCAPSULATION
Encapsulation is defined as the wrapping up of data under a
single unit. It is the mechanism that binds together code and the data
it manipulates. In Encapsulation, the variables or data of a class are
hidden from any other class and can be accessed only through any
member Function of their class in which they are declared. As in
encapsulation, the data in a class is hidden from other classes, so it is
also known as data-hiding.
14
SEE6C/SEZ6E – Client/Server Computing
INHERITANCE TM
16
SEE6C/SEZ6E – Client/Server Computing
TM
POLYMORPHISM
The word polymorphism mean is having many forms. In
simple words, we can define polymorphism as the ability of a
message to be displayed in more than one form. For
example, A person at the same time can have different
characteristics. Like a man at the same time is a father, a
husband, an employee. So the same person posses different
behaviour in different situations. This is called polymorphism.
17
SEE5C – Client/Server Computing
DYNAMIC BINDING
TM
MESSAGE PASSING
Objects communicate with one another by
sending and receiving information to each
other. 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 results. Message
passing involves specifying the name of the
object, the name of the function and the
information to be sent.
19
SEE6C/SEZ6E – Client/Server Computing
I/O Library Header Files TM
1 <iostream>
This file defines the cin,, cout,, cerr and clog objects, which correspond
to the standard input stream,, the standard output stream,, the un--
buffered standard error stream and the buffered standard error stream,
respectively.
2 <iomanip>
This file declares services useful for performing formatted I/O with so--
called parameterized stream manipulators, such as setw and
setprecision..
3 <fstream>
20
SEE6C/SEZ6E – Client/Server Computing
The Standard Output Stream (cout) TM
21
SEE6C/SEZ6E – Client/Server Computing
The Standard Input Stream (cin) TM
The predefined object cin is an instance of istream class. The cin object is said to
be attached to the standard input device, which usually is the keyboard. The cin is
used in conjunction with the stream extraction operator, which is written as >>
which are two greater than signs as shown in the following example.
When the above code is compiled and executed, it will prompt you
to enter a name. You enter a value and then hit enter to see the
following result −
Please enter your name: cplusplus
Your name is: cplusplus
22
SEE6C/SEZ6E – Client/Server Computing