SlideShare a Scribd company logo
R.KARTHIKEYAN
Assistant Professor
Department of Commerce(CA)
Vivekananda College
Tiruvedakam West
Madurai – 625 234
E-mail : vishalkarthi12@gmail.com
Contact No: 97893 89135
 Pointers
 Polymorphism
 Polymorphism Types
 This Pointer
 Virtual Functions
 Pure Virtual Function
 C++ Stream
 Stream Classes
 Unformatted I/O operations
 Formatted I/O operations
.
Pointers
 Pointer is a variable, that holds the address of
another variable.
 Every variable is a memory location and every
memory location has its address defined which can
be accessed using ampersand (&) operator which
denotes an address in memory.
 Like any variable or constant, you must declare a
pointer before you can work with it.
Syntax of Pointer variable declaration
type *var-name;
 type is the pointer's base type
 var-name is the name of the pointer variable.
int *ip; // pointer to an integer
float *fp; // pointer to a float
Note: Asterisk is being used to designate a variable as
a pointer.
Example
#include <iostream>
#include <conio.h>
int main ()
{
int var = 20;
int *ip;
ip = &var;
cout << "Value of var variable: ";
cout << var << endl;
cout << "Address stored in ip variable: ";
cout << ip << endl;
cout << "Value of *ip variable: ";
cout << *ip << endl;
return 0;
}
Output:
Value of var variable: 20
Address stored in ip variable:
0x7ffc787f0f44
Value of *ip variable: 20
Polymorphism
 Polymorphism means having many forms.
 polymorphism means that a call to a
member function will cause a different
function to be executed depending on the
type of object that invokes the function.
Types of Polymorphism
COMPILE TIME POLYMORPHISM.
 Static Polymorphism also known as
compile time polymorphism.
 Polymorphism that is resolved during
compiler time is known as static
polymorphism.
 Method overloading is an example of
compile time polymorphism.
Method overloading:
Method Overloading is more than one method having the
same name, if their argument lists are different.
Run Time Polymorphism
 Dynamic Polymorphism also known as
runtime polymorphism.
 Dynamic polymorphism is a process in which
a call to an overridden method is resolved at
runtime, thats why it is called runtime
polymorphism.
Virtual Function
 A virtual function is a member function in
the base class that you redefine in a derived
class.
 A 'virtual' is a keyword preceding the normal
declaration of a function.
Syntax:
virtual return _type f unction name()
{
}
Base Class
Derived Class
Member Function
Pure Virtual Function
 Pure Virtual function are virtual functions with
no definition.
 They start with Virtual keyword and ends with =
0.
Virtual void display () = 0
class Test
{
// Data members of class
public:
virtual void show() = 0;
/* Other members */
};
Pure Virtual Function
This pointer
 This pointer is used to represent the
address of an object inside a member
function.
 The this pointer is an implicit parameter to
all member functions.
 Friend functions do not have a this pointer,
because friends are not members of a class.
 Only member functions have a this pointer.
This pointer Example
class Test
{
private:
int x;
public:
void setX (int x)
{
this->x = x;
}
void print()
{
cout << "x = " << x << endl;
}
};
int main()
{
Test obj;
int x = 20;
obj.setX(x);
obj.print();
return 0;
}
Streams
A transfer of information in the form of sequence of bytes.
The I/O system of c++ contains:
 Istream class supports Input function
 Ostream class supports Output function
 iostream standard library, which provides cin and cout methods
for reading from standard input and writing to standard output.
Stream Classes
Cin
 Cin is predefined object of istream
class.
 The cin object is attached to be
standard input device.
 Cin is used in Conjuction with stream
extraction operator, which is written
as >>.
#include <iostream.h>
#include <conio.h>
int main()
{
int no;
cout<<"Enter a number ";
cin>>no;
cout<<"Number entered is ="<<no;
return 0;
}
Output:
Enter a number 55
Number entered is = 55
Cout
 Cout is predefined object ofostream
class.
 The cout object is to be connected to
the standard output device, which
display in screen.
 Cout object connected with stream
insertion operator as <<.
Cout
include <iostream>
include <iostream>
int main()
{
int a=10;
Cout<<“Value of the a:”<<a<<endl;
}
Output:
Value of the a:10
Formatted I/O Operations
Format the I/O operations like determining the
number of digits to be displayed after the decimal
point, specifying number base .
 Using the ios class or various ios member functions.
 Using manipulators(special functions)
ios class functions
width(): The width method is used to set the required
field width. The output will be displayed in the given
width.
precision(): The precision method is used to set the
number of the decimal point to a float value.
fill(): The fill method is used to set a character to fill in
the blank space of a field.
setf(): The setf method is used to set various flags for
formatting output.
unsetf(): The unsetf method is used To remove the
flag setting.
Manipulators
 Manipulators are operators used in C++ for formatting
output.
 The data is manipulated by the programmer’s choice of
display.
Endl
This manipulator has the same functionality as the ‘n’
newline character.
Example:
cout << “exam" << endl;
setw
This manipulator sets the minimum field width on output.
Manipulators
Setfill
 This is used after setw manipulator.
 If a value does not entirely fill a field, then the character
specified in the setfill argument of the manipulator is used
for filling the fields.
Manipulators
setprecision :
 The setprecision Manipulator is used with floating point
numbers.
 It is used to set the number of digits printed to the right of the
decimal point.
Example:
#include <iostream>
#include <iomanip>
void main( )
{
float x = 0.1;
cout << fixed << setprecision(3) << x << endl;
Unformatted consol input output
Unformatted console input/output functions are used to read a
single input from the user at console and it also allows us to
display the value in the output to the user at the console.
get () – used to read a single character from the i/p device.
Syntax:
char c=cin.get();
put() – used to print a single character on to the console.
Syntax:
cout.put(variable / character);
getline() - reads array of characters that ends with ‘n’
by default or until the limit is reached.
#include<iostream>
#include<conio.h>
int main()
{
cout<<"Enter name :";
char c[10];
cin.getline(c,10);
cout<<c<<endl;
return 0;
}
It takes 10 characters as input;
write() – print the array of characters to the console
#include<iostream>
#include<conio.h>
int main()
{ cout<<"Enter name : ";
char c[10]; cin.getline(c,10);
cout.write(c,9);
return 0;
}
It takes 10 characters as input;
Object Oriented Programming with C++
Object Oriented Programming with C++

More Related Content

What's hot

Lecture#7 Call by value and reference in c++
Lecture#7 Call by value and reference in c++Lecture#7 Call by value and reference in c++
Lecture#7 Call by value and reference in c++
NUST Stuff
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
AmIt Prasad
 
Unit iv functions
Unit  iv functionsUnit  iv functions
Unit iv functions
indra Kishor
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
kavitha muneeshwaran
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
Advanced C programming
Advanced C programmingAdvanced C programming
Advanced C programming
Claus Wu
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Maaz Hasan
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
Sachin Yadav
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
Inline assembly language programs in c
Inline assembly language programs in cInline assembly language programs in c
Inline assembly language programs in cTech_MX
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
Mohammed Saleh
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
VC Infotech
 
Function in C
Function in CFunction in C
Function in C
Dr. Abhineet Anand
 
Functions in c
Functions in cFunctions in c
Functions in c
KavithaMuralidharan2
 
Control Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, StructuresControl Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, Structures
indra Kishor
 
functions in C and types
functions in C and typesfunctions in C and types
functions in C and types
mubashir farooq
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
Vishalini Mugunen
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
Syed Mustafa
 

What's hot (20)

Lecture#7 Call by value and reference in c++
Lecture#7 Call by value and reference in c++Lecture#7 Call by value and reference in c++
Lecture#7 Call by value and reference in c++
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 
Unit iv functions
Unit  iv functionsUnit  iv functions
Unit iv functions
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Advanced C programming
Advanced C programmingAdvanced C programming
Advanced C programming
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 
Inline assembly language programs in c
Inline assembly language programs in cInline assembly language programs in c
Inline assembly language programs in c
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
 
Function in C
Function in CFunction in C
Function in C
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Control Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, StructuresControl Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, Structures
 
Type Casting in C++
Type Casting in C++Type Casting in C++
Type Casting in C++
 
functions in C and types
functions in C and typesfunctions in C and types
functions in C and types
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
 

Similar to Object Oriented Programming with C++

Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programming
LidetAdmassu
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphism
lalithambiga kamaraj
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
msharshitha03s
 
Functions in C++.pdf
Functions in C++.pdfFunctions in C++.pdf
Functions in C++.pdf
LadallaRajKumar
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloadingankush_kumar
 
Function C++
Function C++ Function C++
Function C++
Shahzad Afridi
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
LPU
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
C function
C functionC function
C function
thirumalaikumar3
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
GebruGetachew2
 
Nitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptxNitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptx
shivam460694
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
ppd1961
 
4th unit full
4th unit full4th unit full
4th unit full
Murali Saktheeswaran
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 FunctionDeepak Singh
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsHCMUTE
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
Function in c
Function in cFunction in c
1. DSA - Introduction.pptx
1. DSA - Introduction.pptx1. DSA - Introduction.pptx
1. DSA - Introduction.pptx
hara69
 
12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp
sharvivek
 

Similar to Object Oriented Programming with C++ (20)

Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programming
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphism
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
Functions in C++.pdf
Functions in C++.pdfFunctions in C++.pdf
Functions in C++.pdf
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 
Function C++
Function C++ Function C++
Function C++
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
C function
C functionC function
C function
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
 
Nitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptxNitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptx
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
 
4th unit full
4th unit full4th unit full
4th unit full
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Function in c
Function in cFunction in c
Function in c
 
1. DSA - Introduction.pptx
1. DSA - Introduction.pptx1. DSA - Introduction.pptx
1. DSA - Introduction.pptx
 
12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp
 

More from R.Karthikeyan - Vivekananda College

Relationship of donor and recipient, immunological basis of graft rejection
Relationship of donor and recipient, immunological basis of graft rejectionRelationship of donor and recipient, immunological basis of graft rejection
Relationship of donor and recipient, immunological basis of graft rejection
R.Karthikeyan - Vivekananda College
 
The govt.of india act of 1919
The govt.of india act of 1919The govt.of india act of 1919
The govt.of india act of 1919
R.Karthikeyan - Vivekananda College
 
Minto morley reform act of 1909
Minto morley reform act of 1909Minto morley reform act of 1909
Minto morley reform act of 1909
R.Karthikeyan - Vivekananda College
 
History of India(From 900 AD to 1707 AD)
History of India(From 900 AD to 1707 AD)  History of India(From 900 AD to 1707 AD)
History of India(From 900 AD to 1707 AD)
R.Karthikeyan - Vivekananda College
 

More from R.Karthikeyan - Vivekananda College (20)

HLA system and principles of tolerance
HLA system and principles of toleranceHLA system and principles of tolerance
HLA system and principles of tolerance
 
Relationship of donor and recipient, immunological basis of graft rejection
Relationship of donor and recipient, immunological basis of graft rejectionRelationship of donor and recipient, immunological basis of graft rejection
Relationship of donor and recipient, immunological basis of graft rejection
 
Autoimmunity
AutoimmunityAutoimmunity
Autoimmunity
 
Optics and sound
Optics and soundOptics and sound
Optics and sound
 
Integral calculus
Integral calculusIntegral calculus
Integral calculus
 
SIDBI
SIDBISIDBI
SIDBI
 
SIDCO
SIDCOSIDCO
SIDCO
 
District Industries Centre
District Industries CentreDistrict Industries Centre
District Industries Centre
 
EDP
EDPEDP
EDP
 
Tamil
TamilTamil
Tamil
 
Tamil
TamilTamil
Tamil
 
Botany
BotanyBotany
Botany
 
Colligative properties
Colligative properties Colligative properties
Colligative properties
 
Sher shah sur
Sher shah surSher shah sur
Sher shah sur
 
Physical training
Physical trainingPhysical training
Physical training
 
The govt.of india act of 1919
The govt.of india act of 1919The govt.of india act of 1919
The govt.of india act of 1919
 
Minto morley reform act of 1909
Minto morley reform act of 1909Minto morley reform act of 1909
Minto morley reform act of 1909
 
Tribal population of india
Tribal population of indiaTribal population of india
Tribal population of india
 
History of India(From 900 AD to 1707 AD)
History of India(From 900 AD to 1707 AD)  History of India(From 900 AD to 1707 AD)
History of India(From 900 AD to 1707 AD)
 
Life and achievements of shivaji
Life and achievements of shivajiLife and achievements of shivaji
Life and achievements of shivaji
 

Recently uploaded

June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 

Recently uploaded (20)

June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 

Object Oriented Programming with C++

  • 1. R.KARTHIKEYAN Assistant Professor Department of Commerce(CA) Vivekananda College Tiruvedakam West Madurai – 625 234 E-mail : vishalkarthi12@gmail.com Contact No: 97893 89135
  • 2.
  • 3.  Pointers  Polymorphism  Polymorphism Types  This Pointer  Virtual Functions  Pure Virtual Function  C++ Stream  Stream Classes  Unformatted I/O operations  Formatted I/O operations .
  • 4. Pointers  Pointer is a variable, that holds the address of another variable.  Every variable is a memory location and every memory location has its address defined which can be accessed using ampersand (&) operator which denotes an address in memory.  Like any variable or constant, you must declare a pointer before you can work with it.
  • 5. Syntax of Pointer variable declaration type *var-name;  type is the pointer's base type  var-name is the name of the pointer variable. int *ip; // pointer to an integer float *fp; // pointer to a float Note: Asterisk is being used to designate a variable as a pointer.
  • 6. Example #include <iostream> #include <conio.h> int main () { int var = 20; int *ip; ip = &var; cout << "Value of var variable: "; cout << var << endl; cout << "Address stored in ip variable: "; cout << ip << endl; cout << "Value of *ip variable: "; cout << *ip << endl; return 0; } Output: Value of var variable: 20 Address stored in ip variable: 0x7ffc787f0f44 Value of *ip variable: 20
  • 7. Polymorphism  Polymorphism means having many forms.  polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function.
  • 9. COMPILE TIME POLYMORPHISM.  Static Polymorphism also known as compile time polymorphism.  Polymorphism that is resolved during compiler time is known as static polymorphism.  Method overloading is an example of compile time polymorphism. Method overloading: Method Overloading is more than one method having the same name, if their argument lists are different.
  • 10. Run Time Polymorphism  Dynamic Polymorphism also known as runtime polymorphism.  Dynamic polymorphism is a process in which a call to an overridden method is resolved at runtime, thats why it is called runtime polymorphism.
  • 11. Virtual Function  A virtual function is a member function in the base class that you redefine in a derived class.  A 'virtual' is a keyword preceding the normal declaration of a function. Syntax: virtual return _type f unction name() { }
  • 13. Pure Virtual Function  Pure Virtual function are virtual functions with no definition.  They start with Virtual keyword and ends with = 0. Virtual void display () = 0 class Test { // Data members of class public: virtual void show() = 0; /* Other members */ }; Pure Virtual Function
  • 14. This pointer  This pointer is used to represent the address of an object inside a member function.  The this pointer is an implicit parameter to all member functions.  Friend functions do not have a this pointer, because friends are not members of a class.  Only member functions have a this pointer.
  • 15. This pointer Example class Test { private: int x; public: void setX (int x) { this->x = x; } void print() { cout << "x = " << x << endl; } }; int main() { Test obj; int x = 20; obj.setX(x); obj.print(); return 0; }
  • 16. Streams A transfer of information in the form of sequence of bytes. The I/O system of c++ contains:  Istream class supports Input function  Ostream class supports Output function  iostream standard library, which provides cin and cout methods for reading from standard input and writing to standard output.
  • 18.
  • 19. Cin  Cin is predefined object of istream class.  The cin object is attached to be standard input device.  Cin is used in Conjuction with stream extraction operator, which is written as >>.
  • 20. #include <iostream.h> #include <conio.h> int main() { int no; cout<<"Enter a number "; cin>>no; cout<<"Number entered is ="<<no; return 0; } Output: Enter a number 55 Number entered is = 55
  • 21. Cout  Cout is predefined object ofostream class.  The cout object is to be connected to the standard output device, which display in screen.  Cout object connected with stream insertion operator as <<.
  • 22. Cout include <iostream> include <iostream> int main() { int a=10; Cout<<“Value of the a:”<<a<<endl; } Output: Value of the a:10
  • 23. Formatted I/O Operations Format the I/O operations like determining the number of digits to be displayed after the decimal point, specifying number base .  Using the ios class or various ios member functions.  Using manipulators(special functions)
  • 24. ios class functions width(): The width method is used to set the required field width. The output will be displayed in the given width. precision(): The precision method is used to set the number of the decimal point to a float value. fill(): The fill method is used to set a character to fill in the blank space of a field. setf(): The setf method is used to set various flags for formatting output. unsetf(): The unsetf method is used To remove the flag setting.
  • 25. Manipulators  Manipulators are operators used in C++ for formatting output.  The data is manipulated by the programmer’s choice of display. Endl This manipulator has the same functionality as the ‘n’ newline character. Example: cout << “exam" << endl; setw This manipulator sets the minimum field width on output.
  • 26. Manipulators Setfill  This is used after setw manipulator.  If a value does not entirely fill a field, then the character specified in the setfill argument of the manipulator is used for filling the fields.
  • 27. Manipulators setprecision :  The setprecision Manipulator is used with floating point numbers.  It is used to set the number of digits printed to the right of the decimal point. Example: #include <iostream> #include <iomanip> void main( ) { float x = 0.1; cout << fixed << setprecision(3) << x << endl;
  • 28. Unformatted consol input output Unformatted console input/output functions are used to read a single input from the user at console and it also allows us to display the value in the output to the user at the console. get () – used to read a single character from the i/p device. Syntax: char c=cin.get(); put() – used to print a single character on to the console. Syntax: cout.put(variable / character);
  • 29. getline() - reads array of characters that ends with ‘n’ by default or until the limit is reached. #include<iostream> #include<conio.h> int main() { cout<<"Enter name :"; char c[10]; cin.getline(c,10); cout<<c<<endl; return 0; } It takes 10 characters as input;
  • 30. write() – print the array of characters to the console #include<iostream> #include<conio.h> int main() { cout<<"Enter name : "; char c[10]; cin.getline(c,10); cout.write(c,9); return 0; } It takes 10 characters as input;