// Encoder.h // encodes a plaintext message into // 4 digit strings, separated by a single blank // and including no punctuation marks // each period (end of sentence) is replaced // by the word "halt" // stores the code in a dll of TNodes #ifndef ENCODE_CLASS #define ENCODE_CLASS #include #include #include "TNode.h" #include "Bst.h" #include "DllIterator.h" class Encoder { private: TNode * plaintext; Bst cb; std::vector code; std::string message; public: // default constructor // sets private data members to default values Encoder(); // copy constructor // makes a deep copy of the dll Encoder(const Encoder &); // destructor // deletes the dll ~Encoder(); // assignment operator Encoder & operator=(const Encoder &); // inserts the plaintext string into a dll; // creates a dll of message, putting each word/expression in dll // NOTE: this is called AFTER decap() and depunc() // and before calling checkCodebook() bool insert(); // checks strings in dll against codebook dll // if string is not there, there a 3 possibilities // 1. word is plural and singular form is in codebook // 2. word is part of expression which is in codebook // 3. word is a garble // IMPLEMENT 1, 2, and 3 // if you find a word that is not part of an expression // and is not a plural, assume it is a garble and // print out the garble 4-digit code void checkCodebook(); // removes punctuation from original plaintext message // replaces any ., ?, or ! with the word "halt" void depunc(); // removes uppercase from message void decap(); // reads the message AS IS // do not use a method that strips blanks out of the original // I am NOT, I repeat, NOT a cat! // would be read as is with blanks, caps and punctuation. void reader(); // prints the message, AS IS void printMessage() const; // prints the dll after decap() and depunc() void printPlain() const; // prints the encoded message // (ie. the contents of the vector) void printCode() const; // deletes the node, p, from dll // dll has one fewer nodes now // used when you must combine words in an expression void erase(TNode * p); // puts the coded message into a vector // if the dll (plaintext) has 25 nodes // then the vector has 25 cells // (one for each string that is in the message and "codebook") // THIS METHOD HAS CHANGED // decrements "halt" by 7 each time it encodes "halt" // except the 1st time // for example if halt = 1049 then // 1st time encode "halt" as 1049 // 2nd time encode "halt" as 1042 // 3rd time encode "halt" as 1035, etc. void encode(); // initialize data members void init(); // empties the dll, RECURSIVELY void makeEmpty(TNode *); // makes a deep copy of the dll void clone(TNode *&); // brackets operator allows indexing into the dll // "fakes" random access to the ith element of the dll // returns contents of ith element of the dll // if dll looks like: // we -> are -> of -> // then element 2 would be "of" std::string & operator[](int i) const; // returns an iterator that references // the 1st position of the dll // returns NULL if dll is empty DllIterator begin(); // returns an iterator that references the // the last element of the dll // returns NULL if dll is empty DllIterator end(); private: // makes a deep copy of the dll void copy(const Encoder &); // you may place any private methods you need here }; #endif // ENCODE_CLASS