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 

More Related Content

What's hot (20)

PPTX
Constructor and destructor
Shubham Vishwambhar
 
PPTX
Data types in c++
Venkata.Manish Reddy
 
PPTX
class and objects
Payel Guria
 
PPTX
Function overloading and overriding
Rajab Ali
 
PPTX
07. Virtual Functions
Haresh Jaiswal
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PPTX
classes and objects in C++
HalaiHansaika
 
PPTX
Polymorphism In c++
Vishesh Jha
 
PPTX
Array Of Pointers
Sharad Dubey
 
PPT
friend function(c++)
Ritika Sharma
 
PPTX
virtual function
VENNILAV6
 
PPT
Basic concept of OOP's
Prof. Dr. K. Adisesha
 
PPTX
Fundamentals of OOP (Object Oriented Programming)
MD Sulaiman
 
PDF
Operator overloading
Pranali Chaudhari
 
PPTX
Static Data Members and Member Functions
MOHIT AGARWAL
 
PPTX
Functions in c++
Rokonuzzaman Rony
 
PPTX
Pointer in C++
Mauryasuraj98
 
PPT
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
PPTX
Type conversion
PreethaPreetha5
 
PPT
FUNCTIONS IN c++ PPT
03062679929
 
Constructor and destructor
Shubham Vishwambhar
 
Data types in c++
Venkata.Manish Reddy
 
class and objects
Payel Guria
 
Function overloading and overriding
Rajab Ali
 
07. Virtual Functions
Haresh Jaiswal
 
Classes, objects in JAVA
Abhilash Nair
 
classes and objects in C++
HalaiHansaika
 
Polymorphism In c++
Vishesh Jha
 
Array Of Pointers
Sharad Dubey
 
friend function(c++)
Ritika Sharma
 
virtual function
VENNILAV6
 
Basic concept of OOP's
Prof. Dr. K. Adisesha
 
Fundamentals of OOP (Object Oriented Programming)
MD Sulaiman
 
Operator overloading
Pranali Chaudhari
 
Static Data Members and Member Functions
MOHIT AGARWAL
 
Functions in c++
Rokonuzzaman Rony
 
Pointer in C++
Mauryasuraj98
 
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
Type conversion
PreethaPreetha5
 
FUNCTIONS IN c++ PPT
03062679929
 

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

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

More from Dr. SURBHI SAROHA (20)

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

Recently uploaded (20)

PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 

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 