C++ Function Overloading Overloads two absolute value functions

Description

C++ Function Overloading Overloads two absolute value functions

#include <iostream>
using namespace std;  
#include <iomanip.h>  
int abs(int i);     
float abs(float x); 
void main()//  w  ww  .  j ava 2s .c o  m
{
   int ians;      
   float fans;
   int i = -15;   
   float x = -64.53;
   ians = abs(i); 
   cout << "Integer absolute value of -15 is " << ians << "\n";
   fans = abs(x); 
   cout << "Float absolute value of -64.53 is " << setprecision(2) << fans << "\n";
   return;
}
int abs(int i)    
{
   if (i < 0){  
      return (i * -1); 
   }
   else{  
      return (i);  
   } 
}
float abs(float x)  
{
   if (x < 0.0)
   {  
      return (x * -1.0); 
   } 
   else
   {  
      return (x);  
   }        
}



PreviousNext

Related