You will implement 2 tables, namely students and grades. Some of the design choices are up to you. You can either implement separate classes, implement a template, or implement a generic class for both row types (e.g. storing the attributes in a string array), etc. You will need one or multiple classes for the table and one or multiple classes for the corresponding rows, i.e. each table will internally be represented by a linked list of rows.
The table "students" stores the following attributes: student id, first name, last name.
The table "grades" stores the following attributes: student id, term, year, grade.
Once the program is started, it will print out the promt "tables> " (> is followed by a whitespace):
./a.out
tables>
You will implement the commands "insert", "print", "select", "join" and "quit":
Insert takes 4 or 5 arguments depending on which table will receive the entry. The first parameter designates the table. The following parameters for each of the tables are in the order listed above. Append the entry to the end of the list. You do not need to check for existing entries. Then repeat the prompt.
tables> insert students 5 Mickey Mouse
tables> insert students 2 Papa Smurf
tables> insert grades 1 Spring 2016 B
tables> insert grades 2 Summer 1738 A
tables>
Print takes 1 argument specifying the table to be printed. Print out all the rows of the table on a single line. The individual attributes will be denoted in tuple notation, i.e. each row is enclosed in parenthesis and the individual attributes are separated by commas. The format for students is (id,firstname,lastname) and the format for grades is (id,term,year,grade). Then repeat the prompt.
tables> print students
(5,Mickey,Mouse)(2,Papa,Smurf)
tables> print grades
(1,Spring,2016,B)(2,Summer,1738,A)
tables>
Select takes 3 arguments. The first argument specifies the table, the second argument the attribute name and the third argument determines the value. Print out all matching row using tuple notation. Then repeat the prompt.
tables> select students id 2
(2,Papa,Smurf)
tables> select grades term Summer
(2,Summer,1738,A)
tables>
Join takes no arguments. Join the tables using the following order for the attributes: (id,firstnaem,lastname,term,year,grade). Then repeat the prompt.
tables> join
(2,Papa,Smurf,Summer,1738,A)
tables>
Exit the program
tables> quit
If the command received from the user input is not supported, print out an error message starting with "Error!". (Do not capitalize the entire word "Error")
Example of program execution:
g++ *.cpp
./a.out
tables> insert students 5 Mickey Mouse
tables> insert students 2 Papa Smurf
tables> insert grades 1 Spring 2016 B
tables> insert grades 2 Summer 1738 A
tables> print students
(5,Mickey,Mouse)(2,Papa,Smurf)
tables> print grades
(1,Spring,2016,B)(2,Summer,1738,A)
tables> select students id 2
(2,Papa,Smurf)
tables> select grades term Summer
(2,Summer,1738,A) tables> join
(2,Papa,Smurf,Summer,1738,A)
tables> quit