P
R
O
G
R
A
M
M
I
N
G
 
C
O
M
P
E
T
I
T
I
O
N
 

Simple Database

Task #7
Novice/Advanced
7 Points

Task Description
Cheap secondary storage (like hard drives and CD-ROMs) have encouraged the widespread use of computer databases. Databases are used in a wide variety of applications including ecommerce, factory automation, accounting, and company personnel records. Your task is to write a simple storage and query system.

Program Input
The input file consists of a header, a data section, and a query section. The first line of the header contains three integers: the number of data fields, the number of data records, and the number of queries. The second line of the header lists each field name. Field names are separated by commas. The maximum number of fields is nine, the maximum number of data rows or queries is one thousand.
     The data section contains has a single line for each data record. The data field values are separated by commas.
     There is one query per line in the query section of the input file. Each query consists of a field name, an equal sign, and a key value. A very simple example input file is shown below.

5 6 2
LASTNAME, FIRSTNAME, TITLE, DEPARTMENT, SALARY
Carter, Steve, Admin. Assistant, Facilities, 2700
Lin, Kyle, Manager, North America Sales, 4200
Gonzales, Maria, Engineer, Manufacturing Support, 4100
Anderson, Greg, Maintenance Technician, Facilities, 2950
Carter, Linda, Heroine, Customer Relations, 6500
Mudhi, Tariq, Sales Specialist, North America Sales, 3200
LASTNAME = Carter
DEPARTMENT = Manufacturing Support

Program Output
The program must respond to each query by writing a result table to the output file. The table should show all data rows that match the query. The result table must have a column for each data field, and the columns must align left, including the column headings. Each result set must be separated by a blank line. See the results below for examples.

LASTNAME FIRSTNAME TITLE            DEPARTMENT             SALARY
Carter   Steve     Admin. Assistant Facilities             2700
Carter   Linda     Heroine          Customer Relations     6500

LASTNAME FIRSTNAME TITLE            DEPARTMENT             SALARY
Gonzales Maria     Engineer         Manufacturing Support  4100