-
Notifications
You must be signed in to change notification settings - Fork 14
/
lab_morse.cpp
105 lines (66 loc) · 2.29 KB
/
lab_morse.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
class Morseifier
{
// MAKE AS MANY CHANGES TO THE CLASS AS YOU WANT
public:
Morseifier()
{
}
/* A function that takes a string as input and
translates it into morse code before returning it */
string translate( string text )
{
string answer = "";
return answer;
}
/* A function that takes a string as input and
translates it from morse code before returning it */
string untranslate( string morse )
{
string answer = "";
return answer;
}
};
int main()
{
Morseifier m;
vector< tuple<string, string> > tests { make_tuple("MORSE CODE","-- --- .-. ... . / -.-. --- -.. ."),
make_tuple("INSPECTOR MORSE",".. -. ... .--. . -.-. - --- .-. / -- --- .-. ... ."),
make_tuple("",""),
make_tuple("LAST OF THE MORSICANS",".-.. .- ... - / --- ..-. / - .... . / -- --- .-. ... .. -.-. .- -. ...") };
int errors = 0;
for( auto test : tests )
{
string yourMorse = m.translate( get<0>(test) );
string yourText = m.untranslate( get<1>(test) );
if( yourMorse != get<1>(test) )
{
cerr << "Error when translating " << get<0>(test) << endl <<
"Yours : \"" << yourMorse << "\"" << endl <<
"Correct: \"" << get<1>(test) << "\"" << endl << endl;
errors += 1;
}
if( yourText != get<0>(test) )
{
cerr << "Error when translating " << get<1>(test) << endl <<
"Yours : \"" << yourText << "\"" << endl <<
"Correct: \"" << get<0>(test) << "\"" << endl << endl;
errors += 1;
}
}
if( errors == 0 )
{
cout << "Congratulations, no errors" << endl <<
"-.-. --- -. --. .-. .- - ..- .-.. .- - .. --- -. ... / -. --- / . .-. .-. --- .-. ..." << endl;
}
else
{
cout << "Uh oh, " << errors << " error/s remain" << endl <<
"..- .... / --- .... / . .-. .-. --- .-. ... / .-. . -- .- .. -." << endl;
}
return errors;
}