Create three functions called prompt( ) that perform this task for data of types int, double, and long : Function Overloaded « Function « C++






Create three functions called prompt( ) that perform this task for data of types int, double, and long

  
#include <iostream>  
using namespace std;

void prompt(char *str, int *i);  
void prompt(char *str, double *d);  
void prompt(char *str, long *l);  
     
int main(void){  
  int i;  
  double d;  
  long l;  
     
  prompt("Enter an integer: ", &i);  
  prompt("Enter a double: ", &d);  
  prompt("Enter a long: ", &l);  
     
  cout << i << " " << d << " " << l;  
     
  return 0;  
}  
     
void prompt(char *str, int *i)  
{  
  cout << str;  
  cin >> *i;  
}  
     
void prompt(char *str, double *d)  
{  
  cout << str;  
  cin >> *d;  
}  
     
void prompt(char *str, long *l)  
{  
  cout << str;  
  cin >> *l;  
}
  
    
  








Related examples in the same category

1.Functions differ in number of parametersFunctions differ in number of parameters
2.Overload abs() three waysOverload abs() three ways
3.Overload function: int and longOverload function: int and long
4.Overload function to accept integer or char * argumentOverload function to accept integer or char * argument
5.Overload the min() function.Overload the min() function.
6.Compute area of a rectangle using overloaded functions.Compute area of a rectangle using overloaded functions.
7.Overload function: int and floatOverload function: int and float
8.function overloading between int and string type