C M S C     2 1 4
C o m p u t e r   S c i e n c e   I I
S p r i n g   2 0 0 3


Project #3

Due Thursday, April 3rd, by 11PM

Checklist

Purpose

  1. To obtain more practice with the STL vector class.
  2. To understand and implement a Binary Search Tree.
  3. To implement an iterator for a BST.
  4. To use artificial intelligence to search and backtrack.
  5. To create a parser for separating long strings into individual words.
  6. As always, to have some fun.

Academic Integrity Statement

Please note that *all* programming projects in this course (including this one) are to be done independently or with the assistance of the instructional staff of this course only.

Please review the policies outlined on the class syllabus concerning the use of class computer accounts and concerning the University's Code of Academic Integrity. The instructors of this course will review the programs submitted by students for potential violations of the Code of Academic Integrity and if it is believed that a violation has occurred it will be referred to the Office of Judicial Programs and the Student Honor Council.

Hardcoding is considered a violation of academic integrity

Background

So you have created an Enigma machine that enciphers and deciphers uncrackable messages. Good Job! (If you haven't gotten the Enigma to work, you must get it working before proceeding on this project.) Notice that the output of a deciphered message looks something like:

theterrapinscoresatmidnight

While this is acceptable for most cryptologists, we do not want important people like the president of the college to have to read such a long crunched string. We would ideally like a parser that can divide this sentence into words. This will be the goal of Project 3.

The parser should be fast and accurate. Speed is of the essence which is why we will be implementing our dictionary of words as a Binary Search Tree, allowing us to find the words in the dictionary in O(log(n)) time (assuming a height-balanced tree). Furthermore, accuracy is crucial. We do not want President Mote to receive "The terrapins' core sat midnight.". All of the preceding words are valid English words. We would, however, prefer for the president to read "The terrapin scores at midnight."

Files Provided

In addition to the primary input and primary output, and all of the updated .h files from Project 2, you will find new files. The following files are in the posting account under Projects/P3.

  • Node.h Stores a plaintext character and pointers.
  • Coder.h The header file for Coder.cpp. Updated
  • Enigma.h The header file for Enigma.cpp. Updated
  • Entry.h The header file for Entry.cpp.
  • Bst.h The header file for Bst.cpp.
  • Dictionary.h The header file for Dictionary.cpp.
  • ConstIterator.h The header file for ConstIterator.cpp

Files Submitted

Note: You should submit all the files provided.

  • Node.h and Node.cpp
  • Coder.h and Coder.cpp
  • Enigma.h and Enigma.cpp
  • Entry.h and Entry.cpp
  • Bst.h and Bst.cpp
  • Dictionary.h and Dictionary.cpp
  • Parser.h and Parser.cpp
  • ConstIterator.h and ConstIterator.cpp
  • test files
    • testNode.cpp
    • Added
    • testEntry.cpp
    • testEnigma.cpp
    • Added
    • testCoder.cpp
    • Added
    • testBst.cpp
    • testDictionary.cpp
    • testParser.cpp
    • testConstIterator.cpp
  • myExcept.cpp
    • Has a total of 10 exceptions.
  • Makefile
    • Your makefile, spelled exactly this way (not "makefile" or anything else).

Tasks

Task 1

Make sure your Enigma from project 2 is working correctly
and can encipher and decipher with:

  • wheels rotating
  • letters deleted

If not, fix it before proceeding.

Task 2

There have been a few updates to P2.
Make certain that you have made the changes to

  • Coder.h
  • Coder.cpp
  • Enigma.h
  • Enigma.cpp

Enigma must be working before proceeding because your
output from Enigma will be the input to your parser.

Update testCoder.cpp and testEnigma.cpp.

Task 3

Create Entry.cpp (the nodes in the BST) and Bst.cpp
Create testEntry.cpp and testBst.cpp
Test these thoroughly before proceeding.

Task 4

Create Dictionary.cpp and testDictionary.cpp
It reads from a file: dictionary.txt
Correct file reading functions are expected.
Hardcode the file name that Dictionary reads as "dictionary.txt".
You can test it on your own dictionary file.

Task 5

Create Parser.h, Parser.cpp and testParser.cpp
Parser works on a deciphered message without any blanks
Note: we will still test your Enigma with letters removed
from the wheels but the message you parse will not contain blanks.

New Parser takes the deciphered message, such as "wearehear", and
locates words in the Bst to insert blanks between the words.
Let's assume that the following words are in your dictionary.txt:

  • a
  • are
  • ear
  • he
  • hear
  • we
  • wear

You start looking for the first letter 'w' in your Dictionary.

You find "we" and "wear". Assume you choose "wear". Keep this word until
you have examined the next few words to make certain you are 'reading'
the message correctly. The next letter in the message is 'e'. So in your
Dictionary, you look for the word "e". It is not there, so look for the word
"eh". There is no such word and no word that begins with "eh" so you must
backtrack to the previous word and select a different one, "we" (instead of "wear").
Then begin again with "we" and look for words that begin with "a" - "a" and
"are". If you choose the wrong one, again you will have to backtrack. Continue
to do this until you have only words from your dictionary.txt in your message.
You might have to backtrack through several words to get the message
separated correctly (i.e. containing only words in the Dictionary.)

Comment your Parser code very well, stating what heuristic you
followed to successfully separate the words.

Task 6

Create ConstIterator.cpp and testConstIterator.cpp
This is a constant iterator that is bidirectional
whose purpose it is to walk from a node in the tree to the
next node in the tree, beginning with the node with smallest
value to the node with largest value. It can traverse both
forward (++) and backwards (--).

Hints

  • Output from Enigma's deciphered message will be the input to Parser.
  • No spaces or non-alphabetic characters will appear in input to Parser
  • We will test ConstIterator but your code will pass primary without it.
  • primary.input is very simple. To get full credit, you will need to be able
    to pass secondary.input and other test files.
  • The input file has changed. It now begins with the single character 'e'
    or 'd' on the first line followed by a newline. This tells you whether to
    encipher or decipher. All wheels, keywords and offsets are provided
    also, in addition to the rotations(cogs) and letters deleted from the wheels.
  • Charles Lin's Tutorial on Deleting a Node from a Tree

I/O

  • New input to Enigma has SAME BNF as in P2 except the first
    line contains a single character followed by a newline.
    New input to your Enigma is located at
    • primary.input
    • secondary.input
  • New output from you Enigma is located at
    • primary.output
    • secondary.output
  • Input to your Parser is located at
    • parser.input1
    • parser.input2
  • Output from your Parser is located at
    • parser.output1
    • parser.output2

BNF

The input file, dictionary.txt, will follow this format:

[lines]

The input to your parser will follow this format:

[message][newline]

With the following definitions:

[lines] := [line][lines] | [line]
[line] := [word][newline]
[word] := [letter][word] | [letter]
[letter] := any alpha-character
[newline] := "\n"
[message] := [lcletter][message] | ""
[lcletter] := any lower-case alpha-character

Notes:

[word] represent the word that should be added to the Dictionary object.
All output should be lower-case.



See the class syllabus for policies concerning email
Last Modified: Monday, March 17, 2003
left up down right home

Web Accessibility