Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 I need help in making morse code translator...
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Minami




PostPosted: Tue Apr 07, 2009 4:07 am   Post subject: I need help in making morse code translator...

i need to create a program that translate code morse to word...

for exampla we type in .... . .-.. .-.. ---, hello will come out...

ive try everything, i do it non stop for abt 2 week edi and my due date is on 9..
tomoro is mylast day to finish it...
i really need help right now...

there i put all the code that i've tried...
im using visual basic..

------------------------------------------------------------------------------------

c++:
#include<iostream>
using namespace std;

void main()
{
        double MorseCode;
        char Asakara;

        cout<<"insert Morse Code)\n";

       
        cin>>MorseCode;
       

        if (MorseCode == .-)
                Asakara = 'A';
       
        else if (MorseCode == '-...')
                Asakara = 'B';
       
        else if (MorseCode == '-.-.')   
                Asakara = 'C';
       
        else if (MorseCode == '-...')   
                Asakara = 'D';
               
        else if (MorseCode == '.')     
                Asakara = 'E';
               
        else if (MorseCode == '..-')   
                Asakara = 'F';
               
        else if (MorseCode == '----')   
                Asakara = 'G';
               
        else if (MorseCode == '....')   
                Asakara = 'H';
               
        else if (MorseCode == '..')     
                Asakara = 'I';
               
        else if (MorseCode == '.---')   
                Asakara = 'J';
               
        else if (MorseCode == '-.-')   
                Asakara = 'K';
               
        else if (MorseCode == '.-..')   
                Asakara = 'L';
               
        else if (MorseCode == '--')     
                Asakara = 'M';
               
        else if (MorseCode == '-.')     
                Asakara = 'N';
               
        else if (MorseCode == '---')   
                Asakara = 'O';
               
        else if (MorseCode == '.--.')   
                Asakara = 'P';
               
        else if (MorseCode == '--.-')   
                Asakara = 'Q';
               
        else if (MorseCode == '.-.')   
                Asakara = 'R';
               
        else if (MorseCode == '...')   
                Asakara = 'S';
               
        else if (MorseCode == '-')     
                Asakara = 'T';
               
        else if (MorseCode == '..--')   
                Asakara = 'U';
               
        else if (MorseCode == '...-')   
                Asakara = 'V';
               
        else if (MorseCode == '.--')   
                Asakara = 'W';
               
        else if (MorseCode == '-..-')   
                Asakara = 'X';
               
        else if (MorseCode == '-.--')   
                Asakara = 'Y';
               
        if (MorseCode == '--..')       
                Asakara = 'Z';

        cout<<Asakara<<endl;



}


-----------------------------------------------------------------------------------------------



#include<string>
using namespace std;


void main()
{
       
        char Aksara;
        int MorseCode;
       

        cout<<"insert Morse Code:\n";

                cin>>MorseCode;

        switch (MorseCode)
        {
        case '.-':      Aksara = 'A';
                break;
        case '-...':    Aksara = 'B';
                break;
        case '-.-.':    Aksara = 'C';
                break;
        case '-..':     Aksara = 'D';
                break;
        case '.':       Aksara = 'E';
                break;
        case '..-':     Aksara = 'F';
                break;
        case '----':    Aksara = 'G';
                break;
        case '....':    Aksara = 'H';
                break;
        case '..':      Aksara = 'I';
                break;
        case '.---':    Aksara = 'J';
                break;
        case '-.-':     Aksara = 'K';
                break;
        case '.-..':    Aksara = 'L';
                break;
        case '--':      Aksara = 'M';
                break;
        case '-.':      Aksara = 'N';
                break;
        case '---':     Aksara = 'O';
                break;
        case '.--.':    Aksara = 'P';
                break;
        case '--.-':    Aksara = 'Q';
                break;
        case '.-.':     Aksara = 'R';
                break;
        case '...':     Aksara = 'S';
                break;
        case '-':       Aksara = 'T';
                break;
        case '..--':    Aksara = 'U';
                break;
        case '...-':    Aksara = 'V';
                break;
        case '.--':     Aksara = 'W';
                break;
        case '-..-':    Aksara = 'X';
                break;
        case '-.--':    Aksara = 'Y';
                break;
        case '--..':    Aksara = 'Z';
                break;
        }
       
        cout<<Aksara<<endl;

}


---------------------------------------------------------------


#include <iostream>
using namespace std;
char code1,code2,code3,code4,code5;
char morse;


char main()
{
        char morse[26]={".-","-...",'-.-.','-..','.','..-','----','....','..','.----','-.-','.-..','--','-.','---','.--.','--.-','.-.','...','-','..-..','...-','.--','-..-','-.--','--..'};

        char 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;

        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='--..';

        cin>>code1;

        for (int i=0;i<26;i++)
                if code1='.-'
                        cout<<'A';
                else if code1='-...'
                        cout<<'B';
                else if code1='-.-.'
                        cout<<'C';
                else if code1='-..'
                        cout<<'D';
                else if code1='.'
                        cout<<'E';
                else if code1='..-'
                        cout<<'F';
                else if code1='----'
                        cout<<'G';
                else if code1='....'
                        cout<<'H';
                else if code1='..'
                        cout<<'I';
                else if code1='.---'
                        cout<<'J';
                else if code1='-.-'
                        cout<<'K';
                else if code1='.-..'
                        cout<<'L';
                else if code1='--'
                        cout<<'M';
                else if code1='-.'
                        cout<<'N';
                else if code1='---'
                        cout<<'O';
                else if code1='.--.'
                        cout<<'P';
                else if code1='--.-'
                        cout<<'Q';
                else if code1='.-.'
                        cout<<'R';
                else if code1='...'
                        cout<<'S';
                else if code1='-'
                        cout<<'T';
                else if code1='..--'
                        cout<<'U';
                else if code1='...-'
                        cout<<'V';
                else if code1='.--'
                        cout<<'W';
                else if code1='-..-'
                        cout<<'X';
                else if code1='-.--'
                        cout<<'Y';
                else code1='--..'
                        cout<<'Z';

}

-------------------------------------------------------------------

#include <iostream>
#include <string>
#include <algorithm>

using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::transform;

int main()
{
        string searchForMorseCode = "";
        string MorseCode[26] = {".-","-...","-.-.","-..",".","..-","----","....","..",".----","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-..","...-",".--","-..-","-.--","--.."};
        char Asakara[26] = {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};

        cout<<"Enter MorsCode (X to exit): ";
        getline(cin, searchForMorseCode);
        transform(searchForMorseCode.begin(), searchForMorseCode.end(), searchForMorseCode.begin(),toupper);

        while (searchForMorseCode != "X")
        {
                int y = 0;
                while(y < 26 && Asakara[y] != searchForMorseCode)
                y = y + 1;

                if (y < 26)
                        cout<<"The code morse is :"<<Asakara[y]<<endl<<endl;
                else
                        cout<< "Invalid Code Morse"<< endl<<endl;
               
                cout<<"Enter MorsCode (X to exit): ";
                getline(cin, searchForMorseCode);
                transform(searchForMorseCode.begin(), searchForMorseCode.end(), searchForMorseCode.begin(),toupper);
        }

        return 0;
}


-------------------------------------------------------------------------

hope you all can help...
i realy2 need ur help...[/u]


Mod Edit: Remember to use syntax tags! Thanks Smile
code:
[syntax="cpp"]Code Here[/syntax]
Sponsor
Sponsor
Sponsor
sponsor
saltpro15




PostPosted: Tue Apr 07, 2009 8:31 am   Post subject: RE:I need help in making morse code translator...

this should really be in the VB section, but oh well, you're new :p well, stuff like this

c++:

 for (int i=0;i<26;i++)
                if code1='.-'
                        cout<<'A';
                else if code1='-...'
                        cout<<'B';
                else if code1='-.-.'
                        cout<<'C';
                else if code1='-..'
                        cout<<'D';
                else if code1='.'
                        cout<<'E';
                else if code1='..-'
                        cout<<'F';
                else if code1='----'
                        cout<<'G';
                else if code1='....'
                        cout<<'H';
                else if code1='..'
                        cout<<'I';
                else if code1='.---'
                        cout<<'J';
                else if code1='-.-'
                        cout<<'K';
                else if code1='.-..'
                        cout<<'L';
                else if code1='--'
                        cout<<'M';
                else if code1='-.'
                        cout<<'N';
                else if code1='---'
                        cout<<'O';
                else if code1='.--.'
                        cout<<'P';
                else if code1='--.-'
                        cout<<'Q';
                else if code1='.-.'
                        cout<<'R';
                else if code1='...'
                        cout<<'S';
                else if code1='-'
                        cout<<'T';
                else if code1='..--'
                        cout<<'U';
                else if code1='...-'
                        cout<<'V';
                else if code1='.--'
                        cout<<'W';
                else if code1='-..-'
                        cout<<'X';
                else if code1='-.--'
                        cout<<'Y';
                else code1='--..'
                        cout<<'Z';

}


is usually where errors come from, I suggest looking there first
Minami




PostPosted: Tue Apr 07, 2009 10:06 am   Post subject: Re: I need help in making morse code translator...

realy? sorry.. in new in this forum.. huhu..
actually im learning c++.. but using visual basic c++.. haha..

thx alot...
but i still cant find the error...

i made a new code..
kinda work, but it translate 1 word by word

example if u type in .-
A will come out..

if u type .- .-
it will say wrong code, it wont come out A A

here the code
c++:

#include <iostream>
#include <string>
#include <algorithm>

using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::transform;

int main()
{
        string searchForWord = "";
        string words[26][2] = {{".-", "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"}};


        cout<< "Enter MorseCode (X to exit): ";
        getline(cin, searchForWord);
        transform(searchForWord.begin(), searchForWord.end(), searchForWord.begin(), toupper);

        while (searchForWord != "X")
        {
                int row = 0;
                while (row < 26 && words[row][0] != searchForWord)
                        row = row + 1;

                if (row < 26)
                        cout << "The word is " << words[row][0] << " = " << words[row][1] << endl << endl;
                else
                        cout << "Invalid MorseCode" << endl << endl;


                cout << "Enter MorseCode (X to exit): ";
                getline(cin, searchForWord);
                transform(searchForWord.begin(), searchForWord.end(), searchForWord.begin(), toupper);
        }

        return 0;
}


i want to make every tyme i put key in, the word is stored in sum kind off array..

example
juz key in .-
then enter.
key in the code again .-
then enter...
then if i type in '0'
AA will come out...
any suggestion??
saltpro15




PostPosted: Tue Apr 07, 2009 2:04 pm   Post subject: RE:I need help in making morse code translator...

Quote:
actually im learning c++.. but using visual basic c++.. haha..
what's visual basic c++? I've never heard of that, do you mean microsoft's visual c++?
Minami




PostPosted: Tue Apr 07, 2009 2:49 pm   Post subject: RE:I need help in making morse code translator...

cuz when i click the program..
Visual basic then from there click c++

mayb got confuse a lil bit..
huhuhu...
md




PostPosted: Tue Apr 07, 2009 2:59 pm   Post subject: RE:I need help in making morse code translator...

I believe he means Visual C++; which when shipped as part of Visual Studio might (maybe?) be confused as being Visual Basic...

Proper english and grammar would certainly help clear up the confusion.

It would appear that you are reading in a word, and then searching your array of letters for it. Perhaps you mean to iterate though the word you read in?
saltpro15




PostPosted: Tue Apr 07, 2009 3:03 pm   Post subject: RE:I need help in making morse code translator...

Always amazes me how people can write these big long detailed programs and then not know how to use proper English or have the slightest clue as to what the program is doing...
Minami




PostPosted: Wed Apr 08, 2009 10:58 pm   Post subject: RE:I need help in making morse code translator...

found the code edi ^^
i use array.. more simple huhu.. thx for all ur help..
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: