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

Morse code translator. Our EPSII Morse code message in file ‘HW4_Morse.txt’ cons

ID: 3676987 • Letter: M

Question

Morse code translator. Our EPSII Morse code message in file ‘HW4_Morse.txt’ consists of using ‘.’ for a dot, and ‘-‘ for a dash. White spaces are used to separate letters, and words are separated by ‘/’.
Here are your tasks for this homework:
1. Open the file named ‘HW4_Morse.txt’ for reading. The file HW4_Morse.txt contains the morse code of:( - .... . / ... - .- - ..- - . / .-- .- ... / .- / -. --- - .- -... .-.. . / .--. .-. . -.-. ..- .-. ... --- .-. / --- ..-. / - .... . / . ... - .- -... .-.. .. ... .... -- . -. - / -.-. .-.. .- ..- ... . / .- -. -.. / ..-. .-. . . / . -..- . .-. -.-. .. ... . / -.-. .-.. .- ..- ... . / --- ..-. / - .... . / ..-. .. .-. ... - / .- -- . -. -.. -- . -. - / - --- / - .... . / ..- -. .. - . -.. / ... - .- - . ... / -.-. --- -. ... - .. - ..- - .. --- -.)
a. Translate the Morse code in that file into a message in the English language.
b. Display the English message on the console.
c. Write the translated message to a file named ‘message.txt’. After writing the file, close the file. The contents of this file should be in English.
2. Now open the file ‘message.txt’ for reading.
a. Read the English text from the file, and translate each letter in the text into Morse code.
b. Write the code, letter by letter, to a new file called ‘message2.txt’ and to the console.
c. When the last letter in the text has been translated and written in Morse code, close the output file.
3. To ensure your program ran correctly, open ‘message2.txt’ and ‘HW4_Morse.txt’ and, by eye, check that the contents are exactly the same.

This is what i have so far:

#include
#include
#include
#include
#include **I need to remove this library but still make the program work***

using namespace std;
void convert_to_morse2(string);
void morse_out(string);

void convert_to_morse(char *);
void morse(char *);

int main()
{
    ofstream fout;
    fout.open("message.txt");
    ifstream morse;     // Read the data
    morse.open("HW4_Morse.txt");
    if (morse.fail()){   // If the open fails, report
        cerr << "File open failed" << endl;
        return 1;

    }
                       // Read every row

    while (!morse.eof()) {
    ifstream morse;     // Read the data
    morse.open("HW4_Morse.txt");
// Declares a structure of 2 parts - Character and string.
struct Code{
ifstream morse;
char letter;
string morse1;
morse >> morse1;
// Array of the structure Code.
Code[] ={
{ 'A', ".- "   },{ 'B', "-... " },{ 'C', "-.-. " },
{ 'D', "-.. " },{ 'E', ". "    },{ 'F', "..-. " },
{ 'G', "--. " },{ 'H', ".... " },{ 'I', ".. "   },
{ 'J', ".--- " },{ 'K', "-.- ", },{ 'L', ".-.. " },
{ 'M', "-- "   },{ 'N', "-. "   },{ 'O', "--- ", },
{ 'P', ".--." },{ 'Q', "--.- " },{ 'R', ".-. " },
{ 'S', "... " },{ 'T', "- "    },{ 'U', "..- " },
{ 'V', "...- " },{ 'W', ".-- " },{ 'X', "-..- " },
{ 'Y', "-.-- " },{ 'Z', "--.. " },{ '0', "-----" },
{ '1', ".----" },{ '2', "..---" },{ '3', "...--" },
{ '4', "....-" },{ '5', "....." },{ '6', "-...." },
{ '7', "--..." },{ '8', "---.." },{ '9', "----." },
{ '?', "..--.. " },{ '!', "-.-.-- "},{ '$', "...-..- "}
};
morse.eof();
    }

char str[100];
string text;


cout << "Enter morse code to convert to a string: "<< fout;

//getline(, text);
//convert_to_morse2(text);


//void convert_to_morse2(string s);
{
int i, j;
;


for ( i = 0; i < s.length(); i++ )
{

  for ( j = 0; j < 38; j++ )
  {
   // Convert characters in s to uppercase before checking for them
   if ( toupper(s[i]) == convert[j].letter )
   {
    letter_out(convert[j].letter);
    break;
   }
  }
}

cout << " ";
}
}
void convert(string str)
{
int lcv;
char ch;
ofstream fout;

for (lcv = 0; lcv != str.length(); lcv++) // keep going until the end (0x00) is reached
{
  ch = str[lcv];
  cout << ch<< fout; // Display on screen;


}
}

Explanation / Answer

    cout<<output<<endl;

    ifstream file;

    file.open(“message.txt”,ios::in);

    file>>output;

    file.close();

    file.open(“message.txt”, ios::out);

    msg=file.read();

    cout<< engtomol (msg,morseCode)<<endl;

    file.close();  

string convertToEnglish(string morse, string const morseCode[])

{

    string output = "";

    string currentLetter = "";

    istringstream ss(morse);

   

    size_t const characters = 26;

   

    while(ss >> currentLetter)

    {

        size_t index = 0;

        while(currentLetter != morseCode[index] && index < characters)

      {

            ++index; //increment here so we don't have to decrement after the loop like if we put in the condition

        }

       

        output += 'A' + index;

    }

  

return output;

}

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