Need help writing one member function in this code

Here is my code so far. I will bold the member function I need help with. If anyone knows what to write it would be greatly appreciated. Here are the instructions.

We will be creating the program which takes a file containing the message in morse code and converts it to the alphabetic message. Your main program will use the below class to input a morse code message from a file. Since every codeword is separated by a space, you can use input the message using cin, and store each codeword as a separate string in a vector. Then submit the vector to the class function decode, and it will return the decoded message. When finished, output the string. You can download the functions morsecode and alphacode. Use your program to decode the messages message 1 and message 2.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

class Code
{
public:
  
  Code();  // Default constructor - loads and uses morse code

  string decode(vector&lt<string> message);  // decodes a message

  vector<string> Sentence_To_Vector(string m);

private:

  vector<string> codewords; // this is a codeword vector parallel to A-Z
  vector<char> alpha; // this is the vector for A-Z

  vector<char>  alphacode(); // function returns vector - A B C etc.

  vector<string>  morsecode(); // function returns vector containing morse code

  char decode(string c); //returns the character for the codeword c.

};

  Code::Code()
{
   alpha = alphacode();
   codewords = morsecode();
}

  string Code::decode(vector<string> message);
{
  
}

  vector<string> Code::Sentence_To_Vector(string m)
{
  vector<string> output;
  int i=0;
  string temp;
  while(m[i] != 'x')
   {
     if (m[i] != '')
     {
        temp+=m[i];
     }
     else
     {
         output.push_back(temp);
         temp="";
     }
    i++;
   }
  output.push_back("x");
  return output;
}




  Code::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;
}



  Code::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[26] ="x";
 return temp;
}

 char Code::decode(string c)
{
  char output;
  for(int i=0; i<codewords.size(); i++)
   {
     if(c== codewords[i])
       output = alpha[i]
   }
  return output;
}
     
int main()
{
  string m = "...---...x";
  Code c;
  vector<string> message=C.Sentence_To_Vector(m);

  cout<< decode(message) << endl;
}

Last edited on
write (no spaces)

[ code ]

Your code

[ /code ]

That won't help your program to work, but your code will look proper in the forums ;-). That way, is easier for us to read your code and review it
Last edited on
That makes the display look much better.
Last edited on
Anyone know what to do by any chance?
I would suggest using a map of morse code "characters" to alphabetical letters. Then you can simply input whatever set of dots/dashes you have and if you find a match, put in that letter. Otherwise they have an invalid letter.
Topic archived. No new replies allowed.