- 分享
- 0
- 人气
- 0
- 主题
- 11
- 帖子
- 1855
- UID
- 144857
- 积分
- 1584
- 阅读权限
- 19
- 注册时间
- 2008-5-27
- 最后登录
- 2016-3-21
- 在线时间
- 5837 小时
|
之前叫我们做 Crossword puzzle,8x8 的 othello,然后 text compressor。
现在的 part 1, 给你看吧
TCS1011 Data Structures and Algorithms
Trimester 3, Session 2008/2009
Faculty of Information Technology
Multimedia University
ASSIGNMENT
ADT for Relational Database Table
1. Title
Implement an ADT for a relational database table using C++.
2. Deadline
To be submitted via email to workjudge@gmail.com by the milestone deadlines set in lecture plan.
3. Grouping
To be done individually.
4. Objective
The objective of this assignment is to test the skill of students in creating a table ADT using the
C++ programming language. The table ADT must be able to support the use of SQL-like
commands to create tables, modify data and query data. The use of STL is not allowed for this
assignment.
5. Milestone 1
a. Introduction
For this milestone, create a C++ program which can read and execute INSERT and
SELECT commands from a text file for a table called Menu. The relation schema of Menu is
Menu( id, name, description, price)
as shown in the table below. The Menu table can contain up to a maximum of 100 tuples. The
domain of each attribute is either character string of 1 to 40 characters or number in the range from
-999999.99 to 999999.99.
Attribute Domain
id string (4)
name string (15)
description string (40)
price number
Note:
string(n) means a character string with a maximum of n characters.
number means a number from -999999.99 to 999999.99.
Using an example to illustrate the requirements, let's assume the text file “menu.sql”
contains the following commands and your C++ program has the name “database.exe”.
// menu.sql
INSERT INTO menu (id, name, description, price)
VALUES (P001, “Dinner Plate”, “Side order and 3 pieces of chicken”, 9.20);
INSERT INTO menu (id, name, description, price)
VALUES (P002, “Lunch Plate”, “Side order and 2 pieces of chicken”, 7.80);
INSERT INTO menu (id, name, description, price)
VALUES (S003, “Potato Snack”, “100g of potato slices”, 3.00);
INSERT INTO menu (id, name, description, price)
VALUES (B004, “Family Bucket”, “Drinks, side order and 9 pcs of chicken”,
25.00);
SELECT * FROM menu;
Executing your program with the command
prompt> database menu.sql
your program should displays the following result on screen.
MENU
----------------------------------------------------------------------------------
| ID | NAME | DESCRIPTION | PRICE |
----------------------------------------------------------------------------------
| P001 | Dinner Plate | Side order and 3 pieces of chicken | 9.20 |
| P002 | Lunch Plate | Side order and 2 pieces of chicken | 7.80 |
| S003 | Potato Snack | 100g of potato slices | 3.00 |
| B004 | Family Bucket | Drinks, side order and 9 pcs of chicken | 25.00 |
---------------------------------------------------------------------------------
4 rows selected.
The width of each column displayed is the maximum width specified for each corresponding
attribute. In the case of Menu, the widths are 4+2 characters, 15+2 characters, 40+2 characters and
10+2 characters for id, name, description and price respectively.
If there are no data in the table Menu, your program should display
MENU
0 rows selected.
The sequence of INSERT statements and SELECT statements can be of any order. For
example, the sequence of statements can start with four INSERT statements followed by two
SELECT statements, and then followed by another 2 INSERT statements Your program should
support any combination of INSERT and SELECT statements.
b. INSERT Statement
In addition to the example your program must be able to support NULL data for the
INSERT statement except for the first attribute (id) which is the primary key. The following
statement is a valid INSERT statement for your program.
INSERT INTO menu (id, name, description, price)
VALUES (001, “Breakfast Meal”, NULL, NULL);
*Note: NULL's should be displayed as blanks when a SELECT statement is executed.
You can assume that the INSERT statement always has the four attributes (id, name, description
and price) in a correct sequence.
c. SELECT Statement
The SELECT statement for this milestone is a greatly simplified version of standard SQL.
Your program only needs to support the * wild card or a sequence of attribute names for indicating
the attributes to display, . For example,
SELECT id, price, name FROM menu;
SELECT name FROM menu;
are valid statements to be supported while
SELECT id, price + 3 FROM menu;
SELECT name, name, id FROM menu;
are invalid statements which should be rejected.
For the WHERE part your program only needs to support one condition which contains
only one operator, the = (equal) operator. For example,
SELECT price, name
FROM menu
WHERE name = “Potato Snack”;
SELECT name, id
FROM menu
WHERE price = 5.00;
are valid statements to be supported while
SELECT id, price
FROM menu
WHERE price > 5.00;
SELECT name, id
FROM menu
WHERE ( name = “Potato Snack” ) AND ( id = “S003” );
are invalid statements which should be rejected.
The syntax of the SELECT syntax is summarized in the table below.
Part of the SELECT statement Supported command structure
SELECT * or a sequence of attribute names
FROM this is always menu as there is only one table
WHERE supports only the = operator for only one condition.
7. Evaluation Criteria
Milestone 1 Mark Sheet
Max Marks
1. Features
a. SELECT statement is supported 1
b. INSERT statement is supported 1
TOTAL 2
8. Submission instruction
a. Create a folder in the following format:
LECTURESECTION_M1_FULLNAME
b. Place ONLY your files of formats .cpp and .h in the folder. DO NOT place your
.exe file in the folder.
c. Zip your folder with the 7Zip program.
2. Send the zipped file to workjudge@gmail.com before the deadline. The email title should
be “TCS1011_TC101_M1_Submission”
a. Late submission will be detected through the system clock.
3. Additional Information
a. 50% of the allocated marks will be deducted if the submission instructions are not
followed.
b. You are expected to make sure that your code is easily readable. Pay attention to
indentation.
c. In your .cpp and .h files, insert appropriate comments to help others to understand
your code.
d. For ALL your .cpp and .h files, insert the following info at the header: |
|