Answer» Hello, Looking for a shove in the right direction. Using a header file "example.h" that defines "2 function templates." One that has to read a set of numbers typed at the keyboard into an array of T. The other TEMPLATE RETURNS the smallest value in the array. Then another file main.cpp uses the template on an array of 4 ints and an array of 5 doubles.
I USED this for the part that returns the smallest value:
template T Smallest(T *a, int N) { T min = a[0]; for (int i = 0; i < N; i++) { if (a<min) min = a; } return min; }
How would I do the first part? Reading the standard input into the array in C++? I am still working on main.cpp as WELL. Any helpful input is greatly appreciated. Thanks in advance.Though I have not reached that CHAPTER of templates yet, this http://www.cplusplus.com/doc/tutorial/templates.html might help.
|