CS 12 - Lab 2

In this lab you will write a program that uses pointers to access the different values in an array. You should read section 5.7 starting on page 327 in the textbook before coming to lab.

The program

Write a program that deals with an array of 10 integers. The program should first declare the array, then ask the user to enter 10 integers, storing them into the array. It should then give the user 3 options:

If the user selects an option other than Quit, the appropriate operations should be performed, then the options should be given again. Once the user selects Quit, the program should stop.

Specifics

When you declare the array, you can use the subscript operator([]). After that, however, you are not allowed to use the subscript operator. All array manipulations must be performed using pointers and pointer arithmetic.

Following is a sample run of the program:

This program will use pointers to manipulate an integer array of size 10.

First, please enter the integer values.
Please enter integer 0: 5
Please enter integer 1: 10
Please enter integer 2: 15
Please enter integer 3: 20
Please enter integer 4: 25
Please enter integer 5: 0
Please enter integer 6: -10
Please enter integer 7: -20
Please enter integer 8: -30
Please enter integer 9: -40

Please select from the following options:

   R) Reverse the array and print the new array contents
   E) Print out all of the values stored at the even positions in the array
   Q) Quit

Choice: R

The array has been reversed.  The new contents are:

-40 -30 -20 -10 0 25 20 15 10 5

Please select from the following options:

   R) Reverse the array and print the new array contents
   E) Print out all of the values stored at the even positions in the array
   Q) Quit

Choice: E

The contents of the even positions are:

-40 -20 0 20 10

Please select from the following options:

   R) Reverse the array and print the new array contents
   E) Print out all of the values stored at the even positions in the array
   Q) Quit

Choice: Q

Grading

When you have finished the program, your TA will grade it. To receive full credit, your TA will check all of the following: