Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you please verify its correct when you finish because I\'ve posted this mult

ID: 3788986 • Letter: C

Question

Can you please verify its correct when you finish because I've posted this multiple times but I've been getting wrong answers from other people who try it. (PLEASE USE C++ CODE) Thank You.

1. Your main program will use the above class to input a morse code message from a file. Since every codeword is separated by a space, you can 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. Use your program to decode the messages below. The functions morsecode and alphacode are at the very buttom if needed.

Message 1:

Message 2:

Your program should include the following functions :

FOR ADDITIONAL HELP SEE MORSECODE AND ALPHACODE BELOW IF NEEDED

Morsecode:

vector<string> morsecode()

Alphacode:

Explanation / Answer

#include <string>
#include <vector>
#include <iostream>
using namespace std;

class Code
{
public:
    Code();             
    string decode(vector<string> message);            
private:
    vector<string> codewords;           
    vector<char> alpha;                 
    vector<char> alphacode();          
    vector<string> morsecode();        
    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<char> Code::alphacode()
{
      vector<char> temp;
    for (char c='A'; c<='Z'; c++)      
    {  
          temp.push_back(c);
          temp.push_back(' ');              
          temp.push_back('.');              
     }
    return temp;                      
}

vector<string> Code::morsecode()
{                
    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;
}

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


int main()
{
    vector<string> message;
    string temp;
    Code c;
  
    cin >> temp;
  
    while (cin.good())
    {
            message.push_back(temp);
            cin >> temp;
    }
    cout << c.decode(message) << endl;
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote