Object-Oriented Programming
Fall 2017
LAB 2 - Array reversal
You have an array of $n$ entries. $n$ should be a constant integer, as a default set to 20. You need to write 2 loops.
The first should start at entry 0 and end at entry $n-1$, and save the value of the entry number in the array (e.g. A[0]
= 0, A[1]=1, .. A[19]=19). This is for initialization.
The second loop should then read through the array entries and swap the outermost entries, moving inwards
towards the middle with every iteration (e.g. A[0] and A[19] swap values, then A[1] and A[18] swap, until A[9]
and A[10] swap).
All this shall run in a single main() routine. Print outputs to the screen.
Make sure you go through the code development process;
• Design the method/algorithm (plain English, pseudo code, flow chart, etc.)
• Code your algorithm (in C++)
• Test your code; Does your algorithm work to swap each entry? Analyze your output and prove it worked.
• Debug your code; If it did not work properly, ask why (from a high level) did it not work? Is it an algorithmic
or coding error? Use the debugger to identify the root-cause and fix your code.