Outputs three different types of data with overloaded function. - C++ Function

C++ examples for Function:Function Overload

Description

Outputs three different types of data with overloaded function.

Demo Code

#include <iostream>
using namespace std;
#include <iomanip>
void output(char []);
void output(int i);
void output(float x);
void main()/* w  w w .  ja  va2  s .c  o m*/
{
   char name[] = "this is a test!";
   int ivalue = 2;
   float fvalue = 9.4321;
   output(name);  
   output(ivalue);
   output(fvalue);
   return;
}
void output(char name[])
{
   cout << setw(30) << name << "\n";
   return;
}
void output(int ivalue)
{
   cout << setw(5) << ivalue << "\n";
   // printed integer within a width of five spaces.
   return;
}
void output(float fvalue)
{
   cout << setprecision(2) << fvalue << "\n";
   // Limited the floating-point value to two decimal places.
   return;
}

Result


Related Tutorials