SlideShare a Scribd company logo
1 of 45
Beginner’s Guide to OOP
No oops in OOP
Introduction
Muzammil Nawaz Asad Ali
Contents
 Pointers
 Structures
 Objects and Classes
 Conversion between basic and user-defined data types
 Functions and Types
 Encapsulation
 Inheritance
 Polymorphism
 Unary and Binary Operator’s Overloading
 File Handling in C++
Clarification
Pointers
 A pointer is a variable that stores the memory address as its value.
 A pointer variable points to a data type (like int or string) of the same
type, and is created with the * operator. The address of the variable you're
working with is assigned to the pointer:
For Example:
 string food = "Pizza"; // A food variable of type string
 string* ptr = &food; //A pointer variable, with the name ptr, that stores the
address of food
Why would one want to store Address?
Let’s See Code
 #include<iostream>
 #include<conio.h>
 using namespace std;
 void sum(int m, int n);
 int main(){
 int m = 10;
 int n = 2
 sum(m,n);
 cout<<m;

 }
 void sum(int m, int n){
 m= m+n;
 }
Output
5+6 = 11 ?
To overcome this issue
 We make a pointer that holds the address of a variable
 Any Changes in a reference variable are non-volatile
 There are no way of passing a variable "by reference" to a function. That's where
you have to use pointers
Code with Pointers
Structures
 We often come around situations where we need to store a group of data whether
of similar data types or non-similar data types. We have seen Arrays in C++ which
are used to store set of data of similar data types
 A structure is a user-defined data type in C/C++. A structure creates a data type
that can be used to group items of possibly different types into a single type.
Code Example
OOP
 Class and Objects
 Encapsulation
 Polymorphism
 Inheritance
(OOP)
Objects and Classes
A class in C++ is a user-defined type or data structure declared with keyword class
that has data and functions as its members whose access is governed by the three
access specifiers private, protected or public. By default access to members of a C++
class is private.
Class is a blueprint, Object is physically present in memory
Everything_around_you == Object
Example
 #include<iostream>
 #include<conio.h>
 using namespace std;
 class MyClass{
 public:
 int myNum;
 string myString;

 };
 int main(){

 MyClass object;
 object.myNum = 73;
 object.myString = "Muzzamil";
 cout<<object.myString<<", "<<object.myNum;
 }
Accessed Object values
Functions and Types
 A function is a block of code which only runs when it is called.
 You can pass data, known as parameters, into a function
 C++ provides some pre-defined functions, such as main(), which is
used to execute code. But you can also create your own functions to
perform certain actions.
 Syntax
 void myFunction() {
// code to be executed
}
 void means that the function does not have a return value.
Example
Types of Function
 Return types can be bool, char, string, int, float even an object
Int type
Bool type
Both are Pass-by Value methods
Pass by Value vs. Pass by Reference
 In call by reference the actual value that is passed as argument is changed after
performing some operation on it. When call by reference is used, it creates a copy
of the reference of that variable into the stack section in memory
 The call by reference is mainly used when we want to change the value of the
passed argument into the invoker function.
Example (pass by reference)
Encapsulation #include<iostream>
#include<conio.h>
using namespace std;
Why Encapsulation?
 Consider a real life example of encapsulation, in a company there are different
sections like the accounts section, finance section, sales section etc. The finance
section handles all the financial transactions and keep records of all the data
related to finance. Similarly the sales section handles all the sales related activities
and keep records of all the sales. Now there may arise a situation when for some
reason an official from finance section needs all the data about sales in a particular
month. In this case, he is not allowed to directly access the data of sales section. He
will first have to contact some other officer in the sales section and then request
him to give the particular data. This is what encapsulation is. Here the data of sales
section and the employees that can manipulate them are wrapped under a single
name “sales section”.
Inheritance
Example (Single) {All public methods}
Example(Multi Inheritance)
Multiple Inheritance in
C++ only
Polymorphism
 Many Shapes/Forms
Function/Method Overload
Function having same name different parameters
Judged at compile time.
Function Override
 Function having same name, same parameters different classes
 Judged at Runtime.
Now No oops in OOP
Reality is often disappointing
Unary and Binary Operator’s Overloading
Unary = Single Argument(operation), works with one class’ object only
Binary Operator’s
 A single argument(Operator) but two objects as operands
File Handling
 Files are important as they store our data
 #include<fstream>
 Creating a file: open()
 Reading data: read()
 Writing new Data: write()
 Closing a file (crucial): close()
Create a file
Read a file
Write on a File
Thank You ;)
17sw73@students.muet.edu.pk 17sw45@students.muet.edu.pk

More Related Content

What's hot

What's hot (20)

Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Computer
ComputerComputer
Computer
 
SPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in CSPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in C
 
C programming structure & pointer
C  programming structure & pointerC  programming structure & pointer
C programming structure & pointer
 
Pointers
PointersPointers
Pointers
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 
Array C programming
Array C programmingArray C programming
Array C programming
 
Array in C
Array in CArray in C
Array in C
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.net
 
C++ version 1
C++  version 1C++  version 1
C++ version 1
 
Double pointer (pointer to pointer)
Double pointer (pointer to pointer)Double pointer (pointer to pointer)
Double pointer (pointer to pointer)
 
Oop concepts
Oop conceptsOop concepts
Oop concepts
 
C++ Version 2
C++  Version 2C++  Version 2
C++ Version 2
 
02 Primitive data types and variables
02 Primitive data types and variables02 Primitive data types and variables
02 Primitive data types and variables
 
Lecture 6 polymorphism
Lecture 6 polymorphismLecture 6 polymorphism
Lecture 6 polymorphism
 
Objective C Primer (with ref to C#)
Objective C  Primer (with ref to C#)Objective C  Primer (with ref to C#)
Objective C Primer (with ref to C#)
 

Similar to Oop (20)

OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
Structures
StructuresStructures
Structures
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
 
Lecture 3.mte 407
Lecture 3.mte 407Lecture 3.mte 407
Lecture 3.mte 407
 
Object Oriented Dbms
Object Oriented DbmsObject Oriented Dbms
Object Oriented Dbms
 
C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01
 
C++ Interview Questions
C++ Interview QuestionsC++ Interview Questions
C++ Interview Questions
 
Actionscript
ActionscriptActionscript
Actionscript
 
U5 SPC.pptx
U5 SPC.pptxU5 SPC.pptx
U5 SPC.pptx
 
U5 SPC.pptx
U5 SPC.pptxU5 SPC.pptx
U5 SPC.pptx
 
Unit 1
Unit  1Unit  1
Unit 1
 
C,c++ interview q&a
C,c++ interview q&aC,c++ interview q&a
C,c++ interview q&a
 
SRAVANByCPP
SRAVANByCPPSRAVANByCPP
SRAVANByCPP
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
C questions
C questionsC questions
C questions
 

More from FatimaYousif11

The concept of vector art
The concept of vector artThe concept of vector art
The concept of vector artFatimaYousif11
 
Android local databases
Android local databasesAndroid local databases
Android local databasesFatimaYousif11
 
Day 5 android app code advancement
Day 5  android app code advancementDay 5  android app code advancement
Day 5 android app code advancementFatimaYousif11
 
Day 4 android bootcamp
Day 4  android bootcampDay 4  android bootcamp
Day 4 android bootcampFatimaYousif11
 
Android app code mediator
Android app code mediatorAndroid app code mediator
Android app code mediatorFatimaYousif11
 
Android App code starter
Android App code starterAndroid App code starter
Android App code starterFatimaYousif11
 
Getting started with android development
Getting started with android developmentGetting started with android development
Getting started with android developmentFatimaYousif11
 
Info session about dsc
Info session  about dscInfo session  about dsc
Info session about dscFatimaYousif11
 

More from FatimaYousif11 (15)

Day 2 react bootcamp
Day 2 react bootcampDay 2 react bootcamp
Day 2 react bootcamp
 
The concept of vector art
The concept of vector artThe concept of vector art
The concept of vector art
 
CV/resume writing
CV/resume writingCV/resume writing
CV/resume writing
 
Day 8 sketchware
Day 8  sketchwareDay 8  sketchware
Day 8 sketchware
 
Firebase
Firebase Firebase
Firebase
 
Android local databases
Android local databasesAndroid local databases
Android local databases
 
Day 5 android app code advancement
Day 5  android app code advancementDay 5  android app code advancement
Day 5 android app code advancement
 
Day 4 android bootcamp
Day 4  android bootcampDay 4  android bootcamp
Day 4 android bootcamp
 
Android app code mediator
Android app code mediatorAndroid app code mediator
Android app code mediator
 
Android App code starter
Android App code starterAndroid App code starter
Android App code starter
 
Android bootcamp-day1
Android bootcamp-day1Android bootcamp-day1
Android bootcamp-day1
 
Getting started with android development
Getting started with android developmentGetting started with android development
Getting started with android development
 
Hello to Kotlin
Hello to KotlinHello to Kotlin
Hello to Kotlin
 
Hacktoberfest slides
Hacktoberfest slidesHacktoberfest slides
Hacktoberfest slides
 
Info session about dsc
Info session  about dscInfo session  about dsc
Info session about dsc
 

Recently uploaded

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 

Recently uploaded (20)

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 

Oop

  • 1. Beginner’s Guide to OOP No oops in OOP
  • 3. Contents  Pointers  Structures  Objects and Classes  Conversion between basic and user-defined data types  Functions and Types  Encapsulation  Inheritance  Polymorphism  Unary and Binary Operator’s Overloading  File Handling in C++
  • 5. Pointers  A pointer is a variable that stores the memory address as its value.  A pointer variable points to a data type (like int or string) of the same type, and is created with the * operator. The address of the variable you're working with is assigned to the pointer: For Example:  string food = "Pizza"; // A food variable of type string  string* ptr = &food; //A pointer variable, with the name ptr, that stores the address of food
  • 6. Why would one want to store Address?
  • 7. Let’s See Code  #include<iostream>  #include<conio.h>  using namespace std;  void sum(int m, int n);  int main(){  int m = 10;  int n = 2  sum(m,n);  cout<<m;   }  void sum(int m, int n){  m= m+n;  }
  • 9. To overcome this issue  We make a pointer that holds the address of a variable  Any Changes in a reference variable are non-volatile  There are no way of passing a variable "by reference" to a function. That's where you have to use pointers
  • 11. Structures  We often come around situations where we need to store a group of data whether of similar data types or non-similar data types. We have seen Arrays in C++ which are used to store set of data of similar data types  A structure is a user-defined data type in C/C++. A structure creates a data type that can be used to group items of possibly different types into a single type.
  • 13. OOP  Class and Objects  Encapsulation  Polymorphism  Inheritance
  • 14. (OOP) Objects and Classes A class in C++ is a user-defined type or data structure declared with keyword class that has data and functions as its members whose access is governed by the three access specifiers private, protected or public. By default access to members of a C++ class is private. Class is a blueprint, Object is physically present in memory
  • 16. Example  #include<iostream>  #include<conio.h>  using namespace std;  class MyClass{  public:  int myNum;  string myString;   };  int main(){   MyClass object;  object.myNum = 73;  object.myString = "Muzzamil";  cout<<object.myString<<", "<<object.myNum;  }
  • 18. Functions and Types  A function is a block of code which only runs when it is called.  You can pass data, known as parameters, into a function  C++ provides some pre-defined functions, such as main(), which is used to execute code. But you can also create your own functions to perform certain actions.  Syntax  void myFunction() { // code to be executed }  void means that the function does not have a return value.
  • 20. Types of Function  Return types can be bool, char, string, int, float even an object Int type Bool type Both are Pass-by Value methods
  • 21. Pass by Value vs. Pass by Reference  In call by reference the actual value that is passed as argument is changed after performing some operation on it. When call by reference is used, it creates a copy of the reference of that variable into the stack section in memory  The call by reference is mainly used when we want to change the value of the passed argument into the invoker function.
  • 22. Example (pass by reference)
  • 24. Why Encapsulation?  Consider a real life example of encapsulation, in a company there are different sections like the accounts section, finance section, sales section etc. The finance section handles all the financial transactions and keep records of all the data related to finance. Similarly the sales section handles all the sales related activities and keep records of all the sales. Now there may arise a situation when for some reason an official from finance section needs all the data about sales in a particular month. In this case, he is not allowed to directly access the data of sales section. He will first have to contact some other officer in the sales section and then request him to give the particular data. This is what encapsulation is. Here the data of sales section and the employees that can manipulate them are wrapped under a single name “sales section”.
  • 26.
  • 27. Example (Single) {All public methods}
  • 31. Function/Method Overload Function having same name different parameters Judged at compile time.
  • 32. Function Override  Function having same name, same parameters different classes  Judged at Runtime.
  • 33.
  • 34. Now No oops in OOP
  • 35. Reality is often disappointing
  • 36. Unary and Binary Operator’s Overloading Unary = Single Argument(operation), works with one class’ object only
  • 37. Binary Operator’s  A single argument(Operator) but two objects as operands
  • 38.
  • 39. File Handling  Files are important as they store our data  #include<fstream>  Creating a file: open()  Reading data: read()  Writing new Data: write()  Closing a file (crucial): close()
  • 42. Write on a File
  • 43.
  • 44.
  • 45. Thank You ;) 17sw73@students.muet.edu.pk 17sw45@students.muet.edu.pk