EEN218 Spring 2005, Database Assignment

Write a simple database program. When started, it should read a file of data about people into memory, using a Flexible Array (An array that can grow as needed, as discussed interminably in class), then allow the user to ask some very simple queries, printing out the answers in a user-friendly form. A sample session, which you should use as guidance, is shown at the end of this file.

I have provided a number of sample files which are accessible to everyone on rabbit. They contain data for some randomly generated (i.e. not real) people. The first has only 500 people in it, and the last has 10,000. Your program should be able to work for a file with any number of people in it, so long as it follows this same format.

The following are links to the sample data files. You can see the format just by following one of the links and looking at the file. Of course, I'll also explain it here, so there is no room for misunderstanding. 500 people, 1000 people, 1500 people, 2000 people, 2500 people, 3000 people, 3500 people, 4000 people, 4500 people, 5000 people, 6000 people, 7000 people, 8000 people, 9000 people, 10000 people.
The files contain one complete line for each person. Each line contains 9 individual items of data. The individual items of data are written as strings or numbers; they never contain spaces, and are separated by spaces. There are no incomplete lines or otherwise bad data.

The data items on each line of the files are:
  1. Social security number, in the standard U.S. format: 9 digits.
  2. Date of birth, as an 8 digit number, e.g. 20040219 means 19th February 2004.
  3. Title, e.g. Ms, Mr, Mrs.
  4. First Name
  5. Last (family) name
  6. Street address
  7. City
  8. State (standard two letter abbreviation)
  9. Zip Code (5 digits)
As stated before, none of these items in the file will contain spaces, spaces are used only as separators. However, real names and addresses do contain spaces. In the file, the underline character "_" is used whenever a space is really wanted, so the street address "123 Cat St" appears in the file as "123_Cat_St", and the city Fort Lauderdale appears as "Fort_Lauderdale". When you have got the basics of your program working, you should make it replace the underlines in these strings with spaces. Do not edit the file to do this, it would become unreadable. Make your program do the replacement on the strings in memory at a reasonable time.

These are the first few lines from the 2000 people file:
691517210 19800718 Mrs Jane Smithers 923_SW_100_St_#161 Fort_Lauderdale FL 33222
285166506 19541219 Mr Nathan Grant 4979_SW_28_St_#3 Miami FL 33123
404940806 19530710 Mr Poindexter Abbot 773_SW_77_St_#103 Miami FL 33136
410396813 19771226 Mr Darrell Hudson 3383_SE_100_Av Miami FL 33132
858522815 19710729 Miss Rose Nitrogen 1762_SE_141_St_#227 Miami FL 33141
699956805 19770131 Mrs Clarissa Clegg 2146_SE_72_Av_#297 Fort_Lauderdale FL 33215
451012113 19830716 Dr Zoe McCoy 4812_NE_122_Av_#127 Davie FL 33511
If programming on rabbit, you do not need to download the files; they are accessible to everyone with an account. Just use "/data/people-1500.txt" (for example) as a filename in your program. If you are working on a different computer, the easiest way to download the files is probably to follow the links given above and paste them into a file.

Requirements

After reading in the data file, your program should enter a loop, allowing the user to enter a query (or say "exit") and answering it. There is no need to save the data by writing it back to the file at the end, as none of these queries will cause a change.

Your program must be able to answer the following questions, but the way the user has to type the questions is up to you.
  1. A "help" command that lists the possible queries and very briefly explains what they mean. It must be made absolutely obvious what the user must type to receive this help.
  2. An "exit" command is also required.
  3. Find and print the details of the oldest person in the database.
  4. Find and print the details of the youngest person in the database.
  5. Find and print the details of the person with a given social security number (selected by the user).
  6. Sort the database entries (ascending by date of birth).
  7. Count the number of people born in a year (the year is selected by the user).
  8. List the details of all people who live in a particular city.
  9. Given the first or last name of a person, find and print the details of all people in the database with matching names.

Sample Session

Your program does not have to look exactly like this when running; this is meant for guidance, so you know what is intended. The responses printed here are not correct for the given file, just samples.
database file: /data/people-2000.txt
[2000 entries read OK]
Type help for help
Query: help
These are the commands understood by this system:
  help       print this list
  exit       stop running the program
  youngest   find youngest peron in database
  oldest     find oldest peron in database
  ssn SSSSS  find person with social security number SSSSS
  born YYYY  count all people born in year YYYY
  city CCCC  list all people living in city CCCC
  name NNN   list all people with first or last name NNN
  sort       sort the records (age order), then print just the first few.

Query: youngest
The youngest known person is
   Mr Maurice Hastings
   of 1234 SW 44th St, Miami, FL 33333
   born 22 April 1987
   SSN 467282273

Query: ssn 123456789
Nobody has SSN 123456789

Query: ssn 467282273
   Mr Maurice Hastings
   of 1234 SW 44th St, Miami, FL 33333
   born 22 April 1987
   SSN 467282273

Query: name hastings
   Mr Maurice Hastings
   of 1234 SW 44th St, Miami, FL 33333
   born 22 April 1987
   SSN 467282273

   Mr Jimbo Hastings
   of 1234 SW 44th St, Miami, FL 33333
   born 29 May 1958
   SSN 983945335

   Dr Hastings O'Connell
   of 666 Smell Road, Palm Beach, FL 33445
   born 8 July 1932
   SSN 723829472

Query: name grzxxzp
Nobody has that name

Query: exit
$

Get the idea?