Description
The purpose of this challenge is to use function templates.
Requirements
- Write a function template that will calculate the average of an array of integers.
template <typename T> double average(T array[], int size) { // calculate and return the average }
- Write a function template, void show(…), that will display the values of an array. Elements will be displayed separated by a single space . Set up the template function similar to Step 1
- Write a specialization for the show() function from Step 2. This version will be strictly for string types. In this function, each element will be displayed one per line.
- In main(), declare three arrays: int idata[10], double ddata[10], string sdata[10].
- Ask the user to fill in data for each of the arrays.
- Show the contents of the int array by calling the show() function
- Show the average of the int aray
- Show the contents of the double array by calling the show() function
- Show the average of the double array
- Show the contents of the string array by calling the show() function. Remember to invoke the specialized version.
Sample main()
int main() { int idata[10]; double ddata[10]; string sdata[10]; /// return 0; }
CATALOG ID: CPP-CHAL00045
Print Requirements