Answer:
#include <iostream> //header file
#include <stdlib.h>
#include <time.h>
using namespace std; // using namespace
string call_by_value(int num) // call by value
{
if(num==1)
return "hello sir!";
if(num==2)
return "what's going on?";
if(num==3)
return "howz you master?!";
if(num==4)
return "i m fine!";
}
string call_by_reference(int *num) //call by reference
{
if(*num==1)
return "hello sir!!";
if(*num==2)
return "what's going on?";
if(*num==3)
return "howz you master?";
if(*num==4)
return "i m fine";
}
int main() { //main function
int n,v,r;
string str;
srand (time(NULL));
cout<<"enter a value 1 and 2 for choice and -1 for exit : ";
cin>>n;
while(n!=-1)
{
if(n==1)
{
int num = (rand()%(4)) + 1;
str=call_by_value(num);
cout<<str<<endl;
}
else if(n==2)
{
int num = (rand()%(4)) + 1;
str=call_by_reference(&num);
cout<<str<<endl;
}
else
cout<<"invalid input !"<<endl;
cout<<"enter a value 1 and 2 for choice and -1 for exit :";
cin>>n;
}
return 0;
}
Explanation:
Firstly, we declare three header files, then use namespace
Then, create the module of call by value and then call by reference.
Then we define the main() function in which we call both the modules.