Technical Point.

The Best Platform of Diploma CSE Students.

Subscribe Us

Breaking

Tuesday, April 28, 2020

OOPC++ unit 1

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.

C++ is a general-purpose and multi-paradigm computer programming language. The C++ programming language supports both object-oriented programming and generic programming. C++ is an object-oriented programming language but it is not purely object-oriented programming language because of features like friend functions, virtual functions, and virtual base classes.
The C++ programming language is used to create applications that will run on a wide variety of hardware platforms such as personal computers running Windows, Linux, UNIX, and Mac OS. It also supports the applications for small form factor hardware such as IoT devices like the Raspberry PI and Arduino–based boards.
The C++ programming language was created by Bjarne Stroustrup in the year 1983, at Bell Laboratories, USA.

The C++ programming language is said to be the superset of C programming language. The programs written in C programming language can run in the C++ compiler. The C++ programming language is an extension of the C programming language.

OOP Concepts

The main aim of the C++ programming language was to add the concepts of object-oriented programming paradigm to the procedure-oriented programming paradigm like C programming language. The following are the object-oriented programming concepts.
  • Object
  • Class
  • Encapsulation
  • Abstraction
  • Inheritance
  • Polymorphism

Object

An object is any real-time entity with some properties and behaviors. The object is the basic unit of the object-oriented programming paradigm. The properties of an object are the data values, and the behaviors are the functionalities that are associated with it. In object-oriented programming, the objects are created through the concept of class.

Class

A class is a collection of data and code where data is defined as variables and code like methods. By creating the class, we can define a blueprint of an object. Every class in OOPs defines a user-defined data type. The data and code defined in a class are said to be the members of that class (data members and member functions respectively).

Encapsulation

Encapsulation is the process of combining data with code into a single unit (class/object). We use the concept of class and object to implement encapsulation. The encapsulation aims to avoid the access of private data members from outside the class. So it binds the data members with member functions.

Abstraction

Abstraction is the process of hiding unnecessary details and showing only useful details to the end-user. Using the abstraction concept, the actual business logic is hidden from the users and shown only required things to solve the problem.

Inheritance

Inheritance is the process of acquiring properties from one object to another object. In other words, inheritance is the process of deriving a new class from an existing class where the members of the existing class are extended to the newly derived class. Here, the existing class is called a base class or a superclass or a parent class, and the newly created class is called a derived class or a subclass or a child class. The inheritance concept enables a major feature called code reusability.

Polymorphism

Polymorphism is the process of defining a single function with different functionalities (or) definitions. It is implemented using the concepts of function overloading and overriding.
In C++, we also have a feature of operator overloading.




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
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<
                 cout<
                 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 exampleA 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 early1980’s.
4.   The original C++ language references are: The C++ programming language byBjarne 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.

No comments:

Post a Comment

Recently

All C program

Write a C program to print ‘Hello World’ on screen . #include < stdio.h > #include < conio.h > void  m...