Answer:
The header file in C++ is as follows
myFunction.h
void max(int a, int b)
{
if(a>b)
{
std::cout<<a;
}
else
{
std::cout<<b;
}
<em>}</em>
The Driver Program is as follows:
#include<iostream>
#include<myFunction.h>
<em>using namespace std; </em>
int main()
{
int m,n;
cin>>m;
cin>>n;
max(m,n);
<em>}</em>
Explanation:
It should be noted that, for this program to work without errors, the header file (myFunction.h) has to be saved in the include directory of the C++ IDE software you are using.
For instance; To answer this question I used DevC++
So, the first thing I did after coding myFunction.h is to save this file in the following directory ..\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\
Back to the code
myFunction.h
void max(int a, int b) {
-> This prototype is intialized with integer variables a and b
if(a>b) -> If the value of a is greater than b;
{
std::cout<<a; -> then the value of variable a will be printed
}
else
-> if otherwise,
{
std::cout<<b;
-> The value of b will be printed
}
}
Driver File (The .cpp file)
#include<iostream>
#include<myFunction.h> -> This line includes the uesr defined header
using namespace std;
int main()
{
int m,n; -> Two integer variables are declared
cin>>m; -> This line accepts first integer input
cin>>n; -> This line accepts second integer input
max(m,n);
-> This line calls user defined function to return the largest of the two integer variables
}