SlideShare a Scribd company logo
Function
Introduction
 Use of function
   Calling a formula defined by user
   Input & Output depends on type of function


 Not included in main body


 Can be called many times
Function Prototype
 After #include<iostream>
 Before int main()

    Example 1

    # include <iostream>

    void FindMax(int, int); //prototype

    using namespace std;
    int main()
4




Calling Function
Example 2

int main()
{
    int num1, num2;
    cout<<"Please enter a number :";
    cin>> num1;
    cout<<"Great!nPlease enter a second number :";
    cin>> num2;
    FindMax(num1, num2); //calling function

     system ("PAUSE");
     return 0;
}
Defining Function
 Outside main body
 Example 3

 void FindMax(int x, int y){
      int maxNum;
      if (x>=y)
      maxNum=x;
      else
      maxNum=y;
      cout<<"Maximum number is : "<<maxNum <<endl;
      }
Using reference variable
 The Prototype:
    void FindMax(double, double, double&);


 The Calling:
    FindMax(num1, num2, maxNum);


 The Defining:
    void FindMax(double x, double y, double& maxNum)


 maxNum: a value edited in main function
•   Compare Example 2

Example 4

int main()
{
    double num1, num2, maxNum;
    cout<<"Please enter a number :";
    cin>> num1;
    cout<<"Great!nPlease enter a second number :";
    cin>> num2;
    FindMax(num1, num2, maxNum); //calling

     system ("PAUSE");
     return 0;
}

                                          Go to DevC++
Looping Function
 Just insert function in loop to call as needed
 Looping with returned value :
    Declare return value
    Send value to function


 Write a loop
   Example :
       Using while loop to keep comparing numbers
Example 5

char next;
while(true){
   cout<<"n('n' to exit')Compare with next number? :";
   cin>> next;
   if(next=='n')
   break;
   cout<<"Okay!nPlease enter the next number :";
   cin>> num1;
   num2 = maxNum;
   FindMax(num1, num2, maxNum);
   }
END
Ad

More Related Content

What's hot (20)

Functions in C++
Functions in C++Functions in C++
Functions in C++
Mohammed Sikander
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
Kamal Acharya
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
Sanjit Shaw
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
Dhrumil Panchal
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
CONST-- once initialised, no one can change it
CONST-- once initialised, no one can change itCONST-- once initialised, no one can change it
CONST-- once initialised, no one can change it
Ajay Chimmani
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
Ahmad Idrees
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
Tech_MX
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
Viji B
 
Standard template library
Standard template libraryStandard template library
Standard template library
Jancypriya M
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
Srichandan Sobhanayak
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
C++ Function
C++ FunctionC++ Function
C++ Function
Hajar
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
Shyam Gupta
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
Neeru Mittal
 
Late and Early binding in c++
Late and Early binding in c++Late and Early binding in c++
Late and Early binding in c++
FazalRehman79
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
Appili Vamsi Krishna
 
Binary operator overloading
Binary operator overloadingBinary operator overloading
Binary operator overloading
BalajiGovindan5
 
Functions in c
Functions in cFunctions in c
Functions in c
sunila tharagaturi
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
Anil Pokhrel
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
Sanjit Shaw
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
Dhrumil Panchal
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
CONST-- once initialised, no one can change it
CONST-- once initialised, no one can change itCONST-- once initialised, no one can change it
CONST-- once initialised, no one can change it
Ajay Chimmani
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
Ahmad Idrees
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
Tech_MX
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
Viji B
 
Standard template library
Standard template libraryStandard template library
Standard template library
Jancypriya M
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
C++ Function
C++ FunctionC++ Function
C++ Function
Hajar
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
Shyam Gupta
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
Neeru Mittal
 
Late and Early binding in c++
Late and Early binding in c++Late and Early binding in c++
Late and Early binding in c++
FazalRehman79
 
Binary operator overloading
Binary operator overloadingBinary operator overloading
Binary operator overloading
BalajiGovindan5
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
Anil Pokhrel
 

Viewers also liked (20)

16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
LPU
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
Function in c++
Function in c++Function in c++
Function in c++
Kumar
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
ForwardBlog Enewzletter
 
Call by value
Call by valueCall by value
Call by value
Dharani G
 
Functions
FunctionsFunctions
Functions
Online
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
Jenish Patel
 
Inline function
Inline functionInline function
Inline function
Tech_MX
 
7 Slide Summary: HOW can India's Parliament function better?
7 Slide Summary: HOW can India's Parliament function better?7 Slide Summary: HOW can India's Parliament function better?
7 Slide Summary: HOW can India's Parliament function better?
Yogesh Upadhyaya
 
02. functions & introduction to class
02. functions & introduction to class02. functions & introduction to class
02. functions & introduction to class
Haresh Jaiswal
 
Dynamics Behaviour of Multi Storeys Framed Structures by of Iterative Method
Dynamics Behaviour of Multi Storeys Framed  Structures by of Iterative Method Dynamics Behaviour of Multi Storeys Framed  Structures by of Iterative Method
Dynamics Behaviour of Multi Storeys Framed Structures by of Iterative Method
AM Publications
 
PARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMSPARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMS
Arpee Callejo
 
What is c
What is cWhat is c
What is c
Nitesh Saitwal
 
Trees
TreesTrees
Trees
Sadaf Ismail
 
EEE 3rd year oops cat 3 ans
EEE 3rd year  oops cat 3  ansEEE 3rd year  oops cat 3  ans
EEE 3rd year oops cat 3 ans
Karthik Venkatachalam
 
Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)
indiangarg
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
Jeba Moses
 
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
Supriya Radhakrishna
 
Viva questions
Viva questions Viva questions
Viva questions
Mohammad Hafiz Bin Hamzah, M. Sc.
 
inline function
inline function inline function
inline function
imran khan
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
LPU
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
Function in c++
Function in c++Function in c++
Function in c++
Kumar
 
Call by value
Call by valueCall by value
Call by value
Dharani G
 
Functions
FunctionsFunctions
Functions
Online
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
Jenish Patel
 
Inline function
Inline functionInline function
Inline function
Tech_MX
 
7 Slide Summary: HOW can India's Parliament function better?
7 Slide Summary: HOW can India's Parliament function better?7 Slide Summary: HOW can India's Parliament function better?
7 Slide Summary: HOW can India's Parliament function better?
Yogesh Upadhyaya
 
02. functions & introduction to class
02. functions & introduction to class02. functions & introduction to class
02. functions & introduction to class
Haresh Jaiswal
 
Dynamics Behaviour of Multi Storeys Framed Structures by of Iterative Method
Dynamics Behaviour of Multi Storeys Framed  Structures by of Iterative Method Dynamics Behaviour of Multi Storeys Framed  Structures by of Iterative Method
Dynamics Behaviour of Multi Storeys Framed Structures by of Iterative Method
AM Publications
 
PARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMSPARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMS
Arpee Callejo
 
Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)
indiangarg
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
Jeba Moses
 
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
Supriya Radhakrishna
 
inline function
inline function inline function
inline function
imran khan
 
Ad

Similar to C++ programming function (20)

C++ file
C++ fileC++ file
C++ file
Mukund Trivedi
 
C++ file
C++ fileC++ file
C++ file
Mukund Trivedi
 
Silde of the cse fundamentals a deep analysis
Silde of the cse fundamentals a deep analysisSilde of the cse fundamentals a deep analysis
Silde of the cse fundamentals a deep analysis
Rayhan331
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functions
TAlha MAlik
 
how to reuse code
how to reuse codehow to reuse code
how to reuse code
jleed1
 
Part 3-functions1-120315220356-phpapp01
Part 3-functions1-120315220356-phpapp01Part 3-functions1-120315220356-phpapp01
Part 3-functions1-120315220356-phpapp01
Abdul Samee
 
Function
FunctionFunction
Function
venkatme83
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
harman kaur
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
temkin abdlkader
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
amrit47
 
C++ Language
C++ LanguageC++ Language
C++ Language
Syed Zaid Irshad
 
Programming Fundamentals lecture-10.pptx
Programming Fundamentals lecture-10.pptxProgramming Fundamentals lecture-10.pptx
Programming Fundamentals lecture-10.pptx
singyali199
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
TarekHemdan3
 
Object Oriented Programming (OOP) using C++ - Lecture 5
Object Oriented Programming (OOP) using C++ - Lecture 5Object Oriented Programming (OOP) using C++ - Lecture 5
Object Oriented Programming (OOP) using C++ - Lecture 5
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
functions
functionsfunctions
functions
teach4uin
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
NagasaiT
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
mallik3000
 
Fp201 unit5 1
Fp201 unit5 1Fp201 unit5 1
Fp201 unit5 1
rohassanie
 
C++ Functions.ppt
C++ Functions.pptC++ Functions.ppt
C++ Functions.ppt
WaheedAnwar20
 
Pointer to Member Function.pptx pointer in c++
Pointer to Member Function.pptx pointer in c++Pointer to Member Function.pptx pointer in c++
Pointer to Member Function.pptx pointer in c++
ankeshshri
 
Silde of the cse fundamentals a deep analysis
Silde of the cse fundamentals a deep analysisSilde of the cse fundamentals a deep analysis
Silde of the cse fundamentals a deep analysis
Rayhan331
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functions
TAlha MAlik
 
how to reuse code
how to reuse codehow to reuse code
how to reuse code
jleed1
 
Part 3-functions1-120315220356-phpapp01
Part 3-functions1-120315220356-phpapp01Part 3-functions1-120315220356-phpapp01
Part 3-functions1-120315220356-phpapp01
Abdul Samee
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
harman kaur
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
amrit47
 
Programming Fundamentals lecture-10.pptx
Programming Fundamentals lecture-10.pptxProgramming Fundamentals lecture-10.pptx
Programming Fundamentals lecture-10.pptx
singyali199
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
NagasaiT
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
mallik3000
 
Pointer to Member Function.pptx pointer in c++
Pointer to Member Function.pptx pointer in c++Pointer to Member Function.pptx pointer in c++
Pointer to Member Function.pptx pointer in c++
ankeshshri
 
Ad

Recently uploaded (20)

GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Build With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdfBuild With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdf
Google Developer Group - Harare
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptxSmart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Seasia Infotech
 
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptxSmart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Seasia Infotech
 
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 

C++ programming function

  • 2. Introduction  Use of function  Calling a formula defined by user  Input & Output depends on type of function  Not included in main body  Can be called many times
  • 3. Function Prototype  After #include<iostream>  Before int main() Example 1 # include <iostream> void FindMax(int, int); //prototype using namespace std; int main()
  • 4. 4 Calling Function Example 2 int main() { int num1, num2; cout<<"Please enter a number :"; cin>> num1; cout<<"Great!nPlease enter a second number :"; cin>> num2; FindMax(num1, num2); //calling function system ("PAUSE"); return 0; }
  • 5. Defining Function  Outside main body Example 3 void FindMax(int x, int y){ int maxNum; if (x>=y) maxNum=x; else maxNum=y; cout<<"Maximum number is : "<<maxNum <<endl; }
  • 6. Using reference variable  The Prototype:  void FindMax(double, double, double&);  The Calling:  FindMax(num1, num2, maxNum);  The Defining:  void FindMax(double x, double y, double& maxNum)  maxNum: a value edited in main function
  • 7. Compare Example 2 Example 4 int main() { double num1, num2, maxNum; cout<<"Please enter a number :"; cin>> num1; cout<<"Great!nPlease enter a second number :"; cin>> num2; FindMax(num1, num2, maxNum); //calling system ("PAUSE"); return 0; } Go to DevC++
  • 8. Looping Function  Just insert function in loop to call as needed  Looping with returned value :  Declare return value  Send value to function  Write a loop  Example :  Using while loop to keep comparing numbers
  • 9. Example 5 char next; while(true){ cout<<"n('n' to exit')Compare with next number? :"; cin>> next; if(next=='n') break; cout<<"Okay!nPlease enter the next number :"; cin>> num1; num2 = maxNum; FindMax(num1, num2, maxNum); }
  • 10. END
  翻译: