Question: In this homework assignment, you are going to write 2 programs to encode and decode messages using codes such as Morse code . NOTE :
In this homework assignment, you are going to write 2 programs to encode and decode messages using codes such as Morse code. NOTE : You will be writing two programs. Both programs will use the class Code. One program will use the class to encode a message. The second will use the code to decode the message.
Our software will support codes that consist of symbols followed by a blank space. For example, in a message if an A appears, it will be replace by ".- ". The trailing space indicates the end of the codeword for that character. (NOTE: We will only be using the characters A-Z. Morse code words are separated by a space, so the message "cat" would be -.-. .- - x where x indicates the end of message. Note that spaces between words are denoted by 7 dots ".......". You can assume that encoded messages end with a lowercase x (which means STOP). When converting a message from text to code, a period "." should be converted to an x.)
Requirements
Your program should include the following class :
class Code { public: Code(); // Default constructor - loads and uses morse code Code(vector codewords); // constructor loading customized code string encode(vector message); // encodes a message consisting of A-Z string decode(vector message); // decodes a message private: vector codewords; // this is a codeword vector parallel to A-Z vector alpha; // this is the vector A-Z vector alphacode(); // function builds the vector alpha - A B C etc. vector morsecode(); // function the vector codewords containing morse code string encode(char x); //returns the codeword for the character x char decode(string c); //returns the character for the codeword c. }; Code::Code(){ alpha = alphacode(); codewords = morsecode(); } vector Code::morsecode() { vector temp(28); temp[0] =".-"; temp[1] ="-..."; temp[2] ="-.-."; temp[3] ="-.."; temp[4] ="."; temp[5] ="..-."; temp[6] ="--."; temp[7] ="...."; temp[8] =".."; temp[9] =".---"; temp[10] ="-.-"; temp[11] =".-.."; temp[12] ="--"; temp[13] ="-."; temp[14] ="---"; temp[15] =".--."; temp[16] ="--.--"; temp[17] =".-."; temp[18] ="..."; temp[19] ="-"; temp[20] ="..-"; temp[21] ="...-"; temp[22] =".--"; temp[23] ="-..-"; temp[24] ="-.--"; temp[25] ="--.."; temp[26] ="......."; temp[27] ="x";
return temp; } vector Code::alphacode() { vector temp; for (char c='A'; c<='Z'; c++) temp.push_back(c); temp.push_back(' '); temp.push_back('.');
return temp; }
You will need to submit your programs that test both encode and decode.. The first (encode) will input an alphabetic message from a file, and use the class to build the morse code string, and then output the string. The second (decode) will input a morse code string from a file and use the classto build the decoded string, and then output the string.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
