Question
Design two function templates as follows: 1. The first function template will be used to sort arrays of different data types in either descending or
Design two function templates as follows:
1. The first function template will be used to sort arrays of different data types in either descending or ascending order. This function template is required to have the following parameters: o An array of a generic type o An integer representing the size of the array o A character representing the order of sorting (i.e., ascending or descending). This last argument (i.e., the order of sorting) is required to be a default argument. The default order of sorting should be ascending.
2. The second function template will be used to display an array. This function template is required to have two parameters: o An array of a generic type o An integer representing the size of the array Design the main program that can be used to test both function templates above. The program should create the two dynamic arrays: one will store integer values, while the other array will store character values. The size of both arrays will be determined at run time (i.e. entered by the user). The requested order of sorting (i.e., ascending or descending) for each array will also be obtained from the user at run time. The values stored in both arrays will be generated by the random numbers generator (i.e., srand() and rand() library functions could be used). Please note that the random characters' ASCII values should be in the range from 33 to 126, while the random integer numbers should be in the range from 1 to 100. The program will call both templates to sort arrays in the requested order and display both arrays before and after sorting. It is required to include all necessary error checking which includes the code to prevent any "garbage input" from the user as well as the code to prevent the memory allocation error.
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