Question: . Make sure the following requirements are met. The program must compile and run. the maxArray function must be a recursive template function. Add a
. Make sure the following requirements are met.
- The program must compile and run.
- the maxArray function must be a recursive template function.
- Add a main function to test the maxArray function so that you have a complete program.
- Test the maxArray function on two arrays of different types.
/*------------------------------------------------------------------------- Program to illustrate the use of a function template to display an array with elements of any type for which << is defined. Output: An array of ints and an array of doubles using display() -------------------------------------------------------------------------*/ #include#include template void display(ElementType array[], int numElements); int main() { double x[] = {1.1, 2.2, 3.3, 4.4, 5.5}; display(x, 5); int num[] = {1, 2, 3, 4}; display (num, 4); std::string s[] = {"aa", "bb", "cc"}; display(s, 3); } /*------------------------------------------------------------------------- Display elements of any type (for which the output operator is defined) stored in an array. Precondition: ElementType is a type parameter. Postcondition: First numElements of array have been output to cout. ------------------------------------------------------------------------*/ template void display(ElementType array[], int numElements) { for (int i = 0; i < numElements; i++) std::cout << array[i] << " "; std::cout << std::endl; } /* 1.1 2.2 3.3 4.4 5.5 1 2 3 4 aa bb cc -------------------------------- Process exited after 0.1019 seconds with return value 0 Press any key to continue . . . */
should be written in c++ code
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
