Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <stdlib.h>
- //#include <conio.h>
- using namespace std;
- int main()
- {
- string morse[39] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.",
- "....", "..", ".---", "-.-", ".-..", "--", "-.",
- "---", ".--.", "--.-", ".-.", "...", "-", "..-",
- "...-", ".--", "-..-", "-.--", "--..", ".----",
- "..---", "...--", "....-", ".....", "-....",
- "--...", "---..", "----.", "-----", ".-.-.-",
- "--..--", "..--.."};
- string letters[39] = { "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",
- "Stop", ",", "?" };
- string input, trans, temp = "", loc;
- int ans, count = 0;
- bool again = true;
- while (again)
- {
- cout << "Welcome to the Morse Code Translator";
- cout << "\n\n\t1 - English to Morse";
- cout << "\n\t2 - Morse to English";
- cout << "\n\t3 - Help";
- cout << "\n\t4 - Exit";
- cout << "\n\n\n\tPlease enter your choice: ";
- cin >> ans;
- switch(ans)
- {
- case 1:
- {
- //Case for translating English to Morse Code
- //system("cls");
- cout << "\nPlease enter the line you want to translate: ";
- cin >> input;
- /*for (int i = 0; i < input.length(); i++)
- {
- input[i] = tolower(input[i]);
- for (int x = 0; x < 39; x++)
- {
- if (input[i] == )
- {
- temp = morse[x] + " ";
- trans += temp;
- }
- }
- }*/
- for (int i = 0; i < 39; i++)
- {
- loc = input.find(letters[i]);
- temp = morse[i] + " ";
- trans.replace(loc,1,temp);
- }
- cout << "\n\nThe Translation is " << trans;
- break;
- }
- case 2:
- {
- //system("cls");
- break;
- }
- case 3:
- {
- system("clear");
- //system("cls");
- cout << "\nThis is the help menu.";
- cout << "\n\nThis is a table that holds translations.\n";
- for (int i = 0; i < 39; i++)
- {
- cout << "\t\"" << morse[i] << "\" - " << letters[i];
- count += 1;
- if (count == 3)
- {
- cout << "\n";
- count = 0;
- }
- }
- break;
- }
- case 4:
- {
- exit (0);
- break;
- }
- default:
- {
- cout << "You did not enter a valid choice!";
- cout << "\n\nPlease enter any key to continuce...";
- //getch();
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement