Define the template function
template <typename T1, typename T2>
int count_exact(T1 a[], T2 size, T1 find)
that returns the number of times find occurs in 623262. Ex: count_exact(arr, 6, 2) would return 3 because 2 appears three times in arr. Test your function in your main() using an array of ints, and an array of strings. Please comment explaining which operations the types T1 and T2 need to support for your code to work.
Solved 1 Answer
See More Answers for FREE
Enhance your learning with StudyX
Receive support from our dedicated community users and experts
See up to 20 answers per week for free
Experience reliable customer service
#include<iostream> using namespace std; //Template Function count_exact template <typename T1, typename T2> int count_exact(T1 a[], T2 size, T1 find) {     int count = 0;     for(T2 i=0; i<size; i++)     {         if(a[i]==find)             count++;     }     return count; } //main function int main() {     //Test using an array of ints     int a[] = {6, 2, 3, 2, 6, 2};     int n = count_exact<int, int>(a, 6, 2);     cout<<"The number of times find occurs: "<< n <<endl;     //Test using an array of strings     string b[] = {"6", "2", "3", "2", "6", "2"};     n = count_exact<string, int>(b, 6, "2");     cout<<"The number of times find occurs: "<< n <<endl;     return 0; }     Output: The number of times find occurs: 3 The number of times find occurs: 3   In the code, comparison operation where  the array elements with the find  (i.e. a[i]==find) need to support, they should be comparable, otherwise the code will not work. For example, if T1 is a cstring then the code will not work. T2 size should countable,  in the code, increment operation (i.e. i++) need to support, otherwise the code will not work.  For example, if T2 is a string or bool then the code will not work.   N.B.  Whether you face any problem then share with me in the comment section, I'll happy to help you. ...