Write a program which will be used to format tables. Name the
program xxtab
(where xx is your starting
number). The program will have following parameters:
xxtab [-n] table_description formatted_table
-
n
Each text file contains definition for only one table. Table
consists of individual cells which are written line by line.
Every that line is started with tag <TR>
.
Each line can contain definitions of individual cells. These
definitions are started by tag <TH>
or <TD>
.
First (<TH>
) have one additional functionality
-- it centers contents of cells in both horizontal and vertical
direction.
Characters '+', '|' a '-' will be used for drawing of borders when formatting a table. There must be at least one space between the vertical border and text in the cells.
Any number of immediately following spaces, tabulators and end of lines in the input file will be interpreted as a single space. Spaces surrounding format tags are ignored.
Special way must be used for writing characters
'<
', '>
' and '&
':
Character | Transcription |
---|---|
< |
< |
> |
> |
& |
& |
Let's look at a small example for better understanding:
Table description | Formatted table |
<TR><TH>Year<TH>Income per head <TR><TD>1987<TD>3 <TR><TD>1988<TD>3.5 <TR><TD>1989<TD>3.2 |
+------------------------+ | Year | Income per head | |------+-----------------| | 1987 | 3 | |------+-----------------| | 1988 | 3.5 | |------+-----------------| | 1989 | 3.2 | +------------------------+ |
Note: Notice that several spaces between words "per" and "head" were substituted by a single space.
Following tasks must be solved in the order in which they are presented. In case you do not solve task with smaller number one with higher number will not be evaluated.
ALIGN
which controls aligning of cell contents can be used with
tags <TD>
and <TH>
.
Value of the attribute may be one of following: left |
aligning to the left |
right |
aligning to the right |
center |
centering |
Example:
Table description | Formatted table |
<TR><TH>foo<TH ALIGN=RIGHT>bar <TR><TD ALIGN=CENTER>fooa<TD ALIGN=LEFT>bara <TR><TD>foob<TD>barb <TR><TD>abrakadabra<TD ALIGN=LEFT>zig-zag |
+-----------------------+ | foo | bar | |-------------+---------| | fooa | bara | |-------------+---------| | foob | barb | |-------------+---------| | abrakadabra | zig-zag | +-----------------------+ |
COLSPAN
and ROWSPAN
can be used with tags <TD>
and <TH>
. A positive integer can be
assigned to this attributes, that controls how many cells
will be joined in to one cell in horizontal or vertical
direction. Example:
Table description | Formatted table |
<TR><TH ROWSPAN=2>Year<TH COLSPAN=2>Sales <TR> <TH>Product A<TH>Product B <TR><TD>1994 <TD>4 600 <TD>2 100 <TR><TD>1995 <TD>4 900 <TD>1 900 <TR><TD>1996 <TD>5 750 <TD>3 160 |
+------------------------------+ | | Sales | | Year |-----------------------| | | Product A | Product B | |------+-----------+-----------| | 1994 | 4 600 | 2 100 | |------+-----------+-----------| | 1995 | 4 900 | 1 900 | |------+-----------+-----------| | 1996 | 5 750 | 3 160 | +------------------------------+ |
Note: Do not forget, that tag <TH>
is used for specifying a cell that is centered also in
vertical direction.
A line can be broken at the place of space character between words. In case that there is no suitable space, breaking can occur at the place of character '-'. The error message will be shown onto screen in case that there is no way to break text in cells into several lines to fit the table into desired width.
Example:
Table description |
<TR><TH>Name<TH>Symbol<TH>Definition <TR><TD>meter<TD>m <TD>The meter is the unit of length; it is equal to distance which light overcome in 1/299 792 458 seconds in vacuum. <TR><TD>kilogram<TD>kg<TD>The kilogram is the unit of mass; it is equal to the mass of the international prototype of kilogram (a cylinder of platinum-iridium). |
Formatted table |
1 2 3 4 5 6 7 01234567890123456789012345678901234567890123456789012345678901234567890123456789 +------------------------------------------------------------------------------+ | Name | Symbol | Definition | +----------+--------+----------------------------------------------------------+ | meter | m | The meter is the unit of length; it is equal to | | | | distance which light overcome in 1/299 792 458 seconds | | | | in vacuum. | +----------+--------+----------------------------------------------------------+ | kilogram | kg | The kilogram is the unit of mass; it is equal to the | | | | mass of the international prototype of kilogram (a | | | | cylinder of platinum-iridium). | +------------------------------------------------------------------------------+ |
Note: Ruler above the table is printed just for your better orientation and for emphasizing that the table does not spread beyond the specified length of line (default 80 characters). Ruler is not part of a formatted table.
VALIGN
which controls vertical alignment of
cell contents can be used with tags <TD>
and <TH>
. It can be one of following
values: top |
aligning to top |
bottom |
aligning to bottom |
middle |
center in vertical direction |
Example:
Table description |
<TR><TH>Name<TH>Symbol<TH>Definition <TR><TD VALIGN=BOTTOM>meter<TD VALIGN=MIDDLE ALIGN=RIGHT>m <TD ALIGN=CENTER>The meter is the unit of length; it is equal to distance which light overcome in 1/299 792 458 seconds in vacuum. <TR><TD VALIGN=MIDDLE>kilogram<TD>kg <TD ALIGN=RIGHT>The kilogram is the unit of mass; it is equal to the mass of the international prototype of kilogram (a cylinder of platinum-iridium). |
Formatted table |
1 2 3 4 5 6 7 01234567890123456789012345678901234567890123456789012345678901234567890123456789 +------------------------------------------------------------------------------+ | Name | Symbol | Definition | +----------+--------+----------------------------------------------------------+ | | | The meter is the unit of length; it is equal to | | | m | distance which light overcome in 1/299 792 458 seconds | | meter | | in vacuum. | +----------+--------+----------------------------------------------------------+ | | kg | The kilogram is the unit of mass; it is equal to the | | kilogram | | mass of the international prototype of kilogram (a | | | | cylinder of platinum-iridium). | +------------------------------------------------------------------------------+ |
Tags and attributes are case insensitive.
Your program and all its modules should be stored in the
directory C:\ICP
. Name the modules in such way that
the two first letters of its name are your starting number.
Write your starting number, list of all used modules and list of task which are solved in your program as a comment at the beginning of the program.
There are several files with extension tbl
in the
directory C:\ICP
. These files contain description of
several tables and you can use them for testing purposes.
Permitted aid is English vocabulary, books which describe programming language, its environment (IDE) and standard libraries. You must not use books with description of various methods, algorithms and data structures.
You can get total of 100 points. 60 out of them are used for evaluating functionality, 30 for evaluating efficiency (smart and fast algorithms, sophisticated data structures). Last ten points are used for documentation (description of algorithm, comments, naming convention, neat way of writing code).
Task | Maximal no. of points assigned for functionality |
---|---|
1 | 20 |
2 | 5 |
3 | 10 |
4 | 15 |
5 | 10 |