0% found this document useful (0 votes)
15 views12 pages

Segment 1

The document provides an introduction to Object Oriented Programming (OOP) and its fundamental concepts, including classes, objects, encapsulation, abstraction, inheritance, and polymorphism. It discusses the differences between structured programming and OOP, as well as the distinctions between C and C++. Additionally, it outlines the benefits and applications of OOP, emphasizing its importance in modern programming languages like C++.

Uploaded by

tawsifahmed790
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)
15 views12 pages

Segment 1

The document provides an introduction to Object Oriented Programming (OOP) and its fundamental concepts, including classes, objects, encapsulation, abstraction, inheritance, and polymorphism. It discusses the differences between structured programming and OOP, as well as the distinctions between C and C++. Additionally, it outlines the benefits and applications of OOP, emphasizing its importance in modern programming languages like C++.

Uploaded by

tawsifahmed790
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/ 12

s Part 1: Introduction of OOP

Content:
 Introduction to OOP
 C++ Console I/O
 Introduction to Classes and Objects
 Basic concept of Object Oriented Programming
 Difference between Structured Programming and Object Oriented Programming
 Difference between C/C++
 Benefits of OOP
 Characteristics of Procedure Oriented Programming
 Characteristics of Object Oriented Programming
 Applications of Object Oriented Programming

About C++:
 It is universal language of programmers.
 It is the language that will create the high-performance software.
 professional programmer must know.
 C++ was invented in 1979 by Bjarne Stroustrup at Bell Laboratories in Murray
Hill, NewJersey. Initially it was called "C with classes." The name was changed to
C++ in 1983.

OOP:
Object Oriented programming (OOP) is a programming methodology that relies on the concept of
classes and objects. “Object-Oriented Programming" refers to a programming model based on
objects and classes, instead of just functions and procedures.It is used to structure a software program
into simple, reusable pieces of code, which are used to create individual instances of objects.So,
complexity is reduced and the programmer can manage larger programs.Most modern programming
languages including Java, C++,C Sharp and PHP, are object-oriented Programming languages.
Class:

A class is a blueprint or template from which objects are created.It is a building block of Object-
Oriented programming. It is a user-defined data type, which holds its own data members and
member functions, which can be accessed and used by creating an object of that class.
A Class is a user-defined data-type which has data members and member functions.
Example: Smartphone is a class, Object will be e.g., Redmi 5, 6, 7 etc.

Object:
Object is an instance of a class. All data members and member functions of the class can be
accessed with the help of objects. When a class is defined, no memory is allocated, but memory is
allocated when an object is created.
Class and Object Declaration Void charge()
// Class Declaration {
Class Smartphone { //Member Function
Public: String model; // data member }
Public: int price; // data member
Public: int memorySize; // data member }
//Object declaration
Void restart() int main(){
{ Smartphone redmi;
//Member Function redmi.model=”Note7 Pro”.
} redmi.price=21000;
redmi.charge();
redmi.restart();

C++ Console I/O:


General Format:
cin>>variable; //for input
cout<<expression;//for output
#include <iostream>
using namespace std;
int main()
{
char name[50];
cout << "Please enter your name: ";
cin >> name;
cout << "Your name is: " << name << endl;
}

Basic Concepts of OOP:


Object-oriented programming has four basic concepts:
 Encapsulation,
 Abstraction,
 Inheritance
 Polymorphism.

Encapsulation:
Encapsulation is one of the concepts in OOPs. Encapsulation means to enclose data within an
object.It is the process that binds together the data and code into a single unit and keeps safe from
outside interference and misuse. In this process, the data is hidden from other classes and can be
accessed only through the current class’s methods. Hence, it is also known as data hiding.
Encapsulation acts as a protective wrapper that prevents the code and data from being accessed by
outsiders.Encapsulation is used for access restriction to class members and methods. Access
modifier keywords are used for encapsulation in object oriented programming. For example,
encapsulation in OOP is achieved using private, protected and public keywords.

Example:
When creating a class to represent a person, you may define private data, such as the person's Social
Security Number. You can encapsulate this data as a private variable in the class, which means
outside code can't access it. If you write a method in the person class to perform a bank transaction,
the function could access the data variable as necessary. In this example, the person's private data is
well-encapsulated within the class.
Abstraction :

Data abstraction is one of the most essential and important features of object-oriented programming
in C++. Abstraction means displaying only essential information and hiding the details. Data
abstraction refers to providing only essential information about the data to the outside world, hiding
the background details or implementation.

Consider a real-life example of a man driving a car. The man only knows that pressing the
accelerators will increase the speed of the car or applying brakes will stop the car but he does not
know about how on pressing accelerator the speed is actually increasing, he does not know about
the inner mechanism of the car or the implementation of accelerator, brakes etc in the car. This is
what abstraction is.
For example, consider the pow() method present in math.h header file. Whenever we need to
calculate thepower of a number, we simply call the function pow() present in the math.h header file and
pass the numbers as arguments without knowing the underlying algorithm according to which the
function is actually calculating the power of numbers.
Polymorphism :
Polymorphism is an important concept of object-oriented programming. The word polymorphism
means having many forms. It simply means more than one form. That is, the same entity (function
or operator) behaves differently in different scenarios.
Let's consider a real-life example of polymorphism. A lady behaves like a teacher in a classroom,
mother or daughter in a home and customer in a market. Here, a single person is behaving differently
according to the situations.
Types of polymorphism :

Example:

Inheritance:
Inheritance is one of the most important features of Object-Oriented Programming. The process of
obtaining the data members and methods from one class to another class is known as
inheritance.The capability of a class to derive properties and characteristics from another class is
called Inheritance. Inheritance is a feature or a process in which, new classes are created from the
existing classes. The new class created is called “derived class” or “child class” and the existing
class is known as the “base class” or “parent class.

Why and when to use inheritance?


Consider a below situation:
You can clearly see that the above process results in duplication of the same code 3 times. This
increases the chances of error and data redundancy. To avoid this type of situation, inheritance is
used.

To avoid redundancy and increase the re-usability of a class, we used inheritance like in the above
example.

Types of Inheritance:

Based on number of ways inheriting the feature of base class into derived class it has several types
they are:

 Single inheritance

 Multiple inheritance

 Hierarchical inheritance

 Multilevel Inheritance

 Hybrid inheritance
Benefits of OOP:
Benefits of OOP include

Reusability: Code can be reused through inheritance, that means a team does not have to write the
same code multiple times.
Productivity: The productivity of 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.
Easily upgradable and scalable: Programmers can implement system functionalities
independently.
Security: Using encapsulation and abstraction, complex code is hidden,

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.

Improved software maintainability: Object oriented software is also easier to maintain. Since the
design is modular, part of the system can be updated in case of issues without a need to make large-
scale changes.

Applications of OOP:
Below are some applications of OOPs:
Real-Time System design: Real-time system inherits complexities and makes it difficult to build
them.OOP techniques make it easier to handle those complexities.
Hypertext and Hypermedia: Hypertext is similar to regular text as it can be stored, searched, and
edited easily. Hypermedia on the other hand is a superset of hypertext. OOP also helps in laying the
framework for hypertext and hypermedia.
AI Expert System: These are computer application that is developed to solve complex problems
which arefar beyond the human brain. OOP helps to develop such an AI expert System
Office automation System: These include formal as well as informal electronic systems that
primarily concerned with information sharing and communication to and from people inside and
outside the organization. OOP also help in making office automation principle.
Neural networking and parallel programming: It addresses the problem of prediction and
approximation of complex-time varying systems. OOP simplifies the entire process by simplifying
the approximation andprediction ability of the network.
Stimulation and modeling system: It is difficult to model complex systems due to varying
specifications of variables. Stimulating complex systems require modeling and understanding
interaction explicitly. OOPprovides an appropriate approach for simplifying these complex models.
Object-oriented database: The databases try to maintain a direct correspondence between the real
world and database object in order to let the object retain it identity and integrity.
Client-server system: Object-oriented client-server system provides the IT infrastructure creating
object- oriented server internet(OCSI) applications.
CIM/CAD/CAM systems: OOP can also be used in manufacturing and designing applications as it
allows people to reduce the efforts involved. For instance, it can be used while designing blueprints
and flowcharts.So it makes it possible to produce these flowcharts and blueprint accurately.

Difference between procedural/structured programming and object oriented


programming:

Difference between C and C++:

C C++

C was developed by Dennis Ritchie C++ was developed by Bjarne Stroustrup in


between the year 1969 and 1973 at AT&T 1979.
Bell Labs.
C does no support polymorphism, C++ supports polymorphism, encapsulation,
encapsulation, and inheritance which and inheritance because it is an object
means that C does not support object oriented programming language.
oriented programming.

C is a subset of C++. C++ is a superset of C.

C contains 32 keywords. C++ contains 63 keywords.

For the development of code, C C++ is known as hybrid language because


supports procedural programming. C++ supports both procedural and object
oriented programming paradigms.

Data and functions are separated in C Data and functions are encapsulated
because it is a procedural programming together in form of an object in C++.
language.

Data is hidden by the Encapsulation to


C does not support information hiding. ensure that data structures and operators
are used as intended.

Built-in & user-defined data types is


Built-in data types is supported in C. supported in C++.

C is a function driven language because C C++ is an object driven language becauseit


is a procedural programming language. is an object oriented programming.

Function and operator overloading is not Function and operator overloading is


supported in C. supported by C++.

C is a function-driven language. C++ is an object-driven language

Functions in C are not defined inside Functions can be used inside a structure
structures. in C++.

Namespace features are not present inside Namespace is used by C++, which avoid
the C. name collisions.
Header file used by C is stdio.h. Header file used by C++ is iostream.h.

Reference variables are not supported by Reference variables are supported by


C. C++.

Virtual and friend functions are not Virtual and friend functions are supported
supported by C. by C++.

C does not support inheritance. C++ supports inheritance.

Direct support for exception handling is


not supported by C. Exception handling is supported by C++.

scanf() and printf() functions are used for cin and cout are used for input/output in
input/output in C. C++.

C structures don’t have access modifiers. C ++ structures have access modifiers.

C follows the top-down approach C++ follows the Bottom-up approach

Procedural Oriented Programming (POP):


Procedure Oriented Programming follow step by step procedure to execute. Here,the problems get
decomposed into small parts and then to solve each part one or more functions are used. Thus in
POP approach, the problem is viewed as a sequence of things to be done, such as, input taking,
calculating and displaying.
For example, considering that we have to take two values from user and then to display the
summation of the inputted values. In POP approach this problem may be decomposed as following,
1. First take an input and put it under one variable, here taking as a.
2. Then take another input and put it under another variable, here taking as b.
3. Now define a variable, such as c, as c = a + b.
4. Now display c.
Characteristics of Procedural Oriented Programming (POP):
 Large problems are divided into smaller programs known as functions.
 Most of the functions share global data.
 Data move openly around the system from function to function.
 Functions transfer data from one form to another.
 Employs top-down approach in program designing.
 In the cases of large program, bringing change is difficult and time consuming.
 Appropriate and effective techniques are unavailable to secure data of a function from
others.

Characteristics of Object Oriented programming language:


The characteristics of OOP are:

Class definitions – Basic building blocks OOP and a single entity which has data and operations on
data together

Objects – The instances of a class which are used in real functionality – its variables and operations

Abstraction – Specifying what to do but not how to do ; a flexible feature for having a overall view
of an object’s functionality.

Encapsulation – Binding data and operations of data together in a single unit – A class adhere this
feature

Inheritance and class hierarchy – Reusability and extension of existing classes


Polymorphism – Multiple definitions for a single name - functions with same name with different
functionality; saves time in investing many function names Operator and Function overloading
Class libraries – Built-in language specific classes

Previous Question and Answer:


1.

1. Cout<<” x=”<<x;
2. int m=5; int n=10; int s=m+n;
3. Std:: cin>>x>>y; or cin>>x>>y;
4. Cout<<”/n Name:”<<name;
5. Cout<<”Enter value:”; cin>>x;
6. /*Addition*/ int z=x+y;
2.

#include <iostram>
Using namespace std;
int main(0){
int math=90;
Int physics=99;
Int chemistry=80;
Cout<<math<<” ”<<physics<<” ”<<chemistry<<endl;
}

Prepared By

Muhammad Nazim Uddin


Lecturer(Adjunct)
Department of Computer Science and Engineering(CSE)
Cell:01830082347
Email:[email protected]

You might also like