Answer to Question #201352 in C++ for Arjun

Question #201352

Q1: Write a function template that takes a single type parameter (T) and accepts four function arguments: an array of T, a start index, a stop index (inclusive), and an optional initial value. The function returns the sum of all the array elements in the specified range and the initial value. Use the default constructor of T for the default initial value.



1
Expert's answer
2021-06-01T03:00:17-0400
#include <iostream>


using namespace std;
template <class T>
T sumArr(T arr[], T start, T stop, T init)
{
    T sum=0;
    for(T i=start;i<=stop;i++){
        sum=sum+arr[i];
    }
    sumArr<T>();{
    init=5;
}
    return sum;
}


int main()
{
    


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog