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

unit-1.1

Uploaded by

aayus0278
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

unit-1.1

Uploaded by

aayus0278
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

The limitations of procedural programming are:

1. Procedural programming mainly focuses on procedures or


functions. Less attention is given to the data.
2. The data and functions are separate from each other.
3. Global data is freely moving and is shared among various
functions. Thus, it becomes difficult for programmers to identify
and fix issues in a program that originate due to incorrect data
handling.
4. Changes in data types need to be carried out manually all over
the program and in the functions using the same data type.
5. Limited and difficult code reusability.
6. It does not model real-world entities (e.g., car, table, bank
account, loan) very well where we as a human being, perceive
everything as an object.
7. The procedural programming approach does not work well for
large and complex systems.

Procedure Oriented Programming


1)In Procedural Oriented Programming, program is divided into small
parts called functions.
2)Procedural Oriented Programming follows Top Down approach.
3)Procedural Oriented Programming does not have any access
specifier.
4)In Procedural Oriented Programming, Overloading is not possible.
5)Example of Procedural Oriented Programming are : C, VB,
FORTRAN, Pascal.

Object Oriented Programming


1)In OOP, program is divided into parts called objects.
2)OOP follows Bottom Up approach.
3)OOP has access specifiers named Public, Private, Protected, etc.
4)In OOP, overloading is possible in the form of Function Overloading
and Operator Overloading.
5)Example of OOP are : C++, JAVA, VB.NET, C#.NET.

Advantages of OOPS
1. Troubleshooting is easier with the OOP language
Suppose the user has no idea where the bug lies if there is an error
within the code. Also, the user has no idea where to look into the code to
fix the error. This is quite difficult for standard programming languages.
However, when Object-Oriented Programming is applied, the user
knows exactly where to look into the code whenever there is an error.
There is no need to check other code sections as the error will show
where the trouble lies.

It is mainly through encapsulation that makes the objects self-contained.


This further helps in troubleshooting and easier collaborative
development.
2. Code Reusability
One of two important concepts that are provided by Object-Oriented
Programming is the concept of inheritance. Through inheritance, the
same attributes of a class are not required to be written repeatedly. This
avoids the issues where the same code has still to be written multiple
times in a code. With the introduction of the concept of classes, the code
section can be used as many times as required in the program. Through
the inheritance approach, a child class is created that inherits the fields
and methods of the parent class. The methods and values that are present
in the parent class can be easily overridden. Through inheritance, the
features of one class can be inherited by another class by extending the
class. Therefore, inheritance is vital for providing code reusability and
also multilevel inheritance.
Thus, Object-Oriented Programming offers the feature of class
reusability where the class that is once created can be used again. In
doing so, time is saved, and the need for extra coding is eliminated as
similar features can be inherited.
3. Productivity
The productivity of two codes increases through the use of Object-
Oriented Programming. This is because the OOP has provided so many
libraries that new programs have become more accessible. Also, as it
provides the facility of code reusability, the length of a code is
decreased, further enhancing the faster development of newer codes and
programs.
4. Data Redundancy
By the term data redundancy, it means that the data is repeated twice.
This means that the same data is present more than one time. In Object-
Oriented Deprogramming the data redundancy is considered to be an
advantage. For example, the user wants to have a functionality that is
similar to almost all the classes. In such cases, the user can create classes
with similar functionaries and inherit them wherever required.
5. Code Flexibility
The flexibility is offered through the concept of Polymorphism. A
scenario can be considered for a better understanding of the concept. A
person can behave differently whenever the surroundings change. For
example, if the person is in a market, the person will behave like a
customer, or the behavior might get changed to a student when the
person is in a school or any institution.
In this example, it can be observed that different behaviors are shown by
the same person whenever the surroundings around the person get
changed. This could explain the concept of Polymorphism and its
flexibility. The developers benefit through Polymorphism in the
following ways: simplicity and extensibility.

6. Solving problems
Problems can be efficiently solved by breaking down the problem into
smaller pieces. If a complex problem is broken down into smaller pieces
or components, it becomes a good programming practice. Considering
this fact, OOPS utilizes this feature where it breaks down the code of the
software into smaller pieces of the object into bite-size pieces that are
created one at a time. Once the problem is broken down, these broken
pieces can be used again to solve other problems. Also, the more minor
codes can get replaced through the modules with the same interface
having the implementation details.
7. Security
Because of the concept of data abstraction in OOPS, only a limited
amount of data is shown to the user. The rest data is not exposed while
exposing only the required amount of data. Therefore, it allows the
maintenance of security. The concept of abstraction is used to hide the
complexity from other users and demonstrate the element’s information
as per the requirements. It also helps in avoiding repetitive code.
Another concept provided in OOPS is the feature of encapsulation that
allows the protection of the data in the classes from getting accessed by
the system. All the internal contents in the class can be safeguarded. In
Java, encapsulation is mainly used for restricting access to the class
fields directly while setting all the fields of the class to private.
The code in the OOPS is an easy maintenance coding due to the
presence of a coding base in a central way. Therefore it is easy to create
procedure code that can be easily maintained.
A lot of benefits are further associated with the use of Object-Oriented
Programming.

Therefore the benefits of Object-Oriented Programming are:


• Users can build programs from the standard modules that communicate
with each other. This prevents writing the code again from scratch,
which ultimately saves the development time of the code and therefore is
higher productivity of the program.
• Problems can be solved easily through OOPS because a program can be
broken down into bit-sized codes or problems that can be easily solved.
• With the development of technology, the maintenance cost of the
programs is reduced, and there is increased productivity.
• The upgrade of the OOP system of languages can be easily done from
smaller systems to larger systems.
• Without interference, there might be multiple instances of the same
object.

Basic Concepts of Object


Oriented Programming
using C++
Object oriented programming is a type of programming which uses objects and classes its
functioning. The object oriented programming is based on real world entities like inheritance,
polymorphism, data hiding, etc. It aims at binding together data and function work on these data
sets into a single entity to restrict their usage.
Some basic concepts of object oriented programming are −
•CLASS
•OBJECTS
•ENCAPSULATION
•POLYMORPHISM
•INHERITANCE
•ABSTRACTION
Class − A class is a data-type that has its own members i.e. data members and member
functions. It is the blueprint for an object in object oriented programming language. It is the
basic building block of object oriented programming in c++. The members of a class are
accessed in programming language by creating an instance of the class.
Some important properties of class are −
•Class is a user-defined data-type.
•A class contains members like data members and member functions.
•Data members are variables of the class.
•Member functions are the methods that are used to manipulate data members.
•Data members define the properties of the class whereas the member functions define the
behaviour of the class.
A class can have multiple objects which have properties and behaviour that in common for all of
them.

Syntax
class class_name {
data_type data_name;
return_type method_name(parameters);
}
Object − An object is an instance of a class. It is an entity with characteristics and behaviour
that are used in the object oriented programming. An object is the entity that is created to
allocate memory. A class when defined does not have memory chunk itself which will be
allocated as soon as objects are created.

Syntax
class_name object_name;

Example
#include<iostream>
using namespace std;
class calculator {
int number1;
int number2;
char symbol;
public :
void add() {
cout<<"The sum is "<<number1 + number2 ;
}
void subtract() {
cout<<"The subtraction is "<<number1 - number2 ;
}
void multiply() {
cout<<"The multiplication is "<<number1 * number2 ;
}
void divide() {
cout<<"The division is "<<number1 / number2 ;
}
calculator (int a , int b , char sym) {
number1 = a;
number2 = b;
symbol = sym;
switch(symbol){
case '+' : add();
break;
case '-' : add();
break;
case '*' : add();
break;
case '/' : add();
break;
default : cout<<"Wrong operator";
}
}
};
int main() {
calculator c1(12 , 34 , '+');
}

Output
The sum is 46
Encapsulation In object oriented programming, encapsulation is the concept of wrapping
together of data and information in a single unit. A formale defination of encapsulation would
be: encapsulation is binding togather the data and related function that can manipulate the
data.
Let’s understand the topic with an easy real life example,
In our colleges, we have departments for each course like computer science, information tech. ,
electronics, etc. each of these departments have their own students and subjects that are kept
track of and being taught. let's think of each department as a class that encapsulates the data
about students of that department and the subjects that are to be taught. Also a department has
some fixed rules and guidelines that are to be followed by the students that course like timings,
methods used while learning, etc. this is encapsulation in real life, there are data and there are
ways to manipulate data.
Due to the concept of encapsulation in object oriented programming another very important
concept is possible, it is data abstraction or Data Hiding. it is possible as encapsulating hides
the data at show only the information that is required to be displayed.
Polymorphism The name defines polymorphism is multiple forms. which means polymorphism
is the ability of object oriented programming to do some work using multiple forms. The
behaviour of the method is dependent on the type or the situation in which the method is called.
Let’s take a real life example, A person can have more than one behaviour depending upon the
situation. like a woman a mother, manager and a daughterAnd this define her behaviour. This is
from where the concept of polymorphism came from.
In c++ programming language, polymorphism is achieved using two ways. They are operator
overloading and function overloading.
Operator overloading In operator overloading and operator can have multiple behaviour in
different instances of usage.
Function overloading Functions with the same name that can do multiple types based on
some condition.
Inheritance it is the capability of a class to inherit or derive properties or characteristics other
class. it is very important and object oriented program as it allows reusability i.e. using a
method defined in another class by using inheritance. The class that derives properties from
other class is known as child class or subclass and the class from which the properties are
inherited is base class or parent class.
C plus plus programming language supports the following types of inheritance
• single inheritance
• multiple inheritance
• multi level inheritance
• Hierarchical inheritance
• hybrid inheritance
Abstraction Data abstraction or Data Hiding is the concept of hiding data and showing only
relevant data to the final user. It is also an important part object oriented programing.
let's take real life example to understand concept better, when we ride a bike we only know that
pressing the brake will stop the bike and rotating the throttle will accelerate but you don't know
how it works and it is also not think we should know that's why this is done from the same as a
concept data abstraction.

What is C++
C++ is a general purpose, case-sensitive, free-form programming language that supports
object-oriented, procedural and generic programming.

C++ is a middle-level language, as it encapsulates both high and low level language features.

C++ history
History of C++ language is interesting to know. Here we are going to discuss brief history of
C++ language.

C++ programming language was developed in 1980 by Bjarne Stroustrup at bell laboratories
of AT&T (American Telephone & Telegraph), located in U.S.A.

Bjarne Stroustrup is known as the founder of C++ language.


It was develop for adding a feature of OOP (Object Oriented Programming) in C without
significantly changing the C component.

C++ programming is "relative" (called a superset) of C, it means any valid C program is also a
valid C++ program.

Let's summarize the above differences in a tabular form.

No. C C++

1) C follows the procedural style C++ is multi-paradigm. It supports


programming. both procedural and object
oriented.

2) Data is less secured in C. In C++, you can use modifiers for


class members to make it inaccessible
for outside users.

3) C follows the top-down C++ follows the bottom-up


approach. approach.

4) C does not support function C++ supports function overloading.


overloading.

5) In C, you can't use functions in In C++, you can use functions in


structure. structure.

6) C does not support reference C++ supports reference variables.


variables.

7) In C, scanf() and printf() are C++ mainly uses stream cin and
mainly used for input/output. cout to perform input and output
operations.

8) Operator overloading is not Operator overloading is possible in


possible in C. C++.

9) C programs are divided C++ programs are divided


into procedures and modules into functions and classes.

10) C does not provide the feature of C++ supports the feature of
namespace. namespace.

11) Exception handling is not easy in C++ provides exception handling


C. It has to perform using other using Try and Catch block.
functions.

12) C does not support the C++ supports inheritance.


inheritance.

You might also like