Morse to english and the other way

Hello!

I am suppose to build a program that convert Morse-code to English and the other way. I will use arrays to define letters and Morse-code. I don't know how to connect two arrays.

Need help to begin my project.

I past the code I have come up with, I am a beginner!
Have only programming in about 3 weeks (c++).

Can anybody explain how to start?
Some code and example?

I will the program to have 2 functions. One to Translate to Morse-code, and the other function to translate Morse-code to English (text).


Text me so we can discuss the problems I have.
I'm online, in principle, all my waking hours.

Text to this subject, and please help me.
/Puckosmucko
/thanks in advance


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using namespace std;
int main()
{
char funk_text_morse()
{
//------------------------morse-tabell---------------------------
char morse[] = {".-",    "-...",  "-.-.", "-..",  ".",    "..-.",
               "--.",   "....",  "..",   ".---", "-.-",  ".-..",
               "--",    "-.",    "---",  ".--.", "--.-", ".-.",
               "...",   "-",    "..-",  "...-", ".--",  "-..-",
               "-.--",  "--..",  ".--.-",".-.-", "---." };

//------------------------text-tabell---------------------------
char text[] = {A, B, C, D, E, F, G, H, I, J, K, L,
               M, N, O, P, Q, R, S, T, U, V, X, Y,
               W, Z, Å, Ä, Ö};
//--------------------------------------------------------------
char string_out;
int k;
for (k=0; k<= 10; k++)
	{
	if (text[k]= morse[k])
		{
			cout >> "Sktiv in ett ord på max 10 tecken."; 
			cin  >> 
		}


	}
 }
 }




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include "iodos.h"
using namespace std;


int main()
{
dos_console();
char inmatning;
cout << "Vad vill du göra?\n(1)Översätta till morse\n(2)Översätta från morse\nVal: ";
cin >> inmatning;

if (inmatning == '1')
{ 
cout << "Översätta till morse\n";
//cout << funktionen som ska utföras, kan man lägga funktionen i en "Header File".
}
else if (inmatning == '2')
cout << "Översätta från morse\n";
//cout << funktionen som ska utföras, kan man lägga funktionen i en "Header File".
return 0;
}


The program is going to be in a commando prompt.
The user is going to see this in the prompt:
-----------------------------------------------
(Window 1:)
What is your chose?
(1) Translate to Morse-code?
(2) Translate to English?
:1
-----------------------------------------------
//The user write 1 -->
(Window 2:)
Translate to Morse-code?

Write a message to be translated?

TEST
----------------------------------------------
(Window 3:)
Translated to Morse-code:
-. ... -

<< press a key and return to the menu >>
----------------------------------------------

And here comes the other way (translate to English):
----------------------------------------------
(Window 1:)
What is your chose?
(1) Translate to Morse-code?
(2) Translate to English?
:1
----------------------------------------------
Translate to English?

Write a message to be translated?
-. ... -
----------------------------------------------
Translated into text, it will be:
TEST
<<Press any key and return to the menu
----------------------------------------------
To convert from English to Morse, read a char, find its place in the 'text' char array (or simply given_char-'A') then find a string in the same position in 'morse' string array and append it to the result string.
#include<string> to make things more simple.
Converting from Morse to English could be a little more complicated. If every letter in morse code is separated by a space, use strtok or stringstream to divide it into letters. Then find those letters in 'morse' array and append their English equivalents to result string.

on line 7, it should be string array (or char* array, but strings are better), not char. char is one letter and you need arrays of them.
on line 14, it should be 'A', not A. 'A' is a char and A is not declared.
on line 18, again. string, not char.
EDIT: just noticed one thing.
on line 2 you enter main() but on line 4 you enter another function. local function declarations are not allowed. Is the first part of code supposed to be a header? There shouldn't be a main, since you've already got one in another file.
Last edited on
Ok!

Thank you for the tips!
You have initialized the text and morse arrays with the required data.
Why not declare a 3rd char text_array[] which is reserved for the text_test message which can be loaded using the getline() function from the keyboard.
Using a loop find the "i" location of the first character of the test message and print the equivalent "i" element from the morse array. Repeat for remaining text_array elements.
Similarly using a 4th char morse_array[] translate morse to text.
It may not be elegant but it would be robust.
Topic archived. No new replies allowed.