-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment-3.cpp
122 lines (120 loc) · 1.79 KB
/
assignment-3.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <bits/stdc++.h>
using namespace std;
class morse_code
{
string s;
public:
string morse__code(char x)
{
switch (x)
{
case '1':
return ".----";
case '2':
return "..---";
case '3':
return "...--";
case '4':
return "....-";
case '5':
return ".....";
case '6':
return "-....";
case '7':
return "--...";
case '8':
return "---..";
case '9':
return "----.";
case '0':
return "-----";
case 'A':
return ".-";
case 'B':
return "-...";
case 'C':
return "-.-.";
case 'D':
return "-..";
case 'E':
return ".";
case 'F':
return "..-.";
case 'G':
return "--.";
case 'H':
return "....";
case 'I':
return "..";
case 'J':
return ".---";
case 'K':
return "-.-";
case 'L':
return ".-..";
case 'M':
return "--";
case 'N':
return "-.";
case 'O':
return "---";
case 'P':
return ".--.";
case 'Q':
return "--.-";
case 'R':
return ".-.";
case 'S':
return "...";
case 'T':
return "-";
case 'U':
return "..-";
case 'V':
return "...-";
case 'W':
return ".--";
case 'X':
return "-..-";
case 'Y':
return "-.--";
case 'Z':
return "--..";
case ' ':
// return "/";
//Seven unit of space as per the given in question
return " ";
default:
cout << "Invalid Input";
exit(0);
}
}
void morseCode(string s)
{
for (int i = 0; s[i]; i++)
{
cout << morse__code(s[i]) << " ";
}
cout << endl;
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//Here I am taking input string from the user
string s;
cout << "Please Enter the String:" << endl;
cout << endl;
getline(cin, s);
transform(s.begin(), s.end(), s.begin(), ::toupper);
//Making object of class morse_code
morse_code M;
//Calling function to produce morse code
cout << endl;
cout << "Corresponding Morse Code:" << endl
<< endl;
M.morseCode(s);
cout << endl;
return 0;
}