Advertisement
Guest User

Untitled

a guest
May 2nd, 2014
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <ctime>
  5. #include <string>
  6. #include <cctype>
  7. #include "BST.h"
  8.  
  9. using namespace std;
  10.  
  11. struct alphaTree
  12. {
  13. string letter;
  14. string code;
  15. };
  16.  
  17. int main()
  18. {
  19. // display time and date
  20. time_t u;
  21. time(&u);
  22. cout << ctime(&u) << endl;
  23.  
  24. // declaring and calling functions
  25. BST t; string message; char* morseCode = new char; char ans;
  26. alphaTree array[27] = {{"E", ". "}, {"T", "- "}, {"I", ".. "}, {"A", ".- "}, {"N", "-. "}, {"M", "-- "},
  27. {"S", "... "}, {"U", "..- "}, {"R", ".-. "}, {"W", ".-- "}, {"D", "-.. "}, {"K", "-.- "},
  28. {"G", "--. "}, {"O", "--- "}, {"H", ".... "}, {"V", "...- "}, {"F", "..-. "}, {"L", ".-.. "},
  29. {"P", ".--. "}, {"J", ".--- "}, {"B", "-... "}, {"X", "-..- "},
  30. {"C", "-.-. "}, {"Y", "-.-- "}, {"Z", "--.. "}, {"Q", "--.- "}, {" ", "---- "}};
  31.  
  32. t.Insert("0", "");
  33.  
  34. for(int i = 0; i < 27; i++)
  35. {
  36. t.Insert(array[i].letter, array[i].code);
  37. }
  38.  
  39. do
  40. {
  41. cout << "Enter your message: ";
  42. getline(cin, message);
  43. int len = message.length();
  44.  
  45. for(int i = 0; i < len; i++)
  46. {
  47. message[i] = toupper(message[i]);
  48. char c = message[i];
  49. if(c == ' ')
  50. cout << "/ ";
  51. t.Encode(c);
  52. }
  53. cout << endl;
  54.  
  55. cout << "Enter your Morse code, separated by /, ended by *: ";
  56. cin.getline(morseCode, 100, '*');
  57. char* token = strtok(morseCode, "/");
  58. while(token != NULL)
  59. {
  60. cout << endl << "Decoding: " << token << endl;
  61. string newCode = token;
  62. t.Decode(newCode);
  63. token = strtok(NULL, "/");
  64. }
  65. cout << "Continue: ";
  66. cin >> ans; cin.ignore(); cout << endl;
  67. }while(ans == 'y');
  68.  
  69. //t.DisplayPreOrder();
  70.  
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement