0% found this document useful (0 votes)
17 views

c++ notes

C++ is an Object-Oriented Programming (OOP) language that enhances the procedural programming paradigm by incorporating features like data encapsulation, polymorphism, and inheritance, making it suitable for complex applications. Developed by Bjarne Stroustrup in the early 1980s, C++ allows for better data management and abstraction through the use of classes and objects. The document discusses the evolution of C++, its advantages over procedural languages, and key OOP concepts such as encapsulation, inheritance, and data hiding.
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

c++ notes

C++ is an Object-Oriented Programming (OOP) language that enhances the procedural programming paradigm by incorporating features like data encapsulation, polymorphism, and inheritance, making it suitable for complex applications. Developed by Bjarne Stroustrup in the early 1980s, C++ allows for better data management and abstraction through the use of classes and objects. The document discusses the evolution of C++, its advantages over procedural languages, and key OOP concepts such as encapsulation, inheritance, and data hiding.
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 5

C++ is an Object-Oriented Programming (OOP) language.

The Object-Oriented Programming


approach has attempted to handle the large complexities reliable and easily maintainable products.
The OOP approach has wide range in programs giving more clear ge of applications Artificial
Intelligence, Neural networks, simulation, Real-time systems etc.

C++ today's dominant computer language because of its striking features like Data Encapsulation,
Polymorphism, Inheritance ofc, which are not covered in the procedure oriented languages such as
Pascal, C. These features have benefits like easy upgradation of programs, reusability of code, data
secunty, clear view of system and simple interface descriptions with external systems.

This chapter focuses on the importance of Object Oriented Approach over Procedurial Oriented
approach, the basic concepts related to OOP and applications of OOP

Evolution of C++
C++ was developed by Bjarne Stroustrup at AT & T Bell Laboratories in Murray Hill, New Jersey,
USA, in the early 1980's. C++ is an extension of C with a major addition of the class construct
feature of Simula 67. Instiuly, Bjame Stroustrup called the new language "C with classes Rick
Mascitti coined the name C++ with addition of unary increment operator + representing
enhancement in C language in 1983. Thus, in 1983, the name was changed to C++

The most important elements added to C to create C++ are concerned with classes, objects and OOP
However, C++ has many other features as well, including an improved approach to 1/0 and a new
way to write comments.

Procedure-Oriented Programming
Fortran, Pascal, COBOL, C. and similar traditional programming languages are procedure oriented
languages. A program in a procedure-oriented language is a list of instructions and nach instruction
tells the computer to do something such as reading, writing and calculating

Main characteristics of Procedure - Oriented Programming


are :
A. Division Into Functions

In this approach, a large program divided indu functions and each function has a cinarly defined
purpose and a clearly defined interface.

This approach is also known as structured programming approach. No matter how well the
structured programming approach is implemented, large programs become excessively complex

B. Globalisation of Data
In procedure-oriented programming, the primary focus is on functions, in the development of
functions, data is given the least importance. To make the data accessed by all the function, they are
to be placed as global as shown in fig. 13. Making data global alows any function to manipulate it
but this may result in losing any important information.
Most language like Pascal and C also support local data, which is hidden within a singe function,
Fig. 1.4 shows the relationship between local and global data

Main problem in global data is that anyone can change or destroy the global data.

C. New Data Types

In this approach, it is very difficult to create the new data types like complex numbers dala type,
dates data type, two-dimensional co-ordinates data type etc. The property to create your own data
types is known as extensibility. Therefore, procedure-oriented languages are not usually extensible.

D. Relationship to the Real World


Another problem with procedural languages is that their primary components-functions and data
structures do not model the real world very well. For Example, Suppose you want to write the code
to create the elements of a graphics user interface (GUI) like menus, windows and so on, there are
no obvious program elements to which a menu or a window would correspon
E. Rich Library
C++ provides a lot of inbuilt functions that make the development fast. Following are the libraries
used in C++ programming are:
<iostream>
<cmath>
<cstdlib>
<fstream>

14) Object-Oriented
In C++, object-oriented concepts like data hiding, encapsulation, and data abstraction can easily be
implemented using keyword class, private, public, and protected access specifiers. Object-oriented
makes development and maintenance easier.

15) Compiler based


C++ is a compiler-based programming language, which means no C++ program can be executed
without compilation. C++ compiler is easily available, and it requires very little space for storage.
First, we need to compile our program using a compiler, and then we can execute our program.

Object-Oriented Programming
Object-Oriented Programming (OOP) approach binds the data and the functions the operate on that
data into a single entity. Such an entity is called an object. Functions of an object can only access its
data. You can't access the data directly. For example, you want to read a data item in an object, you
call a member function in t will mad the data item a n and retum the value to you. This secures data
from any changers from outside Thus, DOP gives more emphasis on data
A C++ program typically consists of a number of objects which communicate with eac other by
calling one anothers member functions. Calling an objects member functions also referred to as
sending a message to the object.

Objects are independent of each other. They are responsible for managing their own state and
offering services to other objects. Therefore, new objects can be easily added whenever necessary.

Concepts of Object-Oriented Programming


Let us discuss the characteristics of OOP

Objects
In procedure-granted programming, a program is dided into functions. Unike s object-orientest
programming, a program is dividied-sects in our day-to-day the, come across a number of objects.
Some examples are TV. telephone, car, computer, table, chair, washing machine inc. Each object
have the long wo charactenstice

1. State or Attributes
The state or atributes refers to the built-in charactentics of an object. For example, a color TV has
the following attributes :

Color reciever
Volume control
Picture control
128 channels
Remote control unit

2. Behavior or Operations
The behavior or operations of an object refers to its action. For example, a TV can behave in any of
the following manner at a given point of time
Switched on
Switched off
Displays picture and sound from a TV cable connection
a TV transmitter
a DVD
a VCR
Software objects can be visualized in a similar manner. Hence one of the most interesting Features
of OOP is that objects correspond to real objects.

Hence, an object consists of the following :

Data members

Member functions

The data members establish the state or attributes for the object. The behavior or operation of the
object is determined by the member functions. From the figure 1.6, it is clear that data can only
accessed through the member functions. The outside world can not directly accessed. The function
is the window to the outside world for accessing the data. Thus, the data is well-protected and
inadvertent manipulation thereof can be prevented.

Classes
A case is a group of objects that share common properties and relationships. For example Consider
a class fruit as shown

Mango, apple, banana etc are the objects of the class fruit.

Classes are user-defined data types and behave like the built-in types of a programming language
Objects are variables of the type class.

Defining the class doesnt create any objects, just as the mere existence of a type int does not create
any ant variable.

Data Abstraction

Abstraction refers to the act of representing essential features without waling t background details
or explanations. Let us consider the following examples.

1. A TV user can switch on the TV set and enjoy the various TV programme or HE/SHE swith from
one channel to another from selecting the desired TV programme without knowing its complete
technical details.

2. In order to drive a car, a person need not know all the parts in it. He can easily drive by using the
external interfaces, such as steering wheel, accelerator, brake and clutch This is abstraction.

The advantages of abstraction is that one can use an object without knowing all its deta This helps
the user to use an object with minimum information just enough information about how to interact
through the exdernal interface.

In OOP, the representation of important features (attributes and a functions) of an object done with
the help of a class. A class members (both data and functions) may be public or private. The private
members of class can not be accessed from outside the class However, the public members can be
accessed from outside the class.

Therefore, each object of a class will have extermal interfaces (Public members) through which it
can be made use of. There is no need to look into its inner details (Private members). The user
needs to know the edernal interfaces only to make use of an object. The internal details of the
objects are hidden which makes them abstract. The technique of hiding internal details in an
object is called data abstraction
Since the class use the concept of data abstraction, they are also known as Abstract Data Types
(ADT)

Data Hiding
Access to the private part of an object is restricted in the sense that the functions of the object can
only access the data. Thus, the private parts of the objects are not available outside the object and
cannot be altered by extemal changes. This property of an object is called an information hiding or
data hiding
Encapsulation

The wrapping up (or binding) of data and functions (that operate on the data) into a single unit
(called class) is known as encapsulation.
Encapsulation is the most fundamental concept of OOP. Thus, the inner parts of the program ane
sesaled or encapsulated to protect from accidental tampering. This feature is not available in
proceduse oriented programming languages where the data can be corrupted since its easily
accessible.

The student and library classes are independent of each other. The class student has no details about
class library. But the object of student class can comunicate within the obiect of library class in case
of book requirement by sending a message The best ofary accordingly respond to the message
received
Relation between encapsulation and Abstraction is shown in the figure 1.10

Inheritance
A child inherits the property of his parent. He can acquire new properties Seature of or modify the
use of OOP, which allows making intentand one. Similarly, wing changes to it This can be and class
Inherits al the p Inherited a (Deived class) from the dexating class (Base class) A denved the base
class. More properties can be adde of the complexity of the dienved class may grow as limit to the
level of inheritance the derived class all prope if needed. Thenfo level of inbentance grow. There
For example, scooter is a class in itself. It is also a member of two wheelers clatz wheelers class in
tum is a member of an automotive class as shown in figure 1.11
Automative
W
Two-Wheelers
Amibiles
Three-Wheelers
Anbutes
Four-Whesiers
Attributes
1.5
Scooter
Alrbules
Motor-Cycle
Attbutes
Bus
Attributes
Car
Attributes
FIGURE 111
Main advantage of inheritance is reusability. Reusability means that we can add ad features of an
existing class without modifying it as shown in figure 1.12
[12]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy