C++
UNIT: - 01
INTRODUCTION TO OBJECTS ORIENTED PROGRAMMING (OOP):
- Basic concept of OOPs
- Comparison of procedural
programming and OOP
- Advantages of OOP, OOP Languages
- Definitions: Class, Objects
- Concepts of inheritance and
encapsulation
- Operator overloading
- Dynamic binding
- Overview of OOP using C++
- Basic program construction: main and
functions, Program statements, class declaration, comments.
Some basic definition: -
1.
PROGRAM: - A program is set of instructions.
2.
Programming: - It is the process of arranging the data and instructions as per user
requirement.
3.
Software: - A set of program is called software.
OR
Software is a
digitalized, automated process. When the environment is having graphical user
interface then it is called digitalized. If the process is conducted without
human interface then it is called automated.
We are having two types of software:-
a. System software
b. Application
software
4.
Language: - A language allows to write the
programs to communicate with the computer.
Basic Concept of Object Oriented
Programming: -
1.
OOP (Object
Oriented Programming) is a type of programming where data types representing
data structures, which are defined by the programmer as well as properties, are
also defined by the programmers.
2.
With Object
Oriented Programming, programmers can create relationships between data
structures and create new data type based on existing ones.
3.
In Object Oriented
Programming, data types defined by the programmer are called classes.
4.
The drawbacks we
are facing in procedural oriented language, object oriented programming is
invented to solve that drawbacks.
5.
In object oriented
program, the data is a critical element in program development and doesn’t
allow it to flow freely around the system.
6.
Oops allows decomposing
a problem into a number of entities called objects and tied data and functions
around these entities.
7.
Some features of
object oriented programming language: -
a.
Class
b.
Object
c.
Data handling
d.
Encapsulation
e.
Abstraction
f.
Inheritance
g.
Polymorphism
h.
Message
communication
Comparison of procedural programming and OOP: -
Procedure Oriented Programming: -
1.
Prime
focus on functions and procedures that operate on data.
2. Procedure programs
are divided into smaller programs called function.
3. Data move freely
around the systems from one function to another.
4. Adding of new data
and functions in this programming is not easy.
5. Program design
follows “Top Down Approach”.
6. It doesn’t have any
proper way of data hiding that’s why it’s provide less security.
7. In POP, overloading
is not possible.
8.
E.g.
C, VB, FORTAN, Pascal
Object Oriented Programming: -
1.
Here more emphasis
is laid on the data is being operated and not the functions or procedures.
2.
Object oriented
programs are divided into smaller programs called object.
3.
Data is hidden
cannot be accessed by the external functions.
4.
It provides an easy
way to adding of new data and functions.
5.
Program design
follows “Bottom Up Approach”.
6.
It provides data
hiding that’s why it can provide better security.
7.
In OOP, overloading
is possible in the form of data function overloading and operator overloading.
8.
E.g. C++, JAVA,
C#.net, VB.net
Advantages of OOP, OOP Languages: -
Advantages of OOPs –
1.
Object oriented
programming defines the real world very well.
2.
Using
this object oriented language, programs are easy to understand and easy to
maintain.
3.
OOP
offers code reusability means write once use many times i.e. we can use already
created classes or code many times without having to write them again.
4.
It
provide facilitates of the quick development of programs and we can develop
parallel classes at a time.
5. Using OOP concept, it is easy to
test the programs, manage the programs and easy to debug.
Disadvantages of OOP –
1. With Object Oriented Programming,
sometime classes tend be over-generalized.
2.
OOPs
typically involve more lines of code than procedural programs.
3.
The Object
Oriented Programming design is tricky and requires appropriate knowledge.
4.
Object-oriented
programs are typically slower than procedure based programs, as they typically
require more instructions to be executed.
5.
To
program with Object Oriented Programming, the programmer needs proper skills of
programming such as design, programming and thinking in terms of objects and
classes etc.
OOPs
Language: -
1. Language which treated
consistently as an object, from primitives such as characters and punctuation,
all the way up to whole classes, prototypes, blocks, modules, etc. are called
pure object oriented languages.
2. Examples of OOPs languages are
Python, Ruby, Scala, etc.
3. There are some languages which
are designed mainly for OO programming, but they have some procedural elements
like C++, JAVA, C#, Pascal, VB.NET etc.
NOTE: - Before discussing about
upcoming topics we must know all are the features of OOPs language which is most important question according to
examination purpose and this question will ask from know to till last semester
Definitions: Class, Objects: -
CLASS:
-
1. Class is a
container which contains data and operations.
2. Class is
encapsulated with information and instructions.
3. Class is a data
type / user defined data type.
4. Class is a blue
print or object. (Blue print is nothing but a planning before constructing an
object)
5. Class is a logical
view of object.
6. Class is collection
of members.
a. Data members
(variables)
b. Member functions
(functions)
OBJECT:
-
1. Object is a
variable type class.
2. Object is an
instance of a class.
3. Object is the
physical representation of class.
4. When the object is
created then only the memory is allocated for data members.
5. One class is
declared we can define any number of objects form that class.
6. An object is a
collection of data members and associated member functions also known as
methods.
We can see some real life example of class
and object in C++ to understand the difference well: -
We will see an example of class which have two fields: id and name.
Object of the class will initializes and prints value of the object
#include <iostream.h>
Class Student
{
int id; // data member or instance variable
string name; // data member or instance variable
};
int main ()
{
Student Stu1; //creating an
object of student
Stu1.id=007;
Stu1.name = “MS Dhoni”;
cout<<Stu1.id<<endl;
cout<<Stu1.name<<endl;
return 0;
}
OUTPUT: -
007
MS Dhoni
NOTE: -
We will see in depth about object and class in
upcoming units and also see features of OOPs.
Concepts
of inheritance, encapsulation, polymorphism, abstraction: -
INHERITANCE: -
1. Inheritance is the
process of deriving the new classes from existing classes.
2. Inheritance is the
process by which one class can inherit the properties of another class.
3. It is the process
of passing the properties of one class to another class.
4. The concept of
inheritance provides the idea of code reusability which means reduces rewriting
of the same code.
5. By the help of “:”
symbol we will inherit from a class.
E.g. class car: public vehicle (here vehicle is the super class and car is sub-class)
6. The new class consists of the old class properties and
its own properties.
7. The new class is called derived class and the old
class is called base class.
8. The class whose
features are inherited such type of class is known as super class, base class or parent class. And the class which
inherits the properties of another class they are known as sub class, child class derived class, extended class.
9. Advantages of
inheritance are
a. Reusability
b. Extensibility
10. There are some
types of inheritance they are as follows: -
a. Single level
inheritance
b. Multiple level
inheritance
c. Hierarchical level inheritance
d. Multi level
inheritance
e. Hybrid inheritance
ENCAPSULATION:
-
1.
Encapsulation is the process of grouping
and wrapping the data and related operations into a single unit in known as
encapsulation.
2.
In C++, encapsulated data is not accessible
by the outside world.
3.
Only the functions declared inside the
class are able to access the data members.
4.
Encapsulation allows organizing the data
and related operations in proper order.
5.
C++’s basic unit of encapsulation is the
class.
POLYMORPHISM:
-
1.
According
to Greek words, poly stands for many and morph means forms/ shapes/ kinds.
2.
Polymorphism is the ability of taking more
than one form. It occurs when there is hierarchy of classes and they are
related by inheritance.
3.
In C++, polymorphism means a call to a
member function which will cause a different function to be executed depending
on the type of object theta invokes the function.
4.
For understanding polymorphism we will see
a real time example, A man behaves like a
teacher in a classroom, father or son in a home and customer in a market. Here,
a single person is behaving differently according to the situations.
ABSTRACTION:
-
1.
Abstraction of data is one of the most
important and essential features of OOPs concept in C++.
2.
Abstraction refers to be the act of
representing essential features without including the background details and
explanations.
3.
Classes give the concept of abstraction and
define a list of abstract activities.
4.
The classes which use the concepts of data
abstraction, they are called abstract data types (ADT).
5.
Abstraction of data refers to providing
only essential information about the data to the outside world and it hide the
background details or implementations.
MESSAGE
PASSING/ COMMUNICATION: -
1.
An object communicates with another by
sending values, which is called message passing.
a.
Here message sender is object.
b.
Message receiver is object.
c.
Message is the function.
DYNAMIC BINDING: -
1.
In C++, it provides the facility of to
specify that compiler should match function calls with their correct definition
at run time, this is called Dynamic Binding.
2.
Late binding and run-time binding is also
known as Dynamic Binding.
3.
When all information needed for a function
call can’t be determined at compile time then Dynamic binding happens.
4.
Dynamic binding is associated with polymorphism
and inheritance.
5.
We can achieve dynamic binding by using the
virtual functions.
6.
The major advantage of dynamic binding is
that since a single function it is flexible and can handle different type of
objects at run-time. It reduces the size of the codebase and also makes the
source code more readable.
Overview of OOP using C++: -
Q . What is C++
language?
1. C++ language is an
advanced version of C-Language. The programs developed in C-language with or
without modifications moved to C++.
2. C++ is not a pure
object oriented programming language. It does not fulfill all the properties of
object oriented.
3. C++ language is
designed by or developed by Bjsrne
Stroupstrup at AT&T (American Telephone & Telegraph) Bell Labs in
the early 1980’s.
4. The original C++
language references are: The C++
programming language by Bjarne
Stroustrup -1986.
Q. Why C++ is
popular language?
1. It retains the
low-level strengths of C language.
2. It provides supports
for creating and using data abstractions.
3. It provides
supports for object oriented design and programming.
4. Retains and
improves organization capabilities.
5. It takes almost
nothing away from the C language, while adding enormous capability.
Other links: -(MORE UPDATES WILL BE COMING SOON)
Semester 4th previous year question
Semester 4th previous year question
Data Structure using C: -Click me
Object Oriented Programming C++: -Click me
Data base management system: - Click me
Notes of data structure using c: -Click me
Easy to understand and very helpful notes...📙📙
ReplyDeleteTHANK YOU DEAR FOR YOUR PRECIOUS COMMENT
DeleteVery nice sir
DeleteThank you
DeleteThat's nice
ReplyDeleteThank You
Delete