1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <iostream>
#include <iomanip>
#include <complex>
using namespace std;
//using std::cout;
//using std::cin;
//using std::endl;
//Definition of the function template amax() starts below:
template <typename T>
T amax( const T array[], const int maxSizeOfArray )
{
T maxValue = 10;//array[0];
/*for(int i = 0; i < maxSizeOfArray; i++)
if (array[i] > maxValue)
maxValue = array[i];
*/
return maxValue;
}
complex<double> complexarray(complex<double> array[],int size)
{
complex<double>carray[3];
carray[0] = array[0];
carray[1] = array[1];
carray[2] = array[2];
double magarray[3];
for (int i=0; i<size; i++)
{
magarray[i] = abs(carray[i]);
}
double maxvalue = magarray[0];
int x = 0;
for (int i = 0; i<size; i++)
{
if (maxvalue<magarray[i])
{
maxvalue = magarray[i];
x= i;
}
}
//double test = 8.2;
return carray[x];
}
//main function begins here.
int main()
{
int a[4] = {92, 764, 906, 658};
double b[3] = {322.72, 874.40, 766.86};
float c[5] = {3, 4, 6, 8, 10};
complex<double>d[3];
d[0] = complex<double>(2.0, 4.0);
d[1] = complex<double>(3.0, 3.0);
d[2] = complex<double>(9.0, 12.0);
cout<< amax<int>(a, 4);
cout<<endl;
cout<< amax<double>(b, 3);
cout<<endl;
cout<< amax<float>(c, 5);
cout<<endl;
cout<<"test" << endl;
cout<< amax<double>(d, 3) << endl;
//cout<< complexarray(d, 3) << endl;
return 0;
}
|