SlideShare a Scribd company logo
Object-Oriented
Programming (OOP)
Template
• Template is simple and yet very powerful tool in C++
• Template are the foundation of generic programming which
involves writing code in a away that is independent of any type.
• A template is a blueprint or formula for creating a generic class
or a function.
• Function Template
• Class Template
Function Template
• Replace Function overloading
• Syntax
Template <class A>
• A is place holder (automatically set according to datatype)
• A big(A a , A b)
• Function template is also known as generic function.
• Template < class type> type func_name ( type arg1,….);
Class Template
• Syntax :
• Template < class type> class class_name {……};
Exception
• An exception is an event, which occurs during the execution of a
program, that disrupts the normal flow of the program's Instructions.
Exception Handling in C++
• The process of converting system error messages into user friendly
error message is known as Exception handling.
• This is one of the powerful feature of C++ to handle run time error
and maintain normal flow of C++ application.
Handling the Exception
• Handling the exception is nothing but converting system error
message into user friendly error message. Use Three keywords for
Handling the Exception in C++ Language, they are;
• try
• catch
• throw
Exception Handling ,templates in C++
Exception Handling ,templates in C++
Try Block
• It is one of the block in which we write the block of statements which
causes executions at run time in other words try block always
contains problematic statements.
Catch block
• It is one of the block in which we write the block of statements which
will generates user friendly error messages in other words catch block
will suppose system error messages
Exception Handling ,templates in C++
Exception Handling ,templates in C++
Exception Handling ,templates in C++
Exception Handling ,templates in C++
Exception Handling ,templates in C++
Exception Handling ,templates in C++
Exception Handling ,templates in C++
File Handling
• File Handling concept in C++ language is used for store a data
permanently in computer.
• Using file handling we can store our data in Secondary memory (Hard
disk).
Exception Handling ,templates in C++
Exception Handling ,templates in C++
Exception Handling ,templates in C++
Why use File Handling in C++
• For permanent storage.
• The transfer of input - data or output - data from one computer to
another can be easily done by using files.
• For read and write from a file you need another standard C++ library
called fstream, which defines three new data types.
Exception Handling ,templates in C++
Exception Handling ,templates in C++
Exception Handling ,templates in C++
Exception Handling ,templates in C++
Exception Handling ,templates in C++
Exception Handling ,templates in C++
Exception Handling ,templates in C++
Exception Handling ,templates in C++
Exception Handling ,templates in C++
My Name Is Ali
My Name Is
Ali
File
Cout<<“ My Name Is Ali”;
Cout<<“ My Name Is /n Ali:
Fout<<“My Name Is /n Ali”;
My Name Is
Ali
Sceen
How to achieve File Handling
For achieving file handling in C++ we need follow following steps
• Naming a file
• Opening a file
• Reading data from file
• Writing data into file
• Closing a file
Defining and Opening a File
• The function open() can be used to open multiple files that use the
same stream object.
Closing a File
• A file must be close after completion of all operation related to file.
For closing file we need close() function.
Program for file handling
#include< iostream . h>
#include< conio .h>
#include< fstream . h>
Class student
{
Public:
Struct stu
{
char name[20];
int roll;
}s;
Void put_data();
Void get_data();
};
void student :: put_data()
{
cout<<"enter name ";
cin>>s. name;
cout<<"enter roll ";
cin>>s. roll;
file. Open ("hit. txt“ , ios :: out | ios :: app);
file. write ((char *)this, sizeof (student));
file. close();
getch();
get_data();
}
void student :: get_data()
{
int temp;
cout<<"enter roll no. ";
cin >>temp;
fstream file;
file. open ("hit . txt", ios :: in);
file.seekg(0,ios::beg);
While (file . read ((char *) this, sizeof (student)))
{
If (temp==s. roll)
{
cout<<"student name "<< s . name<<"n";
cout<<"student roll "<< s . roll;
}
}
getch ();
}
void main()
{
clrscr();
student st;
st .put_data();
}
Ad

More Related Content

Similar to Exception Handling ,templates in C++ (20)

C- language Lecture 8
C- language Lecture 8C- language Lecture 8
C- language Lecture 8
Hatem Abd El-Salam
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)
Dr. SURBHI SAROHA
 
Data file handling
Data file handlingData file handling
Data file handling
TAlha MAlik
 
Csharp introduction
Csharp introductionCsharp introduction
Csharp introduction
Sireesh K
 
C++ Version 2
C++  Version 2C++  Version 2
C++ Version 2
JIGAR MAKHIJA
 
C+Comprehensive overview of the IoT system aims, architecture, challenges, ap...
C+Comprehensive overview of the IoT system aims, architecture, challenges, ap...C+Comprehensive overview of the IoT system aims, architecture, challenges, ap...
C+Comprehensive overview of the IoT system aims, architecture, challenges, ap...
vyshnavzpradeep619
 
Basic Structure of C Language and Related Term
Basic Structure of C Language  and Related TermBasic Structure of C Language  and Related Term
Basic Structure of C Language and Related Term
MuhammadWaseem305
 
Intro To C++ - Class #21: Files
Intro To C++ - Class #21: FilesIntro To C++ - Class #21: Files
Intro To C++ - Class #21: Files
Blue Elephant Consulting
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
CoolGamer16
 
32sql server
32sql server32sql server
32sql server
Sireesh K
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
valerie5142000
 
INTRODUCTIONTO BASICS OF PROGRAMMING.pptx
INTRODUCTIONTO BASICS OF PROGRAMMING.pptxINTRODUCTIONTO BASICS OF PROGRAMMING.pptx
INTRODUCTIONTO BASICS OF PROGRAMMING.pptx
urvashipundir04
 
31cs
31cs31cs
31cs
Sireesh K
 
Chtp415
Chtp415Chtp415
Chtp415
giovanniveitch
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
Sireesh K
 
IOStream.pptx
IOStream.pptxIOStream.pptx
IOStream.pptx
HindAlmisbahi
 
File handling
File handlingFile handling
File handling
muhammad sharif bugti
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
Mahfuzur Rahman
 
Basics of Programming.pptx
Basics of Programming.pptxBasics of Programming.pptx
Basics of Programming.pptx
SoumitraChakraborty28
 
Csc240 -lecture_3
Csc240  -lecture_3Csc240  -lecture_3
Csc240 -lecture_3
Ainuddin Yousufzai
 

More from jamilmalik19 (11)

Evolution of Database Technology.pptx
Evolution of Database Technology.pptxEvolution of Database Technology.pptx
Evolution of Database Technology.pptx
jamilmalik19
 
Deadlocks.ppt
Deadlocks.pptDeadlocks.ppt
Deadlocks.ppt
jamilmalik19
 
Evolution of Database Technology.pptx
Evolution of Database Technology.pptxEvolution of Database Technology.pptx
Evolution of Database Technology.pptx
jamilmalik19
 
CD Store Management.pptx
CD Store Management.pptxCD Store Management.pptx
CD Store Management.pptx
jamilmalik19
 
bankers-algorithm2.pptx
bankers-algorithm2.pptxbankers-algorithm2.pptx
bankers-algorithm2.pptx
jamilmalik19
 
Introduction to DSA
Introduction to DSAIntroduction to DSA
Introduction to DSA
jamilmalik19
 
Wildcard In database
Wildcard In databaseWildcard In database
Wildcard In database
jamilmalik19
 
Angular momentum
Angular momentumAngular momentum
Angular momentum
jamilmalik19
 
What is IDE in C++?
What is IDE in C++?What is IDE in C++?
What is IDE in C++?
jamilmalik19
 
introduction to C++.pptx
introduction to C++.pptxintroduction to C++.pptx
introduction to C++.pptx
jamilmalik19
 
Data Types and variables in C++.pptx
Data Types and variables in C++.pptxData Types and variables in C++.pptx
Data Types and variables in C++.pptx
jamilmalik19
 
Evolution of Database Technology.pptx
Evolution of Database Technology.pptxEvolution of Database Technology.pptx
Evolution of Database Technology.pptx
jamilmalik19
 
Evolution of Database Technology.pptx
Evolution of Database Technology.pptxEvolution of Database Technology.pptx
Evolution of Database Technology.pptx
jamilmalik19
 
CD Store Management.pptx
CD Store Management.pptxCD Store Management.pptx
CD Store Management.pptx
jamilmalik19
 
bankers-algorithm2.pptx
bankers-algorithm2.pptxbankers-algorithm2.pptx
bankers-algorithm2.pptx
jamilmalik19
 
Introduction to DSA
Introduction to DSAIntroduction to DSA
Introduction to DSA
jamilmalik19
 
Wildcard In database
Wildcard In databaseWildcard In database
Wildcard In database
jamilmalik19
 
What is IDE in C++?
What is IDE in C++?What is IDE in C++?
What is IDE in C++?
jamilmalik19
 
introduction to C++.pptx
introduction to C++.pptxintroduction to C++.pptx
introduction to C++.pptx
jamilmalik19
 
Data Types and variables in C++.pptx
Data Types and variables in C++.pptxData Types and variables in C++.pptx
Data Types and variables in C++.pptx
jamilmalik19
 
Ad

Recently uploaded (20)

Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)
GS Virdi
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
How to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo SlidesHow to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo Slides
Celine George
 
Lecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptxLecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptx
Arshad Shaikh
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Computer crime and Legal issues Computer crime and Legal issues
Computer crime and Legal issues Computer crime and Legal issuesComputer crime and Legal issues Computer crime and Legal issues
Computer crime and Legal issues Computer crime and Legal issues
Abhijit Bodhe
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Tax evasion, Tax planning & Tax avoidance.pptx
Tax evasion, Tax  planning &  Tax avoidance.pptxTax evasion, Tax  planning &  Tax avoidance.pptx
Tax evasion, Tax planning & Tax avoidance.pptx
manishbaidya2017
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)
GS Virdi
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
How to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo SlidesHow to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo Slides
Celine George
 
Lecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptxLecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptx
Arshad Shaikh
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Computer crime and Legal issues Computer crime and Legal issues
Computer crime and Legal issues Computer crime and Legal issuesComputer crime and Legal issues Computer crime and Legal issues
Computer crime and Legal issues Computer crime and Legal issues
Abhijit Bodhe
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Tax evasion, Tax planning & Tax avoidance.pptx
Tax evasion, Tax  planning &  Tax avoidance.pptxTax evasion, Tax  planning &  Tax avoidance.pptx
Tax evasion, Tax planning & Tax avoidance.pptx
manishbaidya2017
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Ad

Exception Handling ,templates in C++

  • 2. Template • Template is simple and yet very powerful tool in C++ • Template are the foundation of generic programming which involves writing code in a away that is independent of any type. • A template is a blueprint or formula for creating a generic class or a function. • Function Template • Class Template
  • 3. Function Template • Replace Function overloading • Syntax Template <class A> • A is place holder (automatically set according to datatype) • A big(A a , A b) • Function template is also known as generic function. • Template < class type> type func_name ( type arg1,….);
  • 4. Class Template • Syntax : • Template < class type> class class_name {……};
  • 5. Exception • An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's Instructions.
  • 6. Exception Handling in C++ • The process of converting system error messages into user friendly error message is known as Exception handling. • This is one of the powerful feature of C++ to handle run time error and maintain normal flow of C++ application.
  • 7. Handling the Exception • Handling the exception is nothing but converting system error message into user friendly error message. Use Three keywords for Handling the Exception in C++ Language, they are; • try • catch • throw
  • 10. Try Block • It is one of the block in which we write the block of statements which causes executions at run time in other words try block always contains problematic statements.
  • 11. Catch block • It is one of the block in which we write the block of statements which will generates user friendly error messages in other words catch block will suppose system error messages
  • 19. File Handling • File Handling concept in C++ language is used for store a data permanently in computer. • Using file handling we can store our data in Secondary memory (Hard disk).
  • 23. Why use File Handling in C++ • For permanent storage. • The transfer of input - data or output - data from one computer to another can be easily done by using files. • For read and write from a file you need another standard C++ library called fstream, which defines three new data types.
  • 33. My Name Is Ali My Name Is Ali File Cout<<“ My Name Is Ali”; Cout<<“ My Name Is /n Ali: Fout<<“My Name Is /n Ali”; My Name Is Ali Sceen
  • 34. How to achieve File Handling For achieving file handling in C++ we need follow following steps • Naming a file • Opening a file • Reading data from file • Writing data into file • Closing a file
  • 35. Defining and Opening a File • The function open() can be used to open multiple files that use the same stream object.
  • 36. Closing a File • A file must be close after completion of all operation related to file. For closing file we need close() function.
  • 37. Program for file handling #include< iostream . h> #include< conio .h> #include< fstream . h> Class student { Public: Struct stu { char name[20]; int roll; }s; Void put_data(); Void get_data(); };
  • 38. void student :: put_data() { cout<<"enter name "; cin>>s. name; cout<<"enter roll "; cin>>s. roll; file. Open ("hit. txt“ , ios :: out | ios :: app); file. write ((char *)this, sizeof (student)); file. close(); getch(); get_data(); }
  • 39. void student :: get_data() { int temp; cout<<"enter roll no. "; cin >>temp; fstream file; file. open ("hit . txt", ios :: in); file.seekg(0,ios::beg); While (file . read ((char *) this, sizeof (student))) { If (temp==s. roll) { cout<<"student name "<< s . name<<"n"; cout<<"student roll "<< s . roll; } } getch (); }