1) Write a template function named problem6 that accepts a constant integer valu
ID: 656505 • Letter: 1
Question
1) Write a template function named problem6 that accepts a constant integer
value as its template argument. Remember, the syntax for this is
"template<int N>", where N is then a template parameter. The function itself
accepts an int as its argument and returns true if the argument is divisible
by the template argument and false otherwise.
2) Write a template function named problem7 that accepts iterators to the
beginning and end of a range as the first two arguments and a function as the
third argument. Sort the elements in the range from beginning and up to but
not including end using the function argument instead of the less than
operator.
Explanation / Answer
template <typename T>
bool problem6(T N , int arg)
{ if(arg/N==0)
{return true;}
else return false; }
template <typename T>
bool problem7(T beg , T end, void *func(T[]))
{int i=beg;
T temp=arr[i];
for (i = beg ; i <= end; i++) {
temp=i;
while ( temp > 0 && arr[temp] < array[temp-1]) {
xyz = arr[temp];
array[temp] = array[temp-1];
array[temp-1] = xyz;
temp--;
}
void func(int arr[])
{//enter array
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.