need help finishing and understanding this program

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. You can download the functions morsecode and alphacode.


class Code
{
public:
Code();
Code(vector<int> codewords);
string encode(vector<char> message);
string decode(vector<string> message);
private:
vector<string> codewords;
vector<char> alpha;
vector<char> alphacode();
vector<string> morsecode();
string encode(char x);
char decode(string c);
};
Code::Code()
{
alpha = alphacode();
codewords = morsecode();
}
string Code::decode(vector<string> message)
{
string temp;
for(int i=0; i< message.size(); i++)
{
temp+= decode(message[i]);
}
return temp;
}
vector<string> morsecode()
{ // This function returns a vector containing the morse code
vector<string> 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<char> alphacode()
{// This returns a vector containing the alphabet a-z and " "
vector<char> temp;
for (char c='A'; c<='Z'; c++)
temp.push_back(c);
temp.push_back(' ');
temp.push_back('.');
return temp;
}

char Code::decode(string c)
{
for(int i=0; i <alpha.size(); i++)
{
if(c== codewords[i])
{
return alpha[i];
}
}
}

int main()
{
Code mess1;
Code mess2;
string S;
string J;
vector<string> code1;
}
Please note, that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.

need help ... understanding this program

That implies that you have not written the code that you have posted. The "copy-paste" is a poor way to program.

PS. please use the code tags. They make the posted code easier to read and comment on. See http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.