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

For this lab you are required to create a class called \" CMorseConvert \" that

ID: 3855142 • Letter: F

Question

For this lab you are required to create a class called "CMorseConvert" that converts a Text string into Morse Code (kind of). The class will not convert the text to dashes and dots but to the words "dash" and "dot".

As an example if the class is given the text string "1" the output would be "dot dash dash dash dash".

Or if the class is given the text string "123" the output would be "dot dash dash dash dash dot dot dash dash dash dot dot dot dash dash".

The CMorseConvert class will need to load the file "codes.dat" (which is already here, you just need to open it and read it in) with the mappings of the letters and numbers to the Morse Code. Here is a partial output of the "codes.dat" file:

A,.-

B,-...

C,-.-.

D,-..

E,.

The class needs to contain just one public function (you can have more but only one will be tested):

string Text2Morse(const string sText)

You can check your conversions using a real Morse Code Translator

I don't have access to codes.dat but you do not need it to write this code.

#include
using namespace std;

int main() {

/* Type your code here. */

return 0;
}

Explanation / Answer


#include <stdio.h>
#include <string.h>
FILE *fr;
char*
while ( fgets ( line, sizeof line, fr ) != NULL )
{
char *pos;
if ((pos=strchr(line, ' ')) != NULL){
*pos = '';
}
printf("%s ",line);
  
char *p = line;
while (strstr(p,stringToBeSearched) != NULL )
{
if(p){
total++;
printf ("First occurrence of string "test" in "%s" is"
" "%s" ",line, p);
}else{
printf("string not found " );
}
p++;
}
printf("%d Total occurences ",total);
}
void readFile(){
  
int isFileValid = 0;
char fileName[50] = {''};
  
while(isFileValid != 1 ){
printf("Enter input file name : ");
scanf("%s",&fileName);
  
fr = fopen (fileName,"rt");
  
if(fr == NULL ){
printf("%s File not found. ",fileName);
}else{
isFileValid = 1;
}
}
  
int total = 0;
char line[50] = {''};
char stringToBeSearched[50] = {''};
  
printf("Enter string which need to be searhced");
scanf("%s",&stringToBeSearched);
printf("Entered search string %s ",stringToBeSearched);
  
char str[25],str1[100];
int j=0;
int i=0;
for(;i<=strlen(stringToBeSearched);i++)
{
switch(toupper(stringToBeSearched[i]))
{
case 'A':
str1[j++]='.';
str1[j]='.';
break;

case 'b':
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j]='.';
break;

case 'c':
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j]='.';
break;

case 'D':
str1[j++]='.';
str1[j++]='.';
str1[j]='.';
break;

case 'E':
str1[j]='.';
break;

case 'F':
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j]='.';
break;

case 'G':
str1[j++]='.';
str1[j++]='.';
str1[j]='.';
break;

case 'H':
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j]='.';
break;

case 'I':
str1[j++]='.';
str1[j]='.';
break;

case 'J':
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j]='.';
break;

case 'K':
str1[j++]='.';
str1[j++]='.';
str1[j]='.';
break;

case 'L':
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j]='.';
break;

case 'M':
str1[j++]='-';
str1[j]='-';
break;

case 'N':
str1[j++]='-';
str1[j]='.';
break;

case 'O':
str1[j++]='-';
str1[j++]='-';
str1[j]='.';
break;

case 'P':
str1[j++]='.';
str1[j++]='-';
str1[j++]='-';
str1[j]='.';
break;

case 'Q':
str1[j++]='-';
str1[j++]='-';
str1[j++]='.';
str1[j]='.';
break;

case 'R':
str1[j++]='.';
str1[j++]='-';
str1[j]='.';
break;

case 'S':
str1[j++]='.';
str1[j++]='.';
str1[j]='.';
break;

case 'T':
str1[j]='-';
break;

case 'U':
str1[j++]='.';
str1[j++]='.';
str1[j]='.';
break;

case 'V':
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j]='-';
break;

case 'W':
str1[j++]='.';
str1[j++]='-';
str1[j]='-';
break;

case 'X':
str1[j++]='-';
str1[j++]='.';
str1[j++]='.';
str1[j]='-';
break;

case 'y':
str1[j++]='-';
str1[j++]='.';
str1[j++]='-';
str1[j]='.';
break;

case 'Z':
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j]='.';
break;

case '0':
str1[j++]='-';
str1[j++]='-';
str1[j++]='-';
str1[j++]='-';
str1[j]='-';
break;

case '1':
str1[j++]='.';
str1[j++]='.';
str1[j++]='-';
str1[j++]='-';
str1[j]='-';
break;

case '2':
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j]='.';
break;

case '3':
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j++]='-';
str1[j]='.';
break;

case '4':
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j]='-';
break;

case '5':
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j]='.';
break;

case '6':
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j]='-';
break;

case '7':
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j]='-';
break;

case '8':
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j++]='.';
str1[j]='-';
break;

case '9':
str1[j++]='-';
str1[j++]='-';
str1[j++]='-';
str1[j++]='-';
str1[j]='.';
break;
}
j++;
}
str1[j-1]='';
puts(str1);
}
int main (){
  
readFile();
  
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