Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <stdlib.h>
  4.  
  5. //#include <conio.h>
  6.  
  7. using namespace std;
  8.  
  9.  
  10.  
  11. int main()
  12. {
  13. string morse[39] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.",
  14. "....", "..", ".---", "-.-", ".-..", "--", "-.",
  15. "---", ".--.", "--.-", ".-.", "...", "-", "..-",
  16. "...-", ".--", "-..-", "-.--", "--..", ".----",
  17. "..---", "...--", "....-", ".....", "-....",
  18. "--...", "---..", "----.", "-----", ".-.-.-",
  19. "--..--", "..--.."};
  20.  
  21. string letters[39] = { "a", "b", "c", "d", "e", "f", "g", "h", "i",
  22. "j", "k", "l", "m", "n", "o", "p", "q", "r",
  23. "s", "t", "u", "v", "w", "x", "y", "z", "1",
  24. "2", "3", "4", "5", "6", "7", "8", "9", "0",
  25. "Stop", ",", "?" };
  26.  
  27.  
  28. string input, trans, temp = "", loc;
  29.  
  30. int ans, count = 0;
  31. bool again = true;
  32.  
  33. while (again)
  34. {
  35. cout << "Welcome to the Morse Code Translator";
  36. cout << "\n\n\t1 - English to Morse";
  37. cout << "\n\t2 - Morse to English";
  38. cout << "\n\t3 - Help";
  39. cout << "\n\t4 - Exit";
  40.  
  41. cout << "\n\n\n\tPlease enter your choice: ";
  42. cin >> ans;
  43.  
  44. switch(ans)
  45. {
  46. case 1:
  47. {
  48. //Case for translating English to Morse Code
  49. //system("cls");
  50. cout << "\nPlease enter the line you want to translate: ";
  51. cin >> input;
  52.  
  53. /*for (int i = 0; i < input.length(); i++)
  54. {
  55. input[i] = tolower(input[i]);
  56. for (int x = 0; x < 39; x++)
  57. {
  58. if (input[i] == )
  59. {
  60. temp = morse[x] + " ";
  61. trans += temp;
  62. }
  63. }
  64. }*/
  65.  
  66. for (int i = 0; i < 39; i++)
  67. {
  68. loc = input.find(letters[i]);
  69. temp = morse[i] + " ";
  70. trans.replace(loc,1,temp);
  71. }
  72. cout << "\n\nThe Translation is " << trans;
  73. break;
  74. }
  75. case 2:
  76. {
  77. //system("cls");
  78. break;
  79. }
  80. case 3:
  81. {
  82. system("clear");
  83. //system("cls");
  84. cout << "\nThis is the help menu.";
  85. cout << "\n\nThis is a table that holds translations.\n";
  86. for (int i = 0; i < 39; i++)
  87. {
  88. cout << "\t\"" << morse[i] << "\" - " << letters[i];
  89. count += 1;
  90. if (count == 3)
  91. {
  92. cout << "\n";
  93. count = 0;
  94. }
  95. }
  96. break;
  97.  
  98. }
  99. case 4:
  100. {
  101. exit (0);
  102. break;
  103. }
  104. default:
  105. {
  106. cout << "You did not enter a valid choice!";
  107. cout << "\n\nPlease enter any key to continuce...";
  108. //getch();
  109. break;
  110. }
  111. }
  112. }
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement