ABSTRACT

In this problem we sort a database of people. Each person is an object that has two attributes: name and age. The program sorts the people by ages or by names. To test the program, we use the 200 popular given names. The names are randomly ordered by using the Linux command sort with -R. The age of a person is a random number between 1 and 100. The database is a text file containing two columns: age and name. A few lines of the database are shown below:

43 Peter

87 Linda

57 Gregory

61 Larry

5 Eric

19 Dennis

56 Betty

70 Joshua

4 Donald

60 Susan

To test the program, we need to compare the answers of our program against the correct answers. We can use the Linux program sort to generate the correct answers. The correct answers are generated as follows: • sort -n: sort the first column and treat the column as numbers. Without -n, the first

column will be treated as strings and “10” is before “9” because 1 is before 9 in the dictionary. • sort -k 2: sort by the second column. This program uses the same Person structure defined earlier. Another structure is de-

fined to store an array of pointers to Person objects. This structure also has an attribute as the number of pointers in the array. The program needs to implement the follow steps:

4. Sort Person objects by ages. 5. Release memory occupied by the objects. 6. Close opened files.