Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <ctime>
- #include <string>
- #include <cctype>
- #include "BST.h"
- using namespace std;
- struct alphaTree
- {
- string letter;
- string code;
- };
- int main()
- {
- // display time and date
- time_t u;
- time(&u);
- cout << ctime(&u) << endl;
- // declaring and calling functions
- BST t; string message; char* morseCode = new char; char ans;
- alphaTree array[27] = {{"E", ". "}, {"T", "- "}, {"I", ".. "}, {"A", ".- "}, {"N", "-. "}, {"M", "-- "},
- {"S", "... "}, {"U", "..- "}, {"R", ".-. "}, {"W", ".-- "}, {"D", "-.. "}, {"K", "-.- "},
- {"G", "--. "}, {"O", "--- "}, {"H", ".... "}, {"V", "...- "}, {"F", "..-. "}, {"L", ".-.. "},
- {"P", ".--. "}, {"J", ".--- "}, {"B", "-... "}, {"X", "-..- "},
- {"C", "-.-. "}, {"Y", "-.-- "}, {"Z", "--.. "}, {"Q", "--.- "}, {" ", "---- "}};
- t.Insert("0", "");
- for(int i = 0; i < 27; i++)
- {
- t.Insert(array[i].letter, array[i].code);
- }
- do
- {
- cout << "Enter your message: ";
- getline(cin, message);
- int len = message.length();
- for(int i = 0; i < len; i++)
- {
- message[i] = toupper(message[i]);
- char c = message[i];
- if(c == ' ')
- cout << "/ ";
- t.Encode(c);
- }
- cout << endl;
- cout << "Enter your Morse code, separated by /, ended by *: ";
- cin.getline(morseCode, 100, '*');
- char* token = strtok(morseCode, "/");
- while(token != NULL)
- {
- cout << endl << "Decoding: " << token << endl;
- string newCode = token;
- t.Decode(newCode);
- token = strtok(NULL, "/");
- }
- cout << "Continue: ";
- cin >> ans; cin.ignore(); cout << endl;
- }while(ans == 'y');
- //t.DisplayPreOrder();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement