SlideShare a Scribd company logo
HackerzZ
Presentations
&
Productions
What we Learn in this Presentation
• Templates
• Function Templates
• Class Templates
Reference :- Object-Oriented Programming using C++ by IT Series
Book Page No :- 490 - 495
CHAPTER NO.17 TEMPLATES
What is template ?
It is a keyword which allows functions or classes to operate
without actually knowing what datatype will be handled by their
operations.
This is what is known as Generic
Programming
>> Advantages of Templates <<
 Allows to generate classes or functions
to handle different data types.
 Reduce the repetition of code.
 Make the program development easier
and more manageable.
Types of Templates
 Function Templates
 Class Templates
FunctionTemplates
FunctionTemplates are used to
define functions which are not related
to specific data types and can work
with different data types.
Syntax of Template Function
template <class T>
return_type function_name (T parameter(s))
{
Function Body
}
Class : Used to define the name of general data type.
T : Any letter/word can be used as a name of general data type.
Return_Type : Used to return value.
Parameter(s) : Parameters passed to a function. The type of parameters is a
general data type T that is defined in a template.
Program 1
Write a template to display the Maximum Number
#include<iostream>
#include<conio.h>
using namespace std;
template <class M>
void Max(M a, M b)
{ if(a>b) cout<<a;
else cout<<b; }
int main()
{ Max(8,20);
cout<<“n”;
Max(4.5,1.7);
getch(); }
Program 2
Write a template to display the Minimum Number between INT and FLOAT
#include<iostream>
#include<conio.h>
using namespace std;
template <class X, class Y>
void Min(X a, Y b)
{ if(a<b) cout<<a;
else cout<<b; }
int main()
{ Min(50,20.77);
cout<<“n”;
Min(4.5,10);
getch(); }
ClassTemplates
ClassTemplates are used to
define classes which are not related to
specific data types and can work with
different data types.
It consists of statements which are
independent of particular data types.
Syntax of Template Class
template <class T>
class class_name
{
Class Body
};
Class :- Used to define the name of general data type.
T :- Any letter/word can be used as a name of general data type.
Class_Name :- It is the name of a class.
Program 3
A program to input five integers in an array and display them using pointer.
#include<iostream>
#include<conio.h>
using namespace std;
template <class A>
class Add
{
private: A x,y;
public:
void get()
{ cout<<"Enter 1st value => "; cin>>x;
cout<<"Enter 2st value => "; cin>>y; }
void add()
{ x=x+y; }
void show()
{ cout<<"Values after addition = "<<x; }
};
Program 3 (contd..)
A program to input five integers in an array and display them using pointer.
int main()
{
Add <int> ob;
ob.get();
ob.add();
ob.show();
getch();
}
<int> = <class A>
Thank You
ANY QUESTIONS ??
DANGER
Created By Muhammad Ammad Hassan
Muhammad Azhar Khalil
Presented By Muhammad Azhar Khalil
Muhammad Ammad Hassan
Participants Toheed Azmat
Nouman Cheema
Hasseb Razzaq
Muhammad Usman Ahmad
Muhammad Ismail

More Related Content

What's hot

Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
Kamal Acharya
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
Tech_MX
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
Doncho Minkov
 

What's hot (20)

Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
Function template
Function templateFunction template
Function template
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
 
Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Constructor and destructor
Constructor  and  destructor Constructor  and  destructor
Constructor and destructor
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#
 
Inheritance C#
Inheritance C#Inheritance C#
Inheritance C#
 
Class or Object
Class or ObjectClass or Object
Class or Object
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory management
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 

Similar to Template C++ OOP

An Introduction To C++Templates
An Introduction To C++TemplatesAn Introduction To C++Templates
An Introduction To C++Templates
Ganesh Samarthyam
 
TEMPLATES in C++ are one of important topics in Object Oriented Programming
TEMPLATES in C++ are one of important topics in Object Oriented ProgrammingTEMPLATES in C++ are one of important topics in Object Oriented Programming
TEMPLATES in C++ are one of important topics in Object Oriented Programming
208BVijaySunder
 
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
ssuser5610081
 

Similar to Template C++ OOP (20)

Templates
TemplatesTemplates
Templates
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
 
Templates presentation
Templates presentationTemplates presentation
Templates presentation
 
Templates2
Templates2Templates2
Templates2
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
X++ 1.pptx
X++ 1.pptxX++ 1.pptx
X++ 1.pptx
 
59_OOP_Function Template and multiple parameters.pptx
59_OOP_Function Template and multiple parameters.pptx59_OOP_Function Template and multiple parameters.pptx
59_OOP_Function Template and multiple parameters.pptx
 
An Introduction To C++Templates
An Introduction To C++TemplatesAn Introduction To C++Templates
An Introduction To C++Templates
 
Unit 1
Unit  1Unit  1
Unit 1
 
OOPJ.pptx
OOPJ.pptxOOPJ.pptx
OOPJ.pptx
 
Advanced Programming C++
Advanced Programming C++Advanced Programming C++
Advanced Programming C++
 
TEMPLATES IN JAVA
TEMPLATES IN JAVATEMPLATES IN JAVA
TEMPLATES IN JAVA
 
TEMPLATES in C++ are one of important topics in Object Oriented Programming
TEMPLATES in C++ are one of important topics in Object Oriented ProgrammingTEMPLATES in C++ are one of important topics in Object Oriented Programming
TEMPLATES in C++ are one of important topics in Object Oriented Programming
 
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
 
Savitch Ch 17
Savitch Ch 17Savitch Ch 17
Savitch Ch 17
 
Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to Advanced
 
Typescript language extension of java script
Typescript language extension of java scriptTypescript language extension of java script
Typescript language extension of java script
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Csharp generics
Csharp genericsCsharp generics
Csharp generics
 
UNIT1-JAVA.pptx
UNIT1-JAVA.pptxUNIT1-JAVA.pptx
UNIT1-JAVA.pptx
 

Recently uploaded

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 

Recently uploaded (20)

Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdf
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 

Template C++ OOP

  • 1.
  • 3. What we Learn in this Presentation • Templates • Function Templates • Class Templates Reference :- Object-Oriented Programming using C++ by IT Series Book Page No :- 490 - 495
  • 4. CHAPTER NO.17 TEMPLATES What is template ? It is a keyword which allows functions or classes to operate without actually knowing what datatype will be handled by their operations. This is what is known as Generic Programming
  • 5. >> Advantages of Templates <<  Allows to generate classes or functions to handle different data types.  Reduce the repetition of code.  Make the program development easier and more manageable.
  • 6. Types of Templates  Function Templates  Class Templates
  • 7. FunctionTemplates FunctionTemplates are used to define functions which are not related to specific data types and can work with different data types.
  • 8. Syntax of Template Function template <class T> return_type function_name (T parameter(s)) { Function Body } Class : Used to define the name of general data type. T : Any letter/word can be used as a name of general data type. Return_Type : Used to return value. Parameter(s) : Parameters passed to a function. The type of parameters is a general data type T that is defined in a template.
  • 9. Program 1 Write a template to display the Maximum Number #include<iostream> #include<conio.h> using namespace std; template <class M> void Max(M a, M b) { if(a>b) cout<<a; else cout<<b; } int main() { Max(8,20); cout<<“n”; Max(4.5,1.7); getch(); }
  • 10. Program 2 Write a template to display the Minimum Number between INT and FLOAT #include<iostream> #include<conio.h> using namespace std; template <class X, class Y> void Min(X a, Y b) { if(a<b) cout<<a; else cout<<b; } int main() { Min(50,20.77); cout<<“n”; Min(4.5,10); getch(); }
  • 11. ClassTemplates ClassTemplates are used to define classes which are not related to specific data types and can work with different data types. It consists of statements which are independent of particular data types.
  • 12. Syntax of Template Class template <class T> class class_name { Class Body }; Class :- Used to define the name of general data type. T :- Any letter/word can be used as a name of general data type. Class_Name :- It is the name of a class.
  • 13. Program 3 A program to input five integers in an array and display them using pointer. #include<iostream> #include<conio.h> using namespace std; template <class A> class Add { private: A x,y; public: void get() { cout<<"Enter 1st value => "; cin>>x; cout<<"Enter 2st value => "; cin>>y; } void add() { x=x+y; } void show() { cout<<"Values after addition = "<<x; } };
  • 14. Program 3 (contd..) A program to input five integers in an array and display them using pointer. int main() { Add <int> ob; ob.get(); ob.add(); ob.show(); getch(); } <int> = <class A>
  • 17.
  • 18. Created By Muhammad Ammad Hassan Muhammad Azhar Khalil Presented By Muhammad Azhar Khalil Muhammad Ammad Hassan Participants Toheed Azmat Nouman Cheema Hasseb Razzaq Muhammad Usman Ahmad Muhammad Ismail