Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ptrfuncs.h : http://www.cs.ucsb.edu/~mikec/cs16/assignments/pa6/ptrfuncs.h ptrfu

ID: 3728161 • Letter: P

Question

ptrfuncs.h : http://www.cs.ucsb.edu/~mikec/cs16/assignments/pa6/ptrfuncs.h

ptrfuncs.cpp: http://www.cs.ucsb.edu/~mikec/cs16/assignments/pa6/ptrfuncs.cpp

prtest1.cpp : http://www.cs.ucsb.edu/~mikec/cs16/assignments/pa6/ptrtest1.cpp

1. [50 points] Complete ptrfuncs.cpp to implement the first four functions declared in ptrfuncs.h. All of the functions in ptrfuncs.h involve C++ pointers. Most of them also manipulate a collection of consecutively stored double values - much like a double array. A pointer to the first value provides access Hint/reminder: *p is the same as p[e], and p[i] is the same as *(p i) Begin with this ptrfuncs.cpp skeleton and follow any instructions in that file. For this part, just implement the first four functions double sum (double *values, int n)-find and return the sum of the n values-the pointer holds the address of the first one double *maxPtr (double *values, int n)-find the maximum value, and return a pointer to its address o double "minPtr(double *values, int n) - ditto the minimum value o double valueDiff (double left, double right) find and return the difference between the two double values as left value minus right value Use ptrtest1.cpp to test your implementations. You can compile it and link to your functions, and then run it as follows:

Explanation / Answer

double sum(double *values, int n) {

double s = 0;

for(int i=0; i<n; i++)

s = s + *(values+i);

return s;

}

double *maxPtr(double *values, int n) {

double *max = values;

for(int i=1; i<n; i++)

if(*max < *(values+i))

max = (values+i);

return max;

}

double *minPtr(double *values, int n) {

double *min = values;

for(int i=1; i<n; i++)

if(*min > *(values+i))

min = (values+i);

return min;

}

double valueDiff(double *left, double *right) {

return *(left) - *(right);

}