Answered step by step
Verified Expert Solution
Question
1 Approved Answer
. 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started