EEN218 Spring 2004, Fifth and Sixth Assignments
Write a user-friendly interactive database program capable of working with
the sample persoanl reocrds files described for the third
and fourth assignments. You may adapt your previous work, but there
are significant changes. You must use linked lists to store the contents of the
data file in memory. You must produce a clear and understandable program
without unnecessarily repeated code.
The program should prompt the user for a command, obey the command,
print a response indicating the outcome, and continue with a
prompt for the next command. The following commands must be
implemented:
- exit: Stop running. Exitting without first saving should
be the way to abandon unwanted changes.
- load filename: Read the database from the indicated file
into memory. You should assume that the file will have exactly the format
described for the third and fourth assignments. The program should respond
with an error message if the file could not be loaded, or a report of the
number of records read.
Example:
> load /data/people-2000.txt
OK, 2000 records read.
- save filename: Save the database as it currently exists
in the program's linked list(s) in a file with the indicated name. You
should write the data in exactly the rigth format, so that a future
"load" command could successfully read the new file.
- first number: (number can be any positive integer)
Print out all details of the first number records in the
database.
Example:
> first 3
Mrs Jane Smithers of 923 SW 100 St #161, Fort Lauderdale, FL 33222, SSN 691517210, DOB 18-07-1980
Mr Nathan Grant of 4979 SW 28 St #3 Miami FL 33123 SSN 285166506, DOB 19-12-1954
Mr Poindexter Abbot of 773 SW 77 St #103 Miami FL 33136, SSN 404940806, DOB 10-07-1953
- last number: (number can be any positive integer)
The same as the "first" command, except that "last 3" would list the
last 3 people in the database, not the first 3.
- find max fieldname operator value:
(max is any integer, fieldname is any of firstname, lastname, state, zip, ssn, etc.,
operator is any of =, < or >, and
value could be anything).
List all the people in the database (up to a maximum of max entries)
that match the given condition.
Example:
> find 5 firstname = Evangelina
1: Mrs Evangelina Maxwell of 777 NE 97 St #138, Fort Lauderdale, FL 33221, SSN 330011892, DOB 17-03-1965
Only 1 match for firstname = Evangelina
> find 3 lastname = Frankenstein
1: Ms Iris Frankenstein of 1365 SW 62 Av, Hallandale FL 33319, SSN 360443664, DOB 04-01-1970
2: Ms Tammy Frankenstein of 2962 SE 171 St, Davie, FL 33511, SSN 270313693, DOB 22-10-1978
3: Miss Zoe Frankenstein of 9641 SW 101 St #21 Hallandale, FL 33318, SSN 520809874, DOB 17-11-1968
3 matches for lastname = Frankenstein, there may be more.
- count fieldname operator value:
The same as "find", except that no maximum number is specified, and
the program should only report the total number of matches.
Example:
> count lastname = Frankenstein
4 records match lastname = Frankenstein
- delete fieldname operator value:
The same as "find", except that the matching records are not
listed, they are instead removed from the database. Remember that you
should only remove the entries from the linked list. Do not modify
the original file unless the user issues the "save" command. You may
include a maximum number as with the "find" command if you prefer to.
Example:
> delete dob < 19380000
21 records deleted, matching dob < 19380000
- Extra Credit: implement the "and" operator to work with the "find", "count", and "delete"
commands, so that for example "delete dob > 19750000 and dob < 19759999" would delete
all entries for people born in 1975.
For the Sixth Assignment
For the sixth assignment, you should add one new command:
- sort fieldname: Sort all the entries in the database
in ascending order, based on the value of the given field. For example,
"sort dob" followed by "first 3" should print out the details of the
three oldest people in the database.
The "sort" command should report the time taken to perform the sorting
operation as accurately (and readably) as is reasonably possible.
For information on making programs time their own operations
look here.
Example:
> sort ssn
It took 1.032 seconds to sort 1000 records.