Array Functions
In this exercise, you’ll be creating a small collection of functions that could help you with working on arrays.
Download
arrayFunctions.c
,
or copy it into your current directory on a CSE system by running
$ cp /web/cs1511/17s2/week05/files/arrayFunctions.c .
Start by downloading the file called arrayFunctions.c. You will need to modify this file and implement the functions.
Some unit tests have been provided in the main file. You should add your own tests to help make sure your code works properly.
Some of these functions read through an array and return some information about the array but do not change the array in any way. These functions are
arrayMax
; which returns the maximum value in the array,arrayMin
; which returns the minimum value in the array,arrayAverage
; which returns the average value in the array, andarraySum
; which returns the sum of all values in the array.
Some other functions change the array values or have an effect outside the program. We say that these functions have side effects as they do something other than just return a value. These functions are
arrayAdd
; which adds a value to every element in the array,arrayScale
; which multiplies every value in array by the same value, andscanArray
; which reads in values from input and stores them in the arrayshowArray
; which shows an array on the screen in the style[1, 2, 3, 4, 5, 6]
copyArray
; which copies one array into another
To run some simple automated tests:
$ 1511 autotest arrayFunctions
To run Styl-o-matic:
$ 1511 stylomatic arrayFunctions.c Looks good!
You’ll get advice if you need to make changes to your code.
Submit your work with the give command, like so:
$ give cs1511 wk05_arrayFunctions
Or, if you are working from home, upload the relevant file(s) to the wk05_arrayFunctions activity on Give Online.