The goals of this lab include doing the specific tasks outlined below
and understanding general concepts behind the tasks.
In this lab, we'll introduce you to some techniques for maintaining a
database. You'll enhance an existing database program for CD's by
adding search and delete capabilities to a database program.
Lab 5 table of contents
For this lab you'll first write member functions to Search the database
using different keys. The program already can read a database file from
disk and print the database. From here you will write member functions
to search for different keys and delete a CD from the database.
The structure of the program is similar to the usepix.cc
program from a previous lab. The file usedb.cc stores the client
program that manipulates CD databases. The class CDlist
implements a CD database (by storing a list of CDs in a vector).
Information about one CD is stored in a struct CDinfo. The
relationship between these parts is diagrammed below with member
functions and some data shown.
Creating and Maintaining Databases are important applications in the real
world. For example, keeping records for all the students at Duke
University is an arduous task if it all had to be done on paper. Databases
give people the ability to look up individual records, add new records, or
to categorize records so we know what students have in common (i.e. a
database of students could list all the sophomores who were originally
born in New Jersey.) In this lab, we will be adding functionality to a
database that maintains a list of CDs for a CD store (by the way, CD
superstore in Brightleaf was started by Duke graduates.)
Information is stored in the file as shown below in the general format
For example:
In this section of the lab you'll copy files and then compile and run
the CD database program.
First change into your cps100e subdirectory (type pwd
to verify where you are). Create a
lab5 subdirectory by typing mkdir lab5 and change
into this subdirectory (be sure to check that you're
in the lab5 subdirectory.) Now copy the files for the lab
(don't forget the . when copying).
You should see the files listed below (these are links to the files in
case you use Netscape, and for users outside of Duke).
Be sure you're in the lab5 subdirectory, and check to see that
all files are there (type ls). Next type
This shows that you've linked to ola's data directory.
Then, from an xterm window (at the prompt [1] ola@teer8% or
similar) compile the first version of the program by typing: make
usedb.
Note that you type make usedb since the function main
is in the usedb.cc file.
This should compile several files and link them together
with the library libtapestry.a. Now run the program by typing:
usedb at the prompt. When you run the program, you can "read" a
CD list file and print out the database. When you load a file, you will
want to use data/smallcd.dat first so that you can test your
program on a small database first. After you get the program working,
then you can try it out on the larger file data/cd.dat Test out
the Print option by printing the database you read in.
In this part of the lab you'll implement changes to the CDlist class
(in cdlist.cc) and to the usedb.cc program to take advantages of these
changes.
You'll need to add functionality as shown in the table below.
Databases
CD Database
There are two files you will use to test your program. One stores
information for about 20 CDs the other stores information for about
3,000 CDs. It's probably a good idea to test your program with the
smaller file.
ID number : price : group name : CD title
100122 : 14.98 : Happy Mondays : Yes, Please
100126 : 14.98 : 10,000 Maniacs : Our Time In Eden
100127 : 11.98 : Skid Row : B-Side Ourselves
100160 : 14.98 : R.E.M. : Murmur
100164 : 14.98 : R.E.M. : Reckoning
102767 : 14.98 : Nine Inch Nails : Downward Spiral, The
106149 : 14.98 : Snoop Doggy Dogg : Murder Was The Case
115586 : 14.98 : Smashing Pumpkins : Siamese Dream
Compiling/Running usedb
ln -s ~ola/cps100e/data data
To link (not copy) a data directory. There's no reason to copy the
files (unless you want to), so you can access them by linking to the
data directory. The data directory stores lots of data files (including
Shakespeare's plays and CD database files.)
Type ls -l data. You should see
something that looks like similar to the following:
Modifications of the Program:
| Additional Functionality | Change in usedb.cc | Change in cdlist.h/cdlist.cc |
|---|---|---|
| search for title | [no change] | implement TitleSearch() |
| search for artist | DoArtist() | implement ArtistSearch() |
| delete a CD | DoDelete() | implement Delete() |
| delete a group's CDs | DoDeleteGroup() | ??? |
| add a new CD to database | DoAdd() | call Add() [no change] |
You will need to modify the CDlist::TitleSearch member function in cdlist.cc to implement the search. You should do this in two steps
if (myList[k].title.Contains(name)to check that name is contained in the k-th entry of myList.
If the title is a match, you should add the CD to the parameter match which stores a list of all the matching CDs. This list is printed in usedb.cc.
Implement the ArtistSearch() member function. This function is similar to the search for title that you implemented above but looks for artist matches. You'll need to implement the DoGroup function in usedb.cc too.
You will now implement the DoDelete function in usedb.cc and the Delete() member function in the CDList class.
To Delete a record from the Database, you will need to
Finally we are going to delete every CD made by a particular group that you (the user enter). Here are some hints:
submit100e lab5.N README usedb.cc cdlist.cc cdlist.h
You can enter the files in any order.
Remember that every assignment must have a README file submitted with it (please use all capital letters). Include your name, the date, and an estimate of how long you worked on the assignment in the README file. You must also include a list of names of all those people with whom you collaborated on the assignment.
You also must turn in the inlab questions either by turning in the sheet during lab or by submitting the answers with your README.