Databases store records, each consisting of several different types of information. Typically, you might want to search a database for information in any specified field, listing all records that match. In this assignment you will be designing a class to accommodate medication records. You will then be implementing a version of a linked list that holds these records in increasing order with respect to expiration date. The assignment is broken into several pieces.
Part a:
A Date class and a Medication class
1) Write a Date class. It should be able to read dates in the
format mm/dd/yyyy and write them in that format, or with the months spelled
out: April 7, 1988. Use overloaded << and >> operators.
Format will be set by a member function but should apply to all dates.
Your class will also need < and > operators for ordering dates:
10/5/2003 < 3/13/2006.
You may add other appropriate functions.
2) Write a Medication class. The record fields are Name, ID#,
and expiration date. The name may have spaces in it, the ID# is an
integer, and the expiration date is a Date. Overload the <<
and >> operators for input and output, where the output is in exactly the
same form as the input.
ID# name
expiration date
Overload the < and > operators to order medications by expiration
dates.
I will post a sample
input file. (file: meddata.txt) The last medication will
be
0 xx
01/01/1901
Thoroughly test your classes and DO NOT DELETE the test stubs.
Part b.
Getting the link list perfected.
For the time being, forget about the Medication, and work with the
list list example from class. (Yet to come.) Add functions
operator> and operator< to the node class. NodeA > NodeB if the data
in NodeA is bigger than the data in NodeB.
Write a new version of insert for link lists that maintains the list in increasing order. That is, insert can create a new node for the int to be inserted into, find out where that node should go, and properly attach the node to the list.
For example, if the data provided is
3 55 7 2 96 40
then the ordered list at various stages will be
Some things to pay attention to:
Write a test stub that thoroughly tests the class, and after testing,
block off the test stub. DO NOT DELETE IT.
Part c:
A linklist of Medications
Modify the node class and the linklist class so that they work with
Medications as data instead of integers as data. You will have to
#include the Medication class in node.h. Very few other changes need
to be made.
Test this modified linklist class by making minimal modifications to a copy of your earlier test stub for part b. DO NOT DELETE this test stub.
Part d:
The main application.
In a new file, write a main program that
Common cause for crashes - dereferencing the 0 pointer, especially
by going past the end of the list.
Thoroughly test your class. You will probably want lots of output
statements while you are testing your
classes, for example in the constructors and destructors, but this
output should be removed from your final
version. (commenting it out is fine)