C++ Function Overloading Outputs three different types of data

Description

C++ Function Overloading Outputs three different types of data

#include <iostream>
using namespace std;
#include <iomanip.h>
void output(char []);
void output(int i);
void output(float x);
void main()/*  w  w  w  .j  a  va 2  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;
}



PreviousNext

Related