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

Hello! I need some help solving this problem. I need to develope a code that hel

ID: 3676328 • Letter: H

Question

Hello! I need some help solving this problem. I need to develope a code that helps do this homework problem. I am having problems with opening the text file and manipulating the text file in order to translate the text. I am also only allowed to use the following inputs: #include #include #include #include and usingnamespace std;

THIS IS C++ CODING

Engineering Problem Solving II Spring 2016 Homework #4 Due March 11,2016 a 5:00 pm Morse code, named after artist and inventor Samuel F. B. Morse (1791-1872), was often used when one dusty sheriff needed to inform another dusty sheriff that the bad guys were coming to town. The code is presently used by many, including Ham radio operators, and the airlines industry (when modern radio communications fail - it's true!). The code consists of dots and dashes. 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 7" Here are your tasks for this homework: 1. Open the file named 'HW4 Morse.txt' for reading. 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. 4. Submit your source code (*.cpp) to the class's ICON site dropbox by 5:00PM, March 11, 2016. Hint: Recall from Lecture Notes 4 (slide 22) and the textbook (pp. 67-68), that cin can be used as cin.get(ch1) to get a single character from the input and store it in the character variable called ch1. You can use the .get() function with an ifstream variable to read a single character from a file in the same manner.

Explanation / Answer

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


   string convertMorseToText(char c)
   {
   string txt = "abcdefghijklmnopqrstuvwqyz";
   string morseArr[] = {".-","-...","-.-.","-..", ".", "..-.", "--.",
                   "....", "..", ".---", "-.-", ".-..", "--",
               "-.", "---", ".--.", "--.-", ".-.", "...", "-",
               "..-", "...-", ".--", "-..-", "-.--", "--.."};
   int index = morseArr.find(c);
   if(index!=-1)
return txt[index];
else
return " ";
   }

int main()
{
   string kod;
   ifstream morsefile ("HW4_Morse.txt");
   if (morsefile.is_open())
   {
   while ( getline (morsefile,kod) )
   {
       string text="";
           for(int i=0; i<kod.length(); i++)
           {
       text += convertMorseToText(kod[i]);
           }
           cout << text << endl;
   }
   myfile.close();
   }else{
       cout << "Unable to open file";
   }
return 0;
}

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