SlideShare a Scribd company logo
2
Most read
5
Most read
6
Most read
Functions, classes & objects in c++
FUNCTIONS
• Function is the building block of C++.
• Used to reduce the size of the program by
calling and using them in different places in
the program.
• main()Function returns an integer value.
int main();
int main(int arg);
 Function return a value using return statement.
FUNCTION PROTOTYPE
• The function interface to the compiler by
giving the details like number, data type,
arguments – function prototype.
• It is a declaration statement in calling program
type function name (argument list);
Eg:
float volume (int x, float y, z);
float volume (int, float, float);
CALL BY REFERENCE
• C++ permits to pass the parameters to the
functions by reference variable.
• When it is passed the formal argument act as
the actual argument in the calling function
void swap(int a, int b)
{
int t = a;
a = b;
b = t;
}
INLINE & RECURSION FUNCTION
• An inline function is a function that is expanded in
line when it is invoked.
• The compiler replaces the function call with the
corresponding function code.
inline function header
{
function body
}
• It send a request not a command
• Recursion means function call by itself ie one of the
statement in the function definition makes a call to
the same in which it is present.
CLASS
• Collection of objects – CLASS
• The entire set of data and code of an object can
be made a user defined data type by using
class.
• 2 Parts:
– Class Declaration – describe the type & scope of
its members
– Class function definitions – how the class
function are implemented.
• General format:
class class-name
{
private:
variable declaration;
function declaration;
public:
variable declaration;
function declaration;
};
Class item
{
int number;
float cost;
public:
void getdata(int a, float b);
void putdata(void);
};
• Class member – the class body contains the
declaration of variables and functions.
• Data member – variables declared inside the
class.
• Member function – the function declared
inside the class.
DEFINING MEMBER FUNCTIONS
• Done by 2 ways
1. Outside the class definition
2. Inside the class definition
Outside the class definition
• Member function declared inside the class has to be
defined separately outside the class.
return-type class-name :: function-name
(argument declaration)
{
function body;
}
void item :: getdata (int a , float b)
{
number = a;
cost = b;
}
void item :: putdata (void)
{
cout<< “Number : “ << number;
cout << “Cost : “ << cost;
}
Inside the class definition
• It is to replace the function declaration by the actual
function definition inside the class.
class item
{
int number;
float cost;
public:
void getdata(int a, float b);
void putdata(void)
{
cout << number;
cout << cost;
}
};
Functions, classes & objects in c++

More Related Content

PPT
Files in c++ ppt
PPT
Function overloading(c++)
PPTX
Types of Constructor in C++
PPTX
Encapsulation C++
PPTX
Error and exception in python
PPT
1.python interpreter and interactive mode
PDF
Constructors and Destructors
PPT
Structure in c
Files in c++ ppt
Function overloading(c++)
Types of Constructor in C++
Encapsulation C++
Error and exception in python
1.python interpreter and interactive mode
Constructors and Destructors
Structure in c

What's hot (20)

PPTX
Functions in c++
PPT
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
PPTX
[OOP - Lec 18] Static Data Member
PPT
Operator Overloading
PPT
friend function(c++)
PPT
Methods in C#
PDF
Constructors and destructors
PPTX
array of object pointer in c++
PPTX
class and objects
PPTX
Templates in C++
PPSX
INTRODUCTION TO C PROGRAMMING
PPTX
Inheritance in c++
PPTX
Function in c
PPTX
GUI components in Java
PPTX
Pointer arithmetic in c
PPTX
Classes and objects
PPTX
classes and objects in C++
PPTX
Friend function
Functions in c++
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
[OOP - Lec 18] Static Data Member
Operator Overloading
friend function(c++)
Methods in C#
Constructors and destructors
array of object pointer in c++
class and objects
Templates in C++
INTRODUCTION TO C PROGRAMMING
Inheritance in c++
Function in c
GUI components in Java
Pointer arithmetic in c
Classes and objects
classes and objects in C++
Friend function
Ad

Similar to Functions, classes & objects in c++ (20)

PPTX
Chapter 13 introduction to classes
PPT
Class objects oopm
PPTX
Object Oriented Programming using C++ Unit 1
PDF
22 scheme OOPs with C++ BCS306B_module1.pdf
PPTX
Classes and objects
PPT
c++ lecture 1
PPT
c++ lecture 1
PPT
c++ introduction
PPT
C++ tutorials
PPTX
Array within a class
PPTX
Functions1
PDF
classes and objects.pdfggggggggffffffffgggf
PDF
Class and object
PPTX
Lecture 4. mte 407
PPT
Object and class presentation
PPTX
Chapter 2 OOP using C++ (Introduction).pptx
PDF
C++ Programming
PPTX
OOC MODULE1.pptx
PPT
Chapter 13 introduction to classes
Class objects oopm
Object Oriented Programming using C++ Unit 1
22 scheme OOPs with C++ BCS306B_module1.pdf
Classes and objects
c++ lecture 1
c++ lecture 1
c++ introduction
C++ tutorials
Array within a class
Functions1
classes and objects.pdfggggggggffffffffgggf
Class and object
Lecture 4. mte 407
Object and class presentation
Chapter 2 OOP using C++ (Introduction).pptx
C++ Programming
OOC MODULE1.pptx
Ad

More from ThamizhselviKrishnam (11)

PPTX
Standard template library
PPTX
Templates in c++
PPTX
Operators and expression in c++
PPTX
Page maker - working with text
PPTX
Microprocessor & architecture
PPTX
Instruction set of 8085
PPTX
Memory and storage devices
PPTX
Generations of computer
PPTX
Adobe Pagemaker 7.0
PPTX
classification of digital computer
PPTX
Standard template library
Templates in c++
Operators and expression in c++
Page maker - working with text
Microprocessor & architecture
Instruction set of 8085
Memory and storage devices
Generations of computer
Adobe Pagemaker 7.0
classification of digital computer

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Big Data Technologies - Introduction.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Cloud computing and distributed systems.
PDF
Approach and Philosophy of On baking technology
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
cuic standard and advanced reporting.pdf
Teaching material agriculture food technology
NewMind AI Weekly Chronicles - August'25 Week I
Big Data Technologies - Introduction.pptx
Machine learning based COVID-19 study performance prediction
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Network Security Unit 5.pdf for BCA BBA.
20250228 LYD VKU AI Blended-Learning.pptx
Spectral efficient network and resource selection model in 5G networks
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Cloud computing and distributed systems.
Approach and Philosophy of On baking technology
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Reach Out and Touch Someone: Haptics and Empathic Computing
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
cuic standard and advanced reporting.pdf

Functions, classes & objects in c++

  • 2. FUNCTIONS • Function is the building block of C++. • Used to reduce the size of the program by calling and using them in different places in the program. • main()Function returns an integer value. int main(); int main(int arg);  Function return a value using return statement.
  • 3. FUNCTION PROTOTYPE • The function interface to the compiler by giving the details like number, data type, arguments – function prototype. • It is a declaration statement in calling program type function name (argument list); Eg: float volume (int x, float y, z); float volume (int, float, float);
  • 4. CALL BY REFERENCE • C++ permits to pass the parameters to the functions by reference variable. • When it is passed the formal argument act as the actual argument in the calling function void swap(int a, int b) { int t = a; a = b; b = t; }
  • 5. INLINE & RECURSION FUNCTION • An inline function is a function that is expanded in line when it is invoked. • The compiler replaces the function call with the corresponding function code. inline function header { function body } • It send a request not a command • Recursion means function call by itself ie one of the statement in the function definition makes a call to the same in which it is present.
  • 6. CLASS • Collection of objects – CLASS • The entire set of data and code of an object can be made a user defined data type by using class. • 2 Parts: – Class Declaration – describe the type & scope of its members – Class function definitions – how the class function are implemented.
  • 7. • General format: class class-name { private: variable declaration; function declaration; public: variable declaration; function declaration; }; Class item { int number; float cost; public: void getdata(int a, float b); void putdata(void); };
  • 8. • Class member – the class body contains the declaration of variables and functions. • Data member – variables declared inside the class. • Member function – the function declared inside the class.
  • 9. DEFINING MEMBER FUNCTIONS • Done by 2 ways 1. Outside the class definition 2. Inside the class definition
  • 10. Outside the class definition • Member function declared inside the class has to be defined separately outside the class. return-type class-name :: function-name (argument declaration) { function body; }
  • 11. void item :: getdata (int a , float b) { number = a; cost = b; } void item :: putdata (void) { cout<< “Number : “ << number; cout << “Cost : “ << cost; }
  • 12. Inside the class definition • It is to replace the function declaration by the actual function definition inside the class. class item { int number; float cost; public: void getdata(int a, float b); void putdata(void) { cout << number; cout << cost; } };