SlideShare a Scribd company logo
1 of 18
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

What's hot (20)

Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Operator overloading in C++
Operator  overloading in C++Operator  overloading in C++
Operator overloading in C++
 
Function in C
Function in CFunction in C
Function in C
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
inheritance
inheritanceinheritance
inheritance
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Polymorphism In c++
Polymorphism In c++Polymorphism In c++
Polymorphism In c++
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
C functions
C functionsC functions
C functions
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract class
 
Function in c
Function in cFunction in c
Function in c
 
C function presentation
C function presentationC function presentation
C function presentation
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
C++ Pointers And References
C++ Pointers And ReferencesC++ Pointers And References
C++ Pointers And References
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 

Similar to Template C++ OOP

Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#SyedUmairAli9
 
Templates presentation
Templates presentationTemplates presentation
Templates presentationmalaybpramanik
 
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.pptxBhushanLilhare
 
An Introduction To C++Templates
An Introduction To C++TemplatesAn Introduction To C++Templates
An Introduction To C++TemplatesGanesh Samarthyam
 
Advanced Programming C++
Advanced Programming C++Advanced Programming C++
Advanced Programming C++guestf0562b
 
TEMPLATES IN JAVA
TEMPLATES IN JAVATEMPLATES IN JAVA
TEMPLATES IN JAVAMuskanSony
 
Function template
Function templateFunction template
Function templateKousalya M
 
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
 
Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to AdvancedTalentica Software
 
Typescript language extension of java script
Typescript language extension of java scriptTypescript language extension of java script
Typescript language extension of java scriptmichaelaaron25322
 

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
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
Advanced Programming C++
Advanced Programming C++Advanced Programming C++
Advanced Programming C++
 
TEMPLATES IN JAVA
TEMPLATES IN JAVATEMPLATES IN JAVA
TEMPLATES IN JAVA
 
Function template
Function templateFunction template
Function template
 
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
 

Recently uploaded

Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 

Recently uploaded (20)

Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 

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