(E) Array operations

Goal: I will learn how to use array type of C++ by using pointers. I will also learn the basics of pointer arithmetics.

Instructions: Retrieve the code template: template/09/arrays/ -> student/09/arrays/.

Implement the functions defined in the file array_operations.hh to the file array_operations.cpp. Since the purpose of the assignment is to practice using pointers, you must not write operator [] in the file array_operations.cpp. Instead, process arrays only via pointers.

Again, the given main program, main.cpp includes some testing for the functions to be implemented and some examples on operations handling arrays. The automated tests do not test the main function, and thus, you can add more covering tests when needed.

When using the unmodified main function, the program should work as:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 3 6 9
9
9
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 3 6 9
9 6 3 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Tips for completing the assignment:

  • Study first the array operations written in the main function. Especially printing the content of an array by using pointers can give an idea of how to implement the required functions. (Example use of STL’s sort algorithm is written only because it is not considered elsewhere in the material.)

A+ presents the exercise submission form here.