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

#include <iostream> #include <string> //needs to use the string functions like t

ID: 3635489 • Letter: #

Question

#include <iostream>
#include <string> //needs to use the string functions like toUpper, gets
#include<cctype> //use for character arrays
using namespace std;
//FUNCTION: main
int main()
{
//create an array MORSE with 40 rows and 7 columns
//it contains the morse codes for alphabets and numbers
char MORSE[40][7]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---",
"-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-",
"..-","...-",".--","-..-","-.--","--..",".----","..---","...--",
"....-",".....","-....","--...","---..","----.","-----"," ","--..--",".-.-.-","..--.."};
////declare a charcter array "in" with 100 size
char in[100];

//character array, stores all the alphabets and numbers run 0 to 9, and symbols
char EnglishAlphabet[40]={'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','1','2','3','4','5','6',
'7','8','9','0',' ',',','.','?'};

//variables for the iterators
int i=0,j,k;
cout<<"Enter a string: ";

//read the string into array "in"
gets(in);
cout<<endl;

//loop repeats till the last character in the string "in"
while(in[i]!='')
//repeats the "for loop" 40 times because the are 40 characters in EnglishAlphabet array
{for(j=0;j<40;j++)
//compares the each character with "in" array to "EnglishAlphabet" array
{if(toupper(in[i])==EnglishAlphabet[j])
//if true enter to the loop
{for(k=0;k<strlen(MORSE[j]);k++)
//display the Morse code for the given string
cout<<MORSE[j][k];
cout<<" "; //espacio entre cada letra traducida
}
}
i++; //updare i, adding 1
}

cout<<endl<<endl;
system("pause");
return 0;
}

Explanation / Answer

Hi, here is the code. I deleted all the comments and commented only those parts that I've added. The main Idea here is to create the output stream that will write your data to file. here is the code #include #include #include #include //we need this to work with files using namespace std; //FUNCTION: main int main() { char MORSE[40][7]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---", "-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-", "..-","...-",".--","-..-","-.--","--..",".----","..---","...--", "....-",".....","-....","--...","---..","----.","-----"," ","--..--",".-.-.-","..--.."}; char in[100]; char EnglishAlphabet[40]={'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','1','2','3','4','5','6', '7','8','9','0',' ',',','.','?'}; int i=0,j,k; cout