Programming Assignment 3: Database
Contents
Overview
In this PA, you will create a database. You will get to choose what kind of data your database will store. However, there is a set of specifications that your database and program must adhere to (see below).
For example, suppose I decided to make a Rolodex. I will store the following attributes about each contact:
- First name
- Last name
- Phone number
- Address
- Business
- Birthday
Each attribute of a contact be saved to its own line in the database file, so each contact will have a total of seven lines associated with it.
The program will allow me to search on any field. The program will also provide the ability to count the number of entries with a field matching a given value for any field.
Here's an example of me running it.
$ rolodex contacts.db ============================================================== Welcome to the Digital Rolodex! ============================================================== Database "contacts.db" does not exist; it will be created on exit. Please select an option: [a]dd contact, [r]emove contact, [u]pdate contact, [s]elect contacts, [c]ount contacts, or [q]uit: a Please enter the following information about the contact you'd like to add: First name: Bob Last name: Smith Phone #: 555-555-5555 Email: bsmith@mail.com Address: 1 Main St., Boston, MA Business: Acme Electronics Birthday: Jan. 1, 1980 Contact added. Please select an option: [a]dd contact, [r]emove contact, [u]pdate contact, [s]elect contacts, [c]ount contacts, or [q]uit: s Please enter the field you'd like to match on ([f]irst name, [l]ast name, [p]hone #, [e]mail, [a]ddress, [b]usiness, b[i]rthday: l Please enter the value you'd like to match: Smith 1 contact(s) found: Bob Smith Acme Electronics 1 Main St., Boston, MA 555-555-5555, bsmith@mail.com Birthday: Jan. 1, 1980 Please select an option: [a]dd contact, [r]emove contact, [u]pdate contact, [s]elect contacts, [c]ount contacts, or [q]uit: q Saving database to "contacts.db". Now exiting. Bye!
The program saved the database of contacts to contacts.db (which was provided as a command line argument when running the program). I only added one contact, and here's what contacts.db looks like:
Bob Smith 555-555-5555 bsmith@mail.com 1 Main St., Boston, MA Acme Electronics Jan. 1, 1980
If I run the program again and provide the already existing contacts.db database file, the program will load the contents in, so our contact will be available. Here's another run of the program where we add an additional contact to the existing database:
$ rolodex contacts.db ============================================================== Welcome to the Digital Rolodex! ============================================================== Database "contacts.db" exists; loading now. This will be updated on exit. Please select an option: [a]dd contact, [r]emove contact, [u]pdate contact, [s]elect contacts, [c]ount contacts, or [q]uit: a Please enter the following information about the contact you'd like to add: First name: Jane Last name: Smith Phone #: 222-222-2222 Email: jsmith@mail.com Address: 10 Pine St., Boston, MA Business: IRS Birthday: Feb. 1, 1978 Contact added. Please select an option: [a]dd contact, [r]emove contact, [u]pdate contact, [s]elect contacts, [c]ount contacts, or [q]uit: s Please enter the field you'd like to match on ([f]irst name, [l]ast name, [p]hone #, [e]mail, [a]ddress, [b]usiness, b[i]rthday: l Please enter the value you'd like to match: Smith 2 contact(s) found: Bob Smith Acme Electronics 1 Main St., Boston, MA 555-555-5555, bsmith@mail.com Birthday: Jan. 1, 1980 Jane Smith IRS 10 Pine St., Boston, MA 222-222-2222, jsmith@mail.com Birthday: Feb. 1, 1978 Please select an option: [a]dd contact, [r]emove contact, [u]pdate contact, [s]elect contacts, [c]ount contacts, or [q]uit: c Please enter the field you'd like to match on ([f]irst name, [l]ast name, [p]hone #, [e]mail, [a]ddress, [b]usiness, b[i]rthday: b Please enter the value you'd like to match: IRS 1 contact(s) matched business = IRS. Please select an option: [a]dd contact, [r]emove contact, [u]pdate contact, [s]elect contacts, [c]ount contacts, or [q]uit: q Saving database to "contacts.db". Now exiting. Bye!
This updates the contacts.db file to the following:
Bob Smith 555-555-5555 bsmith@mail.com 1 Main St., Boston, MA Acme Electronics Jan. 1, 1980 Jane Smith 222-222-2222 jsmith@mail.com 10 Pine St., Boston, MA IRS Feb. 1, 1978
This example is meant to serve as just that, and example. Your database does not need to work exactly like this. However, it does need to meet all of the specifications laid out below.
(Back to top)Specifications
Your completed submission must meet the following requirements:
- you must have your database idea approved by me at least two weeks before the assignment is due (April 10th)
- (10pts) the code is well formatted (correct indentation)
- (5pts) the code has a header with the student's name, date, a description of the program, how many hours you spent on it, and lists who the student sought help from (see below)
- (10pts) comments are included to explain the code
- (10pts) the code is clean and efficient
- (20pts) the program compiles
- (20pts) the program runs smoothly: it doesn't crash, it is clear what information the program is asking for from the user, and the behavior of the program is as expected based on the given inputs
- (25 pts) the following operations are implemented and make sense with
the theme of the database:
- load a database from a given file (doesn't need to be explicit if the filename is provided as a command line argument)
- save the database in memory to a given file (doesn't need to be explicit if the filename is provided as a command line argument)
- add an entry
- remove an entry
- update an existing entry
- select entries that match some condition
- at least one aggregation operation (e.g., sum over a numeric field or count the number of matching entries)
- each entry in the database includes at least four pieces of information
- a struct is used to represent a database entry
- a class is used to encapsulate operations over the database
- uses well designed functions/methods as needed and uses pass-by-reference and pass-by-value appropriately
- is wholly of your own design and programming (i.e., don't work with others—that's cheating, and don't copy code from other sources—that's plagiarism) (Back to top)
Submissions
Submit your .cpp file here.
(Back to top)