1/18/09

C++ overloaded function example

C++ overloaded function example in this tuturial we used the c++ property of overloading to use single function for different purposes square rout , addition , multiplication and devision in one single operation

we include cmath library in order to use math functions

The code below marked in red demonstrate how made this sample program


#include
#include
using namespace std ;
double SQUAREROOT_MULTIPLY_SUM_DEVISION( double a){
return sqrt( a);}
double SQUAREROOT_MULTIPLY_SUM_DEVISION( double a , double b){
return a *b ;}
double SQUAREROOT_MULTIPLY_SUM_DEVISION (double a ,double b, double c){
return a + b + c ;}
double SQUAREROOT_MULTIPLY_SUM_DEVISION( double a ,double b, double c , double d){

return a /( b +c +d) ; }
C++ overloaded function example In this tutorial we used the property of overloading to use single function for 4 different purposes Square rout addition multiplication and division


int main (){


cout << " this program used single function to perform square rout , multiplication , addition and devisition in single operation " <<>

double w = SQUAREROOT_MULTIPLY_SUM_DEVISION(4);
cout<< " square root of 4 ="<<>
double x = SQUAREROOT_MULTIPLY_SUM_DEVISION( 12 ,14);
cout << " the sum of 13 and 14 is "<<>
double y = SQUAREROOT_MULTIPLY_SUM_DEVISION( 2 ,3,4);
cout <<" 2 *3*4 = "<<>
double z = SQUAREROOT_MULTIPLY_SUM_DEVISION ( 100, 2,3,5);
cout << " 100 / ( 2 + 3 +5) "<<>
return 0 ;

}

3 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete

leave me messege