// 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 MNodes #ifndef ENCODE_CLASS #define ENCODE_CLASS #include #include #include "MNode.h" #include "Codebook.h" #include "DllIterator.h" class Encoder { private: MNode * plaintext; // dll holding each "word" of the message Codebook cb; // dll holding each pair in codebook.txt std::vector code; // holds 4-digit translations of words std::string message; // original string // overwritten by decaped and depunced string 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, do nothing // 2. word is part of expression which is in codebook, combine // node contents and delete extraneous nodes // 3. word is a garble // ******** IMPLEMENT 1 and 2 ********** void checkCodebook(); // removes punctuation from original plaintext message // replaces any ., ?, or ! with the word "halt" // call from main.cpp // ******** THIS METHOD HAS CHANGED ********** void depunc(); // removes uppercase from message // call from main.cpp 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() // for input: I am NOT, I repeat, NOT a cat! // output would be: // i -> am -> not -> i -> repeat -> not -> a -> cat -> void printPlain() const; // prints the encoded message // (ie. the contents of the vector) // with 1 space between each 4-digit code // 2945 9963 3110 2945 3599 3110 8064 0036 void printCode() const; // deletes the node, p, from dll // post condition: dll has one fewer node // used when you must combine words in an expression void erase(MNode * 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") void encode(); // initialize private data members in this class void init(); // empties the dll, RECURSIVELY void makeEmpty(MNode *); // makes a deep copy of the dll void clone(MNode *&); // 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" // ******** THIS METHOD IS NEW ********** std::string & operator[](int i) const; // returns an iterator that references // the 1st position of the dll // returns NULL if dll is empty // ******** THIS METHOD IS NEW ********** DllIterator begin(); // returns an iterator that references the // the last element of the dll // returns NULL if dll is empty // ******** THIS METHOD IS NEW ********** DllIterator end(); // makes a deep copy of the dll // ******** THIS METHOD IS NEW ********** void copy(const Encoder &); private: // you may place any private methods you need here }; #endif // ENCODE_CLASS