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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include <iostream>
#include <iomanip>
using namespace std;
const int size = 10;
int get_smallest(int ,int );
double get_smallest(double ,int );
template <class T>
void get_array_data(T arrayname[], int size)
{
for(int i = 0; i < size;i++)
{
cin >> arrayname[i];
}
}
template <class T>
T iterate_sum(T arrayname[], int size = 10)
{
}
template <class T>
T recur_sum(T arrayname[], int size = 10)
{
}
template <class T>
void print_data(T arrayname[])
{
int *smallest = NULL;
cout << setiosflags(ios::left) << "Printing Array: ";
for(int i = 0; i < 10; i++)
{
cout << arrayname[i] << " ";
}
cout << endl;
cout << setiosflags(ios::left) << "Smallest Value: " << resetiosflags << setiosflags(ios::right) << get_smallest(arrayname,10); //RETURNS ADDRESS HERE!! I NEED VALUE!!!!
}
int main()
{
//declare and initialize arrays
int i_array[size] = {0};
double d_array[size] = {0.0};
//prompt the user to enter data, read data and print results
cout<<"Enter 10 integer values on a line, each separated by a space\n";
get_array_data(i_array,size);
print_data(i_array);
cout<<endl;
cout<<"\nEnter 10 double values on a line, each separated by a space\n";
get_array_data(d_array,size);
print_data(d_array);
system("PAUSE");
return 0;
}
int get_smallest(int arrayname[],int size)
{
int smallest = *(arrayname);
cout << smallest << endl;
for(int i =0; i < size; i++)
{
if (*(arrayname + i) < smallest)
{
smallest = *(arrayname + i);
}
}
cout << smallest << endl;
return smallest;
}
double get_smallest(double arrayname[],int size)
{
double smallest = *(arrayname);
for(int i =0; i < size; i++)
{
if (*(arrayname + i) < smallest)
{
*(arrayname + i) = smallest;
}
}
return smallest;
}
|