i need help in these questions. please help me . COMP 2010 Function Template Hom
ID: 3701700 • Letter: I
Question
i need help in these questions. please help me .
COMP 2010 Function Template HomeWO Due: April 6th (F), before the start of class Name: 1. Programming: Write a template function to calculate the sum for all elements in an array of numerical numbers (e.g, int, double). The function should take the array as an argument and work for any size of array. It returns the sum of the array. Use const parameters when necessary. You only need to show the template function here, but you should write a driver to test your function.Explanation / Answer
Question 1:
int arraySum(int* a)
{
int i = 0, sum = 0;
while(a[i] != NULL)
{
sum += a[i];
i++;
}
return sum;
}
double arraySum(double* a)
{
int i = 0;
double sum = 0;
while(a[i] != NULL)
{
sum += a[i];
i++;
}
return sum;
}
/* The above code performs the array sum for the given array*/
Question 2 and Question 3 are not complete as they do not have enough information for answering them. The sample code to be referenced is not given.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.