PA6 can be done either in two-people teams or individually. If you are working with a partner, be sure that both partners' names are in a comment at the top of the source code file, and be sure to properly form a group for this project in the submit.cs system.
This assignment is all about practice using pointers. Therefore, please try to solve
the problems using pointer notation only, and not equivalent array notation
(i.e., no There is a program skeleton and three other necessary files this time, and you probably
want a copy of the sample data file from Part 2 as well. Get copies of
ptrfuncs.cpp, ptrfuncs.h,
ptrtest1.cpp, ptrtest2.cpp
and data1.txt from ~cs16/pa6/ and we suggest you store them in
a new directory in your own account at CSIL, specifically ~/cs16/pa6.
You can use the Linux wildcard character cp ~cs16/pa6/* ~/cs16/pa6/ |
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[0] , and
p[i] is the same as *(p + i) .
|
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.double *minPtr(double *values, int n)
- ditto the minimum value.double valueDiff(double *left, double *right)
- find and return the
difference between the two double values as left value minus right value.g++ -o ptrtest1 ptrtest1.cpp ptrfuncs.cpp ./ptrtest1Your results must match our ptrtest1 results exactly.
void printTable(double *values, int n, int perRow)
- print the
values as a neatly-formatted table with the specified number of values per
row, and each value in a field of width 10 showing 2 significant digits.void sortValues(double *first, double *last)
- sort the values
from first
through last
, where these parameters
are pointers into the same dynamic array. Write your own sorting routine,
such as the selection sort procedure presented in Chapter 7 - but remember
you should use pointer notation, not array notation to do it. You may write
helper functions if you want, but they should use pointer notation too.~submit/submit -p 967 ptrfuncs.cppBe sure to wait for the test results. If you score 100/100 and you've followed all of the other rules, then you'll earn full credit.