SlideShare a Scribd company logo
Object Oriented
Programming using C++
UNIT 1
BY:Ms SURBHI SAROHA
SYLLABUS
 Introduction to OOPs and C++ Elements
 Introduction to OOPs
 Features & Advantages of OOPs
 Different element of C++(Tokens, Keywords , Indentifiers , variable, constant
operators , Expression , String).
Introduction to OOPs and C++ Elements
 Object-oriented programming – As the name suggests uses objects in programming.
 Object-oriented programming aims to implement real-world entities like
inheritance, hiding, polymorphism, etc. in programming.
 The major purpose of C++ programming is to introduce the concept of object
orientation to the C programming language.
 Object Oriented Programming is a paradigm that provides many concepts such
as inheritance, data binding, polymorphism etc.
 The programming paradigm where everything is represented as an object is known
as truly object-oriented programming language.
 Smalltalk is considered as the first truly object-oriented programming language.
 Object-Oriented Programming is a methodology or paradigm to design a program
using classes and objects.
There are some basic concepts that act
as the building blocks of OOPs i.e.
 Class
 Objects
 Encapsulation
 Abstraction
 Polymorphism
 Inheritance
Characteristics of an Object-Oriented
Programming
Class
 The building block of C++ that leads to Object-Oriented programming is a
Class.
 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 instance of that
class.
 A class is like a blueprint for an object.
 For Example: Consider the Class of Cars. There may be many cars with
different names and brands but all of them will share some common
properties like all of them will have 4 wheels, Speed Limit, Mileage range,
etc. So here, the Car is the class, and wheels, speed limits, and mileage are
their properties.
Object
 An Object is an identifiable entity with some characteristics and behavior.
 An Object is an instance of a Class.
 When a class is defined, no memory is allocated but when it is instantiated
(i.e. an object is created) memory is allocated.
 Object means a real word entity such as pen, chair, table etc.
 Any entity that has state and behavior is known as an object.
Encapsulation
 Binding (or wrapping) code and data together into a single unit is known as
encapsulation.
 For example: capsule, it is wrapped with different medicines.
 Encapsulation is typically understood as the grouping of related pieces of
information and data into a single entity.
 Encapsulation is the process of tying together data and the functions that work
with it in object-oriented programming.
 Take a look at a practical illustration of encapsulation: at a company, there are
various divisions, including the sales division, the finance division, and the
accounts division.
 All financial transactions are handled by the finance sector, which also maintains
records of all financial data.
 In a similar vein, the sales section is in charge of all tasks relating to sales and
maintains a record of each sale.
Cont…..
 Now, a scenario could occur when, for some reason, a financial official
requires all the information on sales for a specific month.
 Under the umbrella term "sales section," all of the employees who can
influence the sales section's data are grouped together.
 Data abstraction or concealing is another side effect of encapsulation.
 In the same way that encapsulation hides the data.
 In the aforementioned example, any other area cannot access any of the data
from any of the sections, such as sales, finance, or accounts.
Abstraction
 Hiding internal details and showing functionality is known as abstraction.
 Data abstraction is the process of exposing to the outside world only the
information that is absolutely necessary while concealing implementation or
background information.
 For example: phone call, we don't know the internal processing.
 In C++, we use abstract class and interface to achieve abstraction.
Polymorphism
 When one task is performed by different ways i.e. known as polymorphism.
 For example: to convince the customer differently, to draw something e.g.
shape or rectangle etc.
 Different situations may cause an operation to behave differently.
 The type of data utilized in the operation determines the behavior.
Inheritance
 When one object acquires all the properties and behaviours of parent
object i.e. known as inheritance. It provides code reusability. It is used to
achieve runtime polymorphism.
 Sub class - Subclass or Derived Class refers to a class that receives properties
from another class.
 Super class - The term "Base Class" or "Super Class" refers to the class from
which a subclass inherits its properties.
 Reusability - As a result, when we wish to create a new class, but an existing
class already contains some of the code we need, we can generate our new
class from the old class thanks to inheritance. This allows us to utilize the
fields and methods of the pre-existing class.
There are mainly five types of
Inheritance in C++ . They are as follows:
 Single Inheritance
 Multiple Inheritance
 Multilevel Inheritance
 Hierarchical Inheritance
 Hybrid Inheritance
Single Inheritance
 Single inheritance is defined as the inheritance in which a derived class is
inherited from the only one base class.
Where 'A' is the base class, and 'B' is the derived class.
Let's see the example of single level
inheritance which inherits the fields only.
 #include <iostream>
 using namespace std;
 class Account {
 public:
 float salary = 60000;
 };
 class Programmer: public Account {
 public:
 float bonus = 5000;
 };
 int main(void) {
Cont….
 Programmer p1;
 cout<<"Salary: "<<p1.salary<<endl;
 cout<<"Bonus: "<<p1.bonus<<endl;
 return 0;
 }
Let's see another example of inheritance
in C++ which inherits methods only.
 #include <iostream>
 using namespace std;
 class Animal {
 public:
 void eat() {
 cout<<"Eating..."<<endl;
 }
 };
 class Dog: public Animal
 {
 public:
 void bark(){
Cont….
 cout<<"Barking...";
 }
 };
 int main(void) {
 Dog d1;
 d1.eat();
 d1.bark();
 return 0;
 }
C++ Multilevel Inheritance
 Multilevel inheritance is a process of deriving a class from another derived
class.
When one class inherits another class which is further
inherited by another class, it is known as multi level
inheritance in C++. Inheritance is transitive so the last
derived class acquires all the members of all its base
classes.
Let's see the example of multi level
inheritance in C++.
 #include <iostream.h>
 using namespace std;
 class Animal {
 public:
 void eat() {
 cout<<"Eating..."<<endl;
 }
 };
 class Dog: public Animal
 {

Cont….
 public:
 void bark(){
 cout<<"Barking..."<<endl;
 }
 };

 class BabyDog: public Dog
 {
 public:
 void weep() {

Cont….
 cout<<"Weeping...";
 }
 };
 int main(void) {
 BabyDog d1;
 d1.eat();
 d1.bark();
 d1.weep();
 return 0;
 }
C++ Multiple Inheritance
 Multiple inheritance is the process of deriving a new class that inherits the
attributes from two or more classes.
Let's see a simple example of multiple
inheritance.
 #include <iostream>
 using namespace std;
 class A
 {
 protected:
 int a;
 public:
 void get_a(int n)
 {
 a = n;
 }
 };

Cont….
 class B
 {
 protected:
 int b;
 public:
 void get_b(int n)
 {
 b = n;
 }
 };
Cont…..
 class C : public A,public B
 {
 public:
 void display()
 {
 std::cout << "The value of a is : " <<a<< std::endl;
 std::cout << "The value of b is : " <<b<< std::endl;
 cout<<"Addition of a and b is : "<<a+b;
 }
 };
 int main()
 {
Cont….
 C c;
 c.get_a(10);
 c.get_b(20);
 c.display();

 return 0;
 }
C++ Hybrid Inheritance
 Hybrid inheritance is a combination of more than one type of inheritance.
Let's see a simple example:
 #include <iostream>
 using namespace std;
 class A
 {
 protected:
 int a;
 public:
 void get_a()
 {
 std::cout << "Enter the value of 'a' : " << std::endl;
 cin>>a;
 }
 };
Cont….
 class B : public A
 {
 protected:
 int b;
 public:
 void get_b()
 {
 std::cout << "Enter the value of 'b' : " << std::endl;
 cin>>b;
 }
 };
Cont….
 class C
 {
 protected:
 int c;
 public:
 void get_c()
 {
 std::cout << "Enter the value of c is : " << std::endl;
 cin>>c;
 }
 };
Cont…..
 class D : public B, public C
 {
 protected:
 int d;
 public:
 void mul()
 {
 get_a();
 get_b();
 get_c();
 std::cout << "Multiplication of a,b,c is : " <<a*b*c<< std::endl;
 }
 };
Cont….
 int main()
 {
 D d;
 d.mul();
 return 0;
 }
Output
 Enter the value of 'a' :
 10
 Enter the value of 'b' :
 20
 Enter the value of c is :
 30
 Multiplication of a,b,c is : 6000
C++ Hierarchical Inheritance
 Hierarchical inheritance is defined as the process of deriving more than one
class from a base class.
Syntax of Hierarchical inheritance:
 class A
 {
 // body of the class A.
 }
 class B : public A
 {
 // body of class B.
 }
 class C : public A
Cont….
 {
 // body of class C.
 }
 class D : public A
 {
 // body of class D.
 }
What Are Child and Parent classes?
 To clearly understand the concept of Inheritance, you must learn about two
terms on which the whole concept of inheritance is based - Child class and
Parent class.
 Child class: The class that inherits the characteristics of another class is
known as the child class or derived class. The number of child classes that can
be inherited from a single parent class is based upon the type of inheritance.
A child class will access the data members of the parent class according to
the visibility mode specified during the declaration of the child class.
 Parent class: The class from which the child class inherits its properties is
called the parent class or base class. A single parent class can derive multiple
child classes (Hierarchical Inheritance) or multiple parent classes can inherit
a single base class (Multiple Inheritance). This depends on the different types
of inheritance in C++.
The syntax for defining the child class and
parent class in all types of Inheritance in C++
is given below:
 class parent_class
 {
 //class definition of the parent class
 };
 class child_class : visibility_mode parent_class
 {
 //class definition of the child class
 };
Syntax Description
 parent_class: Name of the base class or the parent class.
 child_class: Name of the derived class or the child class.
 visibility_mode: Type of the visibility mode (i.e., private, protected, and
public) that specifies how the data members of the child class inherit from
the parent class.
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.
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.
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 programming 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.
6. Solving problems
 Problems can be efficiently solved by breaking down the problem into smaller
pieces and this makes as one of the big advantages of object-oriented
programming.
 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.
Different element of C++
 Tokens
 A C++ program is composed of tokens which are the smallest individual
unit. Tokens can be one of several things, including keywords, identifiers,
constants, operators, or punctuation marks.
 There are 6 types of tokens in c++:
 Keyword
 Identifiers
 Constants
 Strings
 Special symbols
 Operators
Keywords
 In C++, keywords are reserved words that have a specific meaning in the
language and cannot be used as identifiers.
 Keywords are an essential part of the C++ language and are used to perform
specific tasks or operations.
 There are 95 keywords in c++.
 If you try to use a reserved keyword as an identifier, the compiler will
produce an error because it will not know what to do with the keyword.
Indentifiers
 The C++ identifier is a name used to identify a variable, function, class,
module, or any other user-defined item.
 An identifier starts with a letter A to Z or a to z or an underscore (_) followed
by zero or more letters, underscores, and digits (0 to 9).
 C++ does not allow punctuation characters such as @, $, and % within
identifiers.
 C++ is a case-sensitive programming language.
 Thus, Manpower and manpower are two different identifiers in C++.
Variable
 Variables in C++ is a name given to a memory location.
 It is the basic unit of storage in a program.
 The value stored in a variable can be changed during program execution.
 A variable is only a name given to a memory location, all the operations done
on the variable effects that memory location.
Constant operators
 Constants refer to fixed values that the program may not alter and they are
called literals.
 Constants can be of any of the basic data types and can be divided into
Integer Numerals, Floating-Point Numerals, Characters, Strings and Boolean
Values.
 Constants are treated just like regular variables except that their values
cannot be modified after their definition.
Expression
 An expression in C++ is an order collection of operators and operands which
specifies a computation.
 An expression can contain zero or more operators and one or more operands,
operands can be constants or variables.
 In addition, an expression can contain function calls as well which return
constant values.
 Examples of C++ expression:
 (a+b) - c
 (x/y) -z
 4a2 - 5b +c
 (a+b) * (x+y)
String
 Strings are used for storing text.
 A string variable contains a collection of characters surrounded by double
quotes.
 Example
 Create a variable of type string and assign it a value:
 string greeting = "Hello“;
 Example
 #include <iostream>
 #include <string>
 using namespace std;
Cont….
 int main() {
 string greeting = "Hello";
 cout << greeting;
 return 0;
 }
 THANK YOU 
Ad

Recommended

Operator overloading
Operator overloading
Pranali Chaudhari
 
Classes and objects
Classes and objects
Nilesh Dalvi
 
OOPS Basics With Example
OOPS Basics With Example
Thooyavan Venkatachalam
 
Function overloading ppt
Function overloading ppt
Prof. Dr. K. Adisesha
 
Introduction Of C++
Introduction Of C++
Sangharsh agarwal
 
OOP Unit 2 - Classes and Object
OOP Unit 2 - Classes and Object
dkpawar
 
C++ classes tutorials
C++ classes tutorials
Mayank Jain
 
Constructor and Destructor
Constructor and Destructor
Kamal Acharya
 
Data types in c++
Data types in c++
Venkata.Manish Reddy
 
Input and output in C++
Input and output in C++
Nilesh Dalvi
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
Sivakumar R D .
 
Inline function
Inline function
Tech_MX
 
Characteristics of OOPS
Characteristics of OOPS
abhishek kumar
 
Operator overloading
Operator overloading
Burhan Ahmed
 
Tokens in C++
Tokens in C++
Mahender Boda
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1
Prof. Dr. K. Adisesha
 
Data types in C language
Data types in C language
kashyap399
 
Static Data Members and Member Functions
Static Data Members and Member Functions
MOHIT AGARWAL
 
Data Types and Variables In C Programming
Data Types and Variables In C Programming
Kamal Acharya
 
This pointer
This pointer
Kamal Acharya
 
Abstract class in c++
Abstract class in c++
Sujan Mia
 
Function in C program
Function in C program
Nurul Zakiah Zamri Tan
 
C++ programming
C++ programming
Emertxe Information Technologies Pvt Ltd
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 
Pointers in C Language
Pointers in C Language
madan reddy
 
Python Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and Functions
DhivyaSubramaniyam
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))
Papu Kumar
 
Data members and member functions
Data members and member functions
Harsh Patel
 
OOPS IN C++
OOPS IN C++
Amritsinghmehra
 
Opp concept in c++
Opp concept in c++
SadiqullahGhani1
 

More Related Content

What's hot (20)

Data types in c++
Data types in c++
Venkata.Manish Reddy
 
Input and output in C++
Input and output in C++
Nilesh Dalvi
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
Sivakumar R D .
 
Inline function
Inline function
Tech_MX
 
Characteristics of OOPS
Characteristics of OOPS
abhishek kumar
 
Operator overloading
Operator overloading
Burhan Ahmed
 
Tokens in C++
Tokens in C++
Mahender Boda
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1
Prof. Dr. K. Adisesha
 
Data types in C language
Data types in C language
kashyap399
 
Static Data Members and Member Functions
Static Data Members and Member Functions
MOHIT AGARWAL
 
Data Types and Variables In C Programming
Data Types and Variables In C Programming
Kamal Acharya
 
This pointer
This pointer
Kamal Acharya
 
Abstract class in c++
Abstract class in c++
Sujan Mia
 
Function in C program
Function in C program
Nurul Zakiah Zamri Tan
 
C++ programming
C++ programming
Emertxe Information Technologies Pvt Ltd
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 
Pointers in C Language
Pointers in C Language
madan reddy
 
Python Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and Functions
DhivyaSubramaniyam
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))
Papu Kumar
 
Data members and member functions
Data members and member functions
Harsh Patel
 
Input and output in C++
Input and output in C++
Nilesh Dalvi
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
Sivakumar R D .
 
Inline function
Inline function
Tech_MX
 
Characteristics of OOPS
Characteristics of OOPS
abhishek kumar
 
Operator overloading
Operator overloading
Burhan Ahmed
 
Data types in C language
Data types in C language
kashyap399
 
Static Data Members and Member Functions
Static Data Members and Member Functions
MOHIT AGARWAL
 
Data Types and Variables In C Programming
Data Types and Variables In C Programming
Kamal Acharya
 
Abstract class in c++
Abstract class in c++
Sujan Mia
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 
Pointers in C Language
Pointers in C Language
madan reddy
 
Python Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and Functions
DhivyaSubramaniyam
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))
Papu Kumar
 
Data members and member functions
Data members and member functions
Harsh Patel
 

Similar to Object Oriented Programming using C++(UNIT 1) (20)

OOPS IN C++
OOPS IN C++
Amritsinghmehra
 
Opp concept in c++
Opp concept in c++
SadiqullahGhani1
 
Rajib Ali Presentation on object oreitation oop.pptx
Rajib Ali Presentation on object oreitation oop.pptx
domefe4146
 
Introduction to inheritance and different types of inheritance
Introduction to inheritance and different types of inheritance
huzaifaakram12
 
L9
L9
lksoo
 
inheritance in C++ programming Language.pptx
inheritance in C++ programming Language.pptx
rebin5725
 
Four Pillers Of OOPS
Four Pillers Of OOPS
Shwetark Deshpande
 
Inheritance
Inheritance
zindadili
 
Inheritance and its types explained.ppt
Inheritance and its types explained.ppt
SarthakKumar93
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
urvashipundir04
 
Chapter 8 Inheritance
Chapter 8 Inheritance
Amrit Kaur
 
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
DeepasCSE
 
What is c++ programming
What is c++ programming
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
6 Inheritance
6 Inheritance
Praveen M Jigajinni
 
00ps inheritace using c++
00ps inheritace using c++
sushamaGavarskar1
 
The smartpath information systems c plus plus
The smartpath information systems c plus plus
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
Inheritance
Inheritance
Pranali Chaudhari
 
Inheritance
Inheritance
Prof. Dr. K. Adisesha
 
C++ & Design Patterns Quicky
C++ & Design Patterns Quicky
Nikunj Parekh
 
C++ & Design Patterns - primera parte
C++ & Design Patterns - primera parte
Nikunj Parekh
 
Rajib Ali Presentation on object oreitation oop.pptx
Rajib Ali Presentation on object oreitation oop.pptx
domefe4146
 
Introduction to inheritance and different types of inheritance
Introduction to inheritance and different types of inheritance
huzaifaakram12
 
inheritance in C++ programming Language.pptx
inheritance in C++ programming Language.pptx
rebin5725
 
Inheritance and its types explained.ppt
Inheritance and its types explained.ppt
SarthakKumar93
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
urvashipundir04
 
Chapter 8 Inheritance
Chapter 8 Inheritance
Amrit Kaur
 
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
DeepasCSE
 
C++ & Design Patterns Quicky
C++ & Design Patterns Quicky
Nikunj Parekh
 
C++ & Design Patterns - primera parte
C++ & Design Patterns - primera parte
Nikunj Parekh
 
Ad

More from Dr. SURBHI SAROHA (20)

Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Dr. SURBHI SAROHA
 
MOBILE COMPUTING UNIT 2 by surbhi saroha
MOBILE COMPUTING UNIT 2 by surbhi saroha
Dr. SURBHI SAROHA
 
Mobile Computing UNIT 1 by surbhi saroha
Mobile Computing UNIT 1 by surbhi saroha
Dr. SURBHI SAROHA
 
DEEP LEARNING (UNIT 2 ) by surbhi saroha
DEEP LEARNING (UNIT 2 ) by surbhi saroha
Dr. SURBHI SAROHA
 
Introduction to Deep Leaning(UNIT 1).pptx
Introduction to Deep Leaning(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2
Dr. SURBHI SAROHA
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptx
Dr. SURBHI SAROHA
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)
Dr. SURBHI SAROHA
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptx
Dr. SURBHI SAROHA
 
JAVA (UNIT 5)
JAVA (UNIT 5)
Dr. SURBHI SAROHA
 
DBMS (UNIT 5)
DBMS (UNIT 5)
Dr. SURBHI SAROHA
 
DBMS UNIT 4
DBMS UNIT 4
Dr. SURBHI SAROHA
 
JAVA(UNIT 4)
JAVA(UNIT 4)
Dr. SURBHI SAROHA
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)
Dr. SURBHI SAROHA
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
Dr. SURBHI SAROHA
 
DBMS UNIT 3
DBMS UNIT 3
Dr. SURBHI SAROHA
 
JAVA (UNIT 3)
JAVA (UNIT 3)
Dr. SURBHI SAROHA
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)
Dr. SURBHI SAROHA
 
DBMS (UNIT 2)
DBMS (UNIT 2)
Dr. SURBHI SAROHA
 
Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Dr. SURBHI SAROHA
 
MOBILE COMPUTING UNIT 2 by surbhi saroha
MOBILE COMPUTING UNIT 2 by surbhi saroha
Dr. SURBHI SAROHA
 
Mobile Computing UNIT 1 by surbhi saroha
Mobile Computing UNIT 1 by surbhi saroha
Dr. SURBHI SAROHA
 
DEEP LEARNING (UNIT 2 ) by surbhi saroha
DEEP LEARNING (UNIT 2 ) by surbhi saroha
Dr. SURBHI SAROHA
 
Introduction to Deep Leaning(UNIT 1).pptx
Introduction to Deep Leaning(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2
Dr. SURBHI SAROHA
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptx
Dr. SURBHI SAROHA
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)
Dr. SURBHI SAROHA
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Ad

Recently uploaded (20)

Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
RAKESH SAJJAN
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
“THE BEST CLASS IN SCHOOL”. _
“THE BEST CLASS IN SCHOOL”. _
Colégio Santa Teresinha
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Introduction to problem solving Techniques
Introduction to problem solving Techniques
merlinjohnsy
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Measuring, learning and applying multiplication facts.
Measuring, learning and applying multiplication facts.
cgilmore6
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
RAKESH SAJJAN
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Introduction to problem solving Techniques
Introduction to problem solving Techniques
merlinjohnsy
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Measuring, learning and applying multiplication facts.
Measuring, learning and applying multiplication facts.
cgilmore6
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 

Object Oriented Programming using C++(UNIT 1)

  • 1. Object Oriented Programming using C++ UNIT 1 BY:Ms SURBHI SAROHA
  • 2. SYLLABUS  Introduction to OOPs and C++ Elements  Introduction to OOPs  Features & Advantages of OOPs  Different element of C++(Tokens, Keywords , Indentifiers , variable, constant operators , Expression , String).
  • 3. Introduction to OOPs and C++ Elements  Object-oriented programming – As the name suggests uses objects in programming.  Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism, etc. in programming.  The major purpose of C++ programming is to introduce the concept of object orientation to the C programming language.  Object Oriented Programming is a paradigm that provides many concepts such as inheritance, data binding, polymorphism etc.  The programming paradigm where everything is represented as an object is known as truly object-oriented programming language.  Smalltalk is considered as the first truly object-oriented programming language.  Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects.
  • 4. There are some basic concepts that act as the building blocks of OOPs i.e.  Class  Objects  Encapsulation  Abstraction  Polymorphism  Inheritance
  • 5. Characteristics of an Object-Oriented Programming
  • 6. Class  The building block of C++ that leads to Object-Oriented programming is a Class.  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 instance of that class.  A class is like a blueprint for an object.  For Example: Consider the Class of Cars. There may be many cars with different names and brands but all of them will share some common properties like all of them will have 4 wheels, Speed Limit, Mileage range, etc. So here, the Car is the class, and wheels, speed limits, and mileage are their properties.
  • 7. Object  An Object is an identifiable entity with some characteristics and behavior.  An Object is an instance of a Class.  When a class is defined, no memory is allocated but when it is instantiated (i.e. an object is created) memory is allocated.  Object means a real word entity such as pen, chair, table etc.  Any entity that has state and behavior is known as an object.
  • 8. Encapsulation  Binding (or wrapping) code and data together into a single unit is known as encapsulation.  For example: capsule, it is wrapped with different medicines.  Encapsulation is typically understood as the grouping of related pieces of information and data into a single entity.  Encapsulation is the process of tying together data and the functions that work with it in object-oriented programming.  Take a look at a practical illustration of encapsulation: at a company, there are various divisions, including the sales division, the finance division, and the accounts division.  All financial transactions are handled by the finance sector, which also maintains records of all financial data.  In a similar vein, the sales section is in charge of all tasks relating to sales and maintains a record of each sale.
  • 9. Cont…..  Now, a scenario could occur when, for some reason, a financial official requires all the information on sales for a specific month.  Under the umbrella term "sales section," all of the employees who can influence the sales section's data are grouped together.  Data abstraction or concealing is another side effect of encapsulation.  In the same way that encapsulation hides the data.  In the aforementioned example, any other area cannot access any of the data from any of the sections, such as sales, finance, or accounts.
  • 10. Abstraction  Hiding internal details and showing functionality is known as abstraction.  Data abstraction is the process of exposing to the outside world only the information that is absolutely necessary while concealing implementation or background information.  For example: phone call, we don't know the internal processing.  In C++, we use abstract class and interface to achieve abstraction.
  • 11. Polymorphism  When one task is performed by different ways i.e. known as polymorphism.  For example: to convince the customer differently, to draw something e.g. shape or rectangle etc.  Different situations may cause an operation to behave differently.  The type of data utilized in the operation determines the behavior.
  • 12. Inheritance  When one object acquires all the properties and behaviours of parent object i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.  Sub class - Subclass or Derived Class refers to a class that receives properties from another class.  Super class - The term "Base Class" or "Super Class" refers to the class from which a subclass inherits its properties.  Reusability - As a result, when we wish to create a new class, but an existing class already contains some of the code we need, we can generate our new class from the old class thanks to inheritance. This allows us to utilize the fields and methods of the pre-existing class.
  • 13. There are mainly five types of Inheritance in C++ . They are as follows:  Single Inheritance  Multiple Inheritance  Multilevel Inheritance  Hierarchical Inheritance  Hybrid Inheritance
  • 14. Single Inheritance  Single inheritance is defined as the inheritance in which a derived class is inherited from the only one base class. Where 'A' is the base class, and 'B' is the derived class.
  • 15. Let's see the example of single level inheritance which inherits the fields only.  #include <iostream>  using namespace std;  class Account {  public:  float salary = 60000;  };  class Programmer: public Account {  public:  float bonus = 5000;  };  int main(void) {
  • 16. Cont….  Programmer p1;  cout<<"Salary: "<<p1.salary<<endl;  cout<<"Bonus: "<<p1.bonus<<endl;  return 0;  }
  • 17. Let's see another example of inheritance in C++ which inherits methods only.  #include <iostream>  using namespace std;  class Animal {  public:  void eat() {  cout<<"Eating..."<<endl;  }  };  class Dog: public Animal  {  public:  void bark(){
  • 18. Cont….  cout<<"Barking...";  }  };  int main(void) {  Dog d1;  d1.eat();  d1.bark();  return 0;  }
  • 19. C++ Multilevel Inheritance  Multilevel inheritance is a process of deriving a class from another derived class. When one class inherits another class which is further inherited by another class, it is known as multi level inheritance in C++. Inheritance is transitive so the last derived class acquires all the members of all its base classes.
  • 20. Let's see the example of multi level inheritance in C++.  #include <iostream.h>  using namespace std;  class Animal {  public:  void eat() {  cout<<"Eating..."<<endl;  }  };  class Dog: public Animal  { 
  • 21. Cont….  public:  void bark(){  cout<<"Barking..."<<endl;  }  };   class BabyDog: public Dog  {  public:  void weep() { 
  • 22. Cont….  cout<<"Weeping...";  }  };  int main(void) {  BabyDog d1;  d1.eat();  d1.bark();  d1.weep();  return 0;  }
  • 23. C++ Multiple Inheritance  Multiple inheritance is the process of deriving a new class that inherits the attributes from two or more classes.
  • 24. Let's see a simple example of multiple inheritance.  #include <iostream>  using namespace std;  class A  {  protected:  int a;  public:  void get_a(int n)  {  a = n;  }  }; 
  • 25. Cont….  class B  {  protected:  int b;  public:  void get_b(int n)  {  b = n;  }  };
  • 26. Cont…..  class C : public A,public B  {  public:  void display()  {  std::cout << "The value of a is : " <<a<< std::endl;  std::cout << "The value of b is : " <<b<< std::endl;  cout<<"Addition of a and b is : "<<a+b;  }  };  int main()  {
  • 27. Cont….  C c;  c.get_a(10);  c.get_b(20);  c.display();   return 0;  }
  • 28. C++ Hybrid Inheritance  Hybrid inheritance is a combination of more than one type of inheritance.
  • 29. Let's see a simple example:  #include <iostream>  using namespace std;  class A  {  protected:  int a;  public:  void get_a()  {  std::cout << "Enter the value of 'a' : " << std::endl;  cin>>a;  }  };
  • 30. Cont….  class B : public A  {  protected:  int b;  public:  void get_b()  {  std::cout << "Enter the value of 'b' : " << std::endl;  cin>>b;  }  };
  • 31. Cont….  class C  {  protected:  int c;  public:  void get_c()  {  std::cout << "Enter the value of c is : " << std::endl;  cin>>c;  }  };
  • 32. Cont…..  class D : public B, public C  {  protected:  int d;  public:  void mul()  {  get_a();  get_b();  get_c();  std::cout << "Multiplication of a,b,c is : " <<a*b*c<< std::endl;  }  };
  • 33. Cont….  int main()  {  D d;  d.mul();  return 0;  }
  • 34. Output  Enter the value of 'a' :  10  Enter the value of 'b' :  20  Enter the value of c is :  30  Multiplication of a,b,c is : 6000
  • 35. C++ Hierarchical Inheritance  Hierarchical inheritance is defined as the process of deriving more than one class from a base class.
  • 36. Syntax of Hierarchical inheritance:  class A  {  // body of the class A.  }  class B : public A  {  // body of class B.  }  class C : public A
  • 37. Cont….  {  // body of class C.  }  class D : public A  {  // body of class D.  }
  • 38. What Are Child and Parent classes?  To clearly understand the concept of Inheritance, you must learn about two terms on which the whole concept of inheritance is based - Child class and Parent class.  Child class: The class that inherits the characteristics of another class is known as the child class or derived class. The number of child classes that can be inherited from a single parent class is based upon the type of inheritance. A child class will access the data members of the parent class according to the visibility mode specified during the declaration of the child class.  Parent class: The class from which the child class inherits its properties is called the parent class or base class. A single parent class can derive multiple child classes (Hierarchical Inheritance) or multiple parent classes can inherit a single base class (Multiple Inheritance). This depends on the different types of inheritance in C++.
  • 39. The syntax for defining the child class and parent class in all types of Inheritance in C++ is given below:  class parent_class  {  //class definition of the parent class  };  class child_class : visibility_mode parent_class  {  //class definition of the child class  };
  • 40. Syntax Description  parent_class: Name of the base class or the parent class.  child_class: Name of the derived class or the child class.  visibility_mode: Type of the visibility mode (i.e., private, protected, and public) that specifies how the data members of the child class inherit from the parent class.
  • 41. 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.
  • 42. 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.
  • 43. 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.
  • 44. 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 programming 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.
  • 45. 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.
  • 46. 6. Solving problems  Problems can be efficiently solved by breaking down the problem into smaller pieces and this makes as one of the big advantages of object-oriented programming.  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.
  • 47. Different element of C++  Tokens  A C++ program is composed of tokens which are the smallest individual unit. Tokens can be one of several things, including keywords, identifiers, constants, operators, or punctuation marks.  There are 6 types of tokens in c++:  Keyword  Identifiers  Constants  Strings  Special symbols  Operators
  • 48. Keywords  In C++, keywords are reserved words that have a specific meaning in the language and cannot be used as identifiers.  Keywords are an essential part of the C++ language and are used to perform specific tasks or operations.  There are 95 keywords in c++.  If you try to use a reserved keyword as an identifier, the compiler will produce an error because it will not know what to do with the keyword.
  • 49. Indentifiers  The C++ identifier is a name used to identify a variable, function, class, module, or any other user-defined item.  An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores, and digits (0 to 9).  C++ does not allow punctuation characters such as @, $, and % within identifiers.  C++ is a case-sensitive programming language.  Thus, Manpower and manpower are two different identifiers in C++.
  • 50. Variable  Variables in C++ is a name given to a memory location.  It is the basic unit of storage in a program.  The value stored in a variable can be changed during program execution.  A variable is only a name given to a memory location, all the operations done on the variable effects that memory location.
  • 51. Constant operators  Constants refer to fixed values that the program may not alter and they are called literals.  Constants can be of any of the basic data types and can be divided into Integer Numerals, Floating-Point Numerals, Characters, Strings and Boolean Values.  Constants are treated just like regular variables except that their values cannot be modified after their definition.
  • 52. Expression  An expression in C++ is an order collection of operators and operands which specifies a computation.  An expression can contain zero or more operators and one or more operands, operands can be constants or variables.  In addition, an expression can contain function calls as well which return constant values.  Examples of C++ expression:  (a+b) - c  (x/y) -z  4a2 - 5b +c  (a+b) * (x+y)
  • 53. String  Strings are used for storing text.  A string variable contains a collection of characters surrounded by double quotes.  Example  Create a variable of type string and assign it a value:  string greeting = "Hello“;  Example  #include <iostream>  #include <string>  using namespace std;
  • 54. Cont….  int main() {  string greeting = "Hello";  cout << greeting;  return 0;  }  THANK YOU 