
(Last Revision: 10/08/97)
(last revision was a change to the due dates.)

//////////////////////////////////////////////////
CS 2500 PROGRAMMING ASSIGNMENT #02

LOADING AND PRINTING A DATABASE OF RECORDS
//////////////////////////////////////////////////

=================================================================
DUE DATES:

Oct 3        Program #2 Second Level of the program (don't
	     forget to turn in both source file and test script
	     via e-mail by midnight)
	     
Oct 11       Program #2 second-level program DUE.  (don't forget to
	     turn in both source file and test script via
	     e-mail by midnight)

Oct 18       Program #2 final-level program DUE.  (don't forget to
	     turn in both source file and test script via
	     e-mail by midnight)
=================================================================

As with the last assignment, I want you to be familiar with the
class documents entitled:

programAssignmentRules,
sampleProgramSubmission-level01,
sampleProgramSubmission-level02,
sampleProgramSubmission-level03,
howToMakeTestScript-level01, 
sampleTestScript-level01,
sampleTestScript-level02, and
sampleTestScript-level03

before beginning to do this programming assignment.  You will find
the documents under "CourseDocuments" in the class directory.

The program you write next is going to use an array of records
to implement a database containing information about certain
characters and character-components used in writing Japanese.

This may sound complicated, but actually what we are going to
do is pretty simple, and there is absolutely no need for you to
learn anything about Japanese writing.

If you are programming in C you can use an array of structs
instead of an array of records.

In the most simple way of saying it, you are going to write a
program that inputs a series of commands of this form:

-----------------------------------------------------------------
+:k:3:np:16:str3:three::floor,ceiling$
+:k:60:p:37:str9:page:head:one,drop,shellfish,eye,animal legs$
p
+:nk:0:p:26:str1::drop:drop$
p
+:k:30:np:24:str5:nightbreak::sun,floor$
#
-----------------------------------------------------------------

and produces a corresponding output, like this:

-----------------------------------------------------------------
##################################
+:k:3:np:16:str3:three::floor,ceiling$
An add command has just been done.
##################################
##################################
+:k:60:p:37:str9:page:head:one,drop,shellfish,eye,animal legs$
An add command has just been done.
##################################
##################################
p
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
isAkanji:     k
kanjiSerNum:  3
isAprimitive: np
pageNum:      16
numStrokes:   str3
KanMEANINGS:  three
PrmMEANINGS:  NONE
ComMEANINGS:  floor,ceiling
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
isAkanji:     k
kanjiSerNum:  60
isAprimitive: p
pageNum:      37
numStrokes:   str9
KanMEANINGS:  page
PrmMEANINGS:  head
ComMEANINGS:  one,drop,shellfish,eye,animal legs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
A print command has just been done.
##################################
##################################
+:nk:0:p:26:str1::drop:drop$
An add command has just been done.
##################################
##################################
p
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
isAkanji:     k
kanjiSerNum:  3
isAprimitive: np
pageNum:      16
numStrokes:   str3
KanMEANINGS:  three
PrmMEANINGS:  NONE
ComMEANINGS:  floor,ceiling
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
isAkanji:     k
kanjiSerNum:  60
isAprimitive: p
pageNum:      37
numStrokes:   str9
KanMEANINGS:  page
PrmMEANINGS:  head
ComMEANINGS:  one,drop,shellfish,eye,animal legs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
isAkanji:     nk
kanjiSerNum:  0
isAprimitive: p
pageNum:      26
numStrokes:   str1
KanMEANINGS:  NONE
PrmMEANINGS:  drop
ComMEANINGS:  drop
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
A print command has just been done.
##################################
##################################
+:k:30:np:24:str5:nightbreak::sun,floor$
An add command has just been done.
##################################
##################################
#
All Done.
##################################
-----------------------------------------------------------------

The INPUT

The commands that start with + are commands to add a record to
the database.  The rest of the line is the information that has
to go into the record.  The : character is used to separate
fields, and the $ character is used to mark the end of the
information.

The command p means "print the records that are now in the
database".

There is one other command in the example: # means "stop".

The program you write must be able to process *any* set of
inputs that has the *form* of the example given above.

Your program must read from standard input.  Files of prepared
input can be read in by using Unix redirection:

a.out < sample1.in

You may assume that each command input is completely contained
on one line.

If you wish, you can write the program so it is able to process
commands that span more than one line, but as I indicated, you
do not have to do that.

Another thing you can do if you want to is to write the program
so it performs commands like this:

?:floor,ceiling$

The meaning of this command is "find all records in which floor
or ceiling is contained in the set of component meanings, and
print out those records".

The OUTPUT

All writes done by the program must be done to standard output.

If you look carefully at the output you will see that each
command that was input is echoed to the output.  At the end of
the execution of each command, a message is printed out telling
what kind of command it was.  The outputs coming from
successive commands are separated with rows of pound-signs like
this: ##################################.  That makes it pretty
easy to find and check the output corresponding to each input.

In the case of the + command, there is no other output
written.  The stop command just prints a small message and
terminates the program.  The output of the p command can be
quite extensive, but it just consists of a series of displays
of the individual records, separated by rows of carats like
this: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^.  Each record is
displayed neatly, with the fields in the same order in which
they appear in a + command.

I expect your outputs to have the same form that I've indicated
in the example, and in this discussion.

In addition to what it writes to standard output, the + command
must store the information internally in a list of records.
The structure of that list will be discussed in the next
section.

DATA STRUCTURES

Basically what you need to do for this program is to use an
array of records to store the information that you are reading
in when you process the + command.  The first record you add is
placed in the first slot in the array, the second in the
second, and so on.

SOMTHING TO HELP YOU GET STARTED

You can start your program with the file shell.p.  These files
contain useful data type definitions and string operations.

(There is also a C version of shell.p called shell.c.  It is
another machine translation, and still "needs work".  If you
are thinking of using shell.c, see me during office hours.)

EVERYTHING ELSE

Let's talk about the rest in class.
