Question: I am writing a program to convert text into morsecode and vice versa. I keep getting an issue at compilation time. Im not sure how

I am writing a program to convert text into morsecode and vice versa. I keep getting an issue at compilation time. Im not sure how to explain the If someone could compile the program and tell me what the issue is, that would be great and fix it, thatd be great.

Update: the error I kept getting was undefined symbols for 64 x86 architecture.

Programing language is c++

MorseMain.cpp

#include

#include "TransInfo.h"

int main()

{

string uI; //stores user input

//Initialize our maps/translations

TransInfo::initTranslation();

//Reads for input from user until eof is detected

while(getline(cin, uI))

{

//Figure out whether input is morse or english:

if(TransInfo::isEnglish(uI))

{

cout << TransInfo::toMorse(uI) << endl;

}

else

{

cout << TransInfo::toEnglish(uI) << endl;

}

}

return 0;

}

TransInfo.cpp

#include "TransInfo.h"

#include //Allows us to add multiple strings into one string

#include //For uppercase transformation

map TransInfo::englishTranslation;

map TransInfo::morseTranslation;

void TransInfo::initTranslation()

{

// Translation info:

englishTranslation['A'] = ".-";

englishTranslation['B'] = "-...";

englishTranslation['C'] = "-.-.";

englishTranslation['D'] = "-..";

englishTranslation['E'] = ".";

englishTranslation['F'] = "..-.";

englishTranslation['G'] = "--.";

englishTranslation['H'] = "....";

englishTranslation['I'] = "..";

englishTranslation['J'] = ".---";

englishTranslation['K'] = "-.-";

englishTranslation['L'] = ".-..";

englishTranslation['M'] = "--";

englishTranslation['N'] = "-.";

englishTranslation['O'] = "---";

englishTranslation['P'] = ".--.";

englishTranslation['Q'] = "--.-";

englishTranslation['R'] = ".-.";

englishTranslation['S'] = "...";

englishTranslation['T'] = "-";

englishTranslation['U'] = "..-";

englishTranslation['V'] = "...-";

englishTranslation['W'] = ".--";

englishTranslation['X'] = "-..-";

englishTranslation['Y'] = "-.--";

englishTranslation['Z'] = "--..";

englishTranslation['0'] = "-----";

englishTranslation['1'] = ".----";

englishTranslation['2'] = "..---";

englishTranslation['3'] = "...--";

englishTranslation['4'] = "....-";

englishTranslation['5'] = ".....";

englishTranslation['6'] = "-....";

englishTranslation['7'] = "--...";

englishTranslation['8'] = "---..";

englishTranslation['9'] = "----.";

englishTranslation['.'] = ".-.-.-";

englishTranslation[','] = "--..--";

englishTranslation['?'] = "..--..";

englishTranslation['\''] = ".----.";

englishTranslation['!'] = "-.-.--";

englishTranslation['/'] = "-..-.";

englishTranslation['('] = "-.--.";

englishTranslation[')'] = "-.--.-";

englishTranslation['&'] = ".-...";

englishTranslation[':'] = "---...";

englishTranslation[';'] = "-.-.-.";

englishTranslation['='] = "-...-";

englishTranslation['+'] = ".-.-.";

englishTranslation['-'] = "-....-";

englishTranslation['_'] = "..--.-";

englishTranslation['"'] = ".-..-.";

englishTranslation['$'] = "...-..-";

englishTranslation['@'] = ".--.-.";

morseTranslation[".-"] = 'A';

morseTranslation["-..."] = 'B';

morseTranslation["-.-."] = 'C';

morseTranslation["-.."] = 'D';

morseTranslation["."] = 'E';

morseTranslation["..-."] = 'F';

morseTranslation["--."] = 'G';

morseTranslation["...."] = 'H';

morseTranslation[".."] = 'I';

morseTranslation[".---"] = 'J';

morseTranslation["-.-"] = 'K';

morseTranslation[".-.."] = 'L';

morseTranslation["--"] = 'M';

morseTranslation["-."] = 'N';

morseTranslation["---"] = 'O';

morseTranslation[".--."] = 'P';

morseTranslation["--.-"] = 'Q';

morseTranslation[".-."] = 'R';

morseTranslation["..."] = 'S';

morseTranslation["-"] = 'T';

morseTranslation["..-"] = 'U';

morseTranslation["...-"] = 'V';

morseTranslation[".--"] = 'W';

morseTranslation["-..-"] = 'X';

morseTranslation["-.--"] = 'Y';

morseTranslation["--.."] = 'Z';

morseTranslation["-----"] = '0';

morseTranslation[".----"] = '1';

morseTranslation["..---"] = '2';

morseTranslation["...--"] = '3';

morseTranslation["....-"] = '4';

morseTranslation["....."] = '5';

morseTranslation["-...."] = '6';

morseTranslation["--..."] = '7';

morseTranslation["---.."] = '8';

morseTranslation["----."] = '9';

morseTranslation[".-.-.-"] = '.';

morseTranslation["--..--"] = ',';

morseTranslation["..--.."] = '?';

morseTranslation[".----."] = '\'';

morseTranslation["-.-.--"] = '!';

morseTranslation["-..-."] = '/';

morseTranslation["-.--."] = '(';

morseTranslation["-.--.-"] = ')';

morseTranslation[".-..."] = '&';

morseTranslation["---..."] = ':';

morseTranslation["-.-.-."] = ';';

morseTranslation["-...-"] = '=';

morseTranslation[".-.-."] = '+';

morseTranslation["-....-"] = '-';

morseTranslation["..--.-"] = '_';

morseTranslation[".-..-."] = '"';

morseTranslation["...-..-"] = '$';

morseTranslation[".--.-."] = '@';

}

//cthe following method check if string is english

bool TransInfo::isEnglish( const string& userInput ) {

//temp to hold single char from string for analysis

char tempChar = ' ';

//Loop through each char of userInput and analys for english

for (unsigned int index = 0; index < userInput.length(); index++)

{

tempChar = userInput.at(index);

//If the char is anything except dot dash or number sign, it is english

if(tempChar == '.' || tempChar == '-' || tempChar == ' ' || tempChar == '#'){ //Continue

}

else

{

//char was not morse, return true (english)

return true;

}

}

//no english found, return false (morse)

return false;

}

string TransInfo::toMorse( const string& English)

{

string rv; // return value

//Just in case we get an empty string

if(English.size() < 1)

{

return " ";

}

else

{

stringstream stringAddition; //store each character translation

//used to access map based on key

map::iterator it;

//loop through each character and translation

for (unsigned int index = 0; index < English.size(); index++)

{

//Make sure what we are translating is uppercase

char upperChar = toupper(English.at(index));

//Add the translation to the stringstream

if(toupper(English.at(index)) != ' ')

{

//If char is not space, try to find it in englishTranslation

it = englishTranslation.find(upperChar);

//Look to see if we found a matching translation

if(it != englishTranslation.end())

{

//A match is found, so we add it to the stringstream

stringAddition << it->second;

}

else

{

// If none, error

stringAddition << "........";

}

}

//Look at the next character to see if it is space

if(index+1 < English.size())

{

if(toupper(English.at(index+1)) == ' ')

{

//If the next character is space, add #

stringAddition << '#';

}

else if(!(upperChar == ' '))

{

//Add a space to separate characters (between two morse strings)

stringAddition << ' ';

}

}

}

//Convert the stringstream (all of the strings) into one string

rv = stringAddition.str();

}

//Return our completed translation (or space if nothing in Morse)

return rv;

}

string TransInfo::toEnglish( const string& Morse)

{

stringstream ec; // English characters

stringstream oneString;

string tempString;

map::iterator it;

for (unsigned int counter = 0; counter < Morse.size(); counter++)

{

if(Morse.at(counter) == '.' || Morse.at(counter) == '-')

{

oneString << Morse.at(counter);

}

else if(Morse.at(counter) == '#')

{

ec << ' ';

}

if((counter+1 < Morse.size()) && oneString.str() != "")

{

if(Morse.at(counter+1) == '#' || Morse.at(counter+1) == ' ')

{

//analyzing previous findings

it = morseTranslation.find(oneString.str());

if(it != morseTranslation.end())

{

ec << it->second;

}

else

{

ec << "" << oneString.str() << "";

}

oneString.str("");

}

}

else if(oneString.str() != "")

it = morseTranslation.find(oneString.str());

if(it != morseTranslation.end())

{

ec << it->second;

}

else

{

ec << "" << oneString.str() << "";

}

oneString.str("");

}

tempString = ec.str();

return tempString;

}

TransInfo::TransInfo()

{

}

TransInfo::~TransInfo()

{

}

TransInfo.h

#ifndef TRANSINFO_H

#define TRANSINFO_H

#include

#include

using namespace std;

// I am using static methods so we don't have to declare an instance of the class in our program

// We are using map to store information about the morse code and the letters that need to be translated

class TransInfo

{

public:

// The english translation map holds translation information

static map englishTranslation;

// the morseTranslation map holds information on morsecode translation

static map morseTranslation;

// The following initializes the translation

static void initTranslation();

// The following checks if input is english

static bool isEnglish( const string& userInput );

// The following converts to morse

static string toMorse( const string& english );

// The following converts back to english

static string toEnglish( const string& morse );

// Constructor and de-constructor

TransInfo();

~TransInfo();

};

#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!