Compare commits
2 Commits
d1f6eae102
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 036cd1ea90 | |||
| 16fe1178f4 |
@@ -64,7 +64,7 @@ In **encode mode**:
|
||||
|
||||
In both modes:
|
||||
|
||||
- Type `exit` to quit the program
|
||||
- Press `Ctrl+D` to quit the program
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
17
main.cpp
17
main.cpp
@@ -25,22 +25,15 @@ const map<char, string> morse_map = {
|
||||
|
||||
bool should_exit = false;
|
||||
|
||||
bool is_exit(const string &s) {
|
||||
return s.length() == 4 && tolower(static_cast<unsigned char>(s[0])) == 'e' &&
|
||||
tolower(static_cast<unsigned char>(s[1])) == 'x' &&
|
||||
tolower(static_cast<unsigned char>(s[2])) == 'i' &&
|
||||
tolower(static_cast<unsigned char>(s[3])) == 't';
|
||||
}
|
||||
|
||||
string read_input(const string &prompt) {
|
||||
cout << prompt;
|
||||
string line;
|
||||
if (!getline(cin, line) || line.empty())
|
||||
return "";
|
||||
if (is_exit(line)) {
|
||||
if (!getline(cin, line)) {
|
||||
should_exit = true;
|
||||
return "";
|
||||
}
|
||||
if (line.empty())
|
||||
return "";
|
||||
return line;
|
||||
}
|
||||
|
||||
@@ -119,7 +112,7 @@ public:
|
||||
void decode_mode() {
|
||||
MorseDecoder decoder;
|
||||
cout << "Decode mode: Enter morse sequence to decode. Press 'e' to switch to "
|
||||
"encode mode, 'exit' to exit.\n\n";
|
||||
"encode mode.\n\n";
|
||||
|
||||
while (!should_exit) {
|
||||
string input = read_input("Enter morse sequence: ");
|
||||
@@ -171,7 +164,7 @@ void decode_mode() {
|
||||
void encode_mode() {
|
||||
MorseEncoder encoder;
|
||||
cout << "Encode mode: Enter text to see Morse code patterns. Press 'd' to "
|
||||
"switch to decode mode, 'exit' to exit.\n\n";
|
||||
"switch to decode mode.\n\n";
|
||||
|
||||
while (!should_exit) {
|
||||
string input = read_input("Enter text to encode: ");
|
||||
|
||||
Reference in New Issue
Block a user