Homework 6
Arrays of Pointers, Access Tables

Due: Tuesday, December 11, 2012 at 5pm

Outcomes

After successfully completing this assignment, you will be able to...

Before Starting

Review Chapters 6, 7, and 8 in Deitel & Deitel.

Access Tables

In this assignment we'll use multiple arrays (access tables) to refer to a single array of information. For example, consider an array of student records at WPI, where each record consists of a student's name and ID number. You can imagine the Registrar wanting, at different times, to obtain a list of students ordered alphabetically by name, or a list of students ordered by increasing ID number. What we would like to do is come up with a scheme in which the data in the array remains in place, but we have a way of visiting the elements in the array in the desired order. What we'll do for each type of ordering is keep an array of subscripts that correspond to the elements ordered the way we want. For example, given this data in the original array:

array element name ID
[0] HAMEL, GLYNIS 39602
[1] WARD, MATT 4412
[2] HEINEMAN, GEORGE 6074
[3] WILLS, CRAIG 5570
[4] FISLER, KATHI 3964

We would construct this array to provide access to the data in alphabetical order:

array element subscript
[0] 4
[1] 0
[2] 2
[3] 1
[4] 3

The meaning is this: you will find the name closest to the beginning of the alphabet (FISLER, KATHI) at subscript 4 in the original array. The next one in order is at subscript 0 (HAMEL, GLYNIS), and so on. Similarly, to order the original data by increasing ID number, we would construct an array consisting of these values:

array element subscript
[0] 4
[1] 1
[2] 3
[3] 2
[4] 0

By using access tables in this way, we can avoid keeping multiple copies of the original data, which would be wasteful of storage space. And if a change needs to be made to one of the student records, we only have to make the change in one place; we're spared the problem of making sure that multiple copies of the data are updated in exactly the same way.

The Assignment

In this assignment, we'll create an alphabetical access table for names of students enrolled in a course. However, instead of storing subscripts in the access table, we'll store pointers (to the name strings). Here are the declarations you should use for the array that holds the names and the array that holds pointers to the names:
#define MAXSTUDENTS 20
#define MAXSTRING 30

char students[MAXSTUDENTS][MAXSTRING];  // the original list of names
char *alphabetic[MAXSTUDENTS];          // array of pointers to the names
Student names are entered into the students array. After all the names are entered, a sorting routine will be called, and both the original list and the alphabetized list will be displayed. The original list should not be modified by the sorting function. Here is a sample execution:
How many students are enrolled?  5

Enter the names of the students on separate lines:

JENKINS, JOHN
WANG, JIN
SULLIVAN, DANIEL
FISHER, KATHERINE
BELOIT, KIMBERLY

Original Order          Alphabetical Order
------------------      -------------------
JENKINS, JOHN           BELOIT, KIMBERLY
WANG, JIN               FISHER, KATHERINE
SULLIVAN, DANIEL        JENKINS, JOHN
FISHER, KATHERINE       SULLIVAN, DANIEL
BELOIT, KIMBERLY        WANG, JIN

Assumptions and Restrictions

Deliverables

Here is what you should submit for the assignment: Submit your files using web-based turnin.

Grading

This assignment is worth 35 points:

Programs submitted after 5pm on December 11 will be tagged as late, and will be subject to the late homework policy.