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