Overload function with array type : function overload « Function « C++ Tutorial

Home
C++ Tutorial
1.Language Basics
2.Data Types
3.Operators statements
4.Array
5.Development
6.Exceptions
7.Function
8.Structure
9.Class
10.Operator Overloading
11.Pointer
12.File Stream
13.template
14.STL Introduction
15.string
16.vector
17.list
18.bitset
19.set multiset
20.valarray
21.queue stack
22.deque
23.map multimap
24.STL Algorithms Modifying sequence operations
25.STL Algorithms Non modifying sequence operations
26.STL Algorithms Binary search
27.STL Algorithms Sorting
28.STL Algorithms Merge
29.STL Algorithms Min Max
30.STL Algorithms Iterator
31.STL Algorithms Heap
32.STL Algorithms Helper
C / ANSI-C
C Tutorial
C++
Visual C++ .NET
C++ Tutorial » Function » function overload 
7.12.6.Overload function with array type
#include<iostream.h>
#include<iomanip.h>

int findmax(int intArray[]);
float findmax(float floatArray[]);
double findmax(double doubleArray[]);
int findmin(int intArray[]);
float findmin(float floatArray[]);
double findmin(double doubleArray[]);

main()
{
  int intArray[10]={1,8,4,2,3,0,9,3,5,7};
  float floatArray[10]={145.15,312.3,3163.2,119.13,710.1,315.4,511.2,513.7,319.4,519.2};
  double doubleArray[10]={15.12354323,2.41237763,63.29123876,19.67123863,
   78.34123541,35.44123009,51.21230392,53.40123967,39.80612304,59.11111232};
  cout<<"largest value in the intArray is "<<(findmax(intArray))<<"\n";
  cout<<"largest value in the floatArray is "<<(findmax(floatArray))<<"\n";
  cout<<"largest value in the doubleArray is "<<(findmax(doubleArray))<<"\n";
  cout<<"smallest value in the intArray is "<<(findmin(intArray))<<"\n";
  cout<<"smallest value in the floatArray is "<<(findmin(floatArray))<<"\n";
  cout<<"smallest value in the doubleArray is "<<(findmin(doubleArray))<<"\n";

  return 0;
}
int findmax(int intArray[])
{
   int max=0;
   for(int i=0;i<10;i++)
   {
     if(intArray[i]>max)
        {
          max=intArray[i];
        }
   }
   return max;
}
float findmax(float floatArray[])
{
   float max=0;
   for(int i=0;i<10;i++)
   {
     if(floatArray[i]>max)
        {
          max=floatArray[i];
        }
   }
   return max;
}
double findmax(double doubleArray[])
{
   double max=0;
   for(int i=0;i<10;i++)
   {
     if(doubleArray[i]>max)
        {
          max=doubleArray[i];
        }
   }
   return max;
}
int findmin(int intArray[])
{
   int min=999;
   for(int i=0;i<10;i++)
   {
     if(intArray[i]<min)
        {
          min=intArray[i];
        }
   }
   return min;
}
float findmin(float floatArray[])
{
   float min=9999.9;
   for(int i=0;i<10;i++)
   {
     if(floatArray[i]<min)
        {
          min=floatArray[i];
        }
   }
   return min;
}
double findmin(double doubleArray[])
{
   double min=9999.9;
   for(int i=0;i<10;i++)
   {
     if(doubleArray[i]<min)
        {
          min=doubleArray[i];
        }
   }
   return min;
}
largest value in the intArray is 9
largest value in the floatArray is 3163.2
largest value in the doubleArray is 78.3412
smallest value in the intArray is 0
smallest value in the floatArray is 119.13
smallest value in the doubleArray is 2.41238
7.12.function overload
7.12.1.Overload a function three times.
7.12.2.Overload function by parameter type: int, double and long
7.12.3.Overload functions with two parameters
7.12.4.Overloading functions with difference in number of parameters
7.12.5.Create overloaded print() and println() functions that display various types of data
7.12.6.Overload function with array type
7.12.7.Overloading a function with const reference parameters
7.12.8.Overloading a function with reference parameters
7.12.9.Default Arguments vs. Overloading
7.12.10.Finding the Address of an Overloaded Function
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.