-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
96 lines (79 loc) · 2.79 KB
/
main.cpp
File metadata and controls
96 lines (79 loc) · 2.79 KB
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
#include <iostream>
#include <string>
using namespace std;
int main()
{
// FCI – Programming 1 – 2018 - Assignment 2
// Program Name: morse code
// Last Modification Date: xx/xx/xxxx
// Author1 and ID and Group:eman ayman 20170067
// Author2 and ID and Group: xxxxx xxxxx
// Author3 and ID and Group: xxxxx xxxxx
// Teaching Assistant: hala abd el kader
cout<< "please choose one for incoding or two for decode"<<endl;
int p;
cin>>p;
if (p==1){
string code [26]={ ".-", "-...", "-.-.", "-..", ".",
"..-.", "--.", "....", "..", ".---",
"-.-", ".-..", "--", "-.", "---",
".--.", "--.-", ".-.", "...", "-",
"..-", "...-", ".--", "-..-", "-.--", "--.."};
cout <<"enter the text:"<<endl;
string text ;
cin.ignore();
getline(cin,text);
for (int i=0;i<text.size();i++) {
if(text[i]>='A'&&text[i]<='Z')
{
text[i]=text[i]-'A'+'a';
}
if (text[i]==' ') {
cout << " ";
}
else {
int idx=text[i]-'a';
cout <<code[idx] << ' ';
}
}}
else if (p==2) {
string code [26]={ ".-", "-...", "-.-.", "-..", ".",
"..-.", "--.", "....", "..", ".---",
"-.-", ".-..", "--", "-.", "---",
".--.", "--.-", ".-.", "...", "-",
"..-", "...-", ".--", "-..-", "-.--", "--.."};
string alpha [26]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
string morse = "", word = "";
cout<<"enter the morse code"<<endl;
cin.ignore();
getline( cin , morse );
int counter = 0 , x = 0;
while ( counter < morse.length() ){
while ( (int)morse[counter] >= 33 && (int)morse[counter] <= 127 ){
word += morse[counter];
counter += 1;
if ( counter == morse.length() ){ break; }
}
for (int i=0;i<26;i++){
if ( code[i] == word ){ cout<<alpha[i];}
}
if ( morse[counter] == ' ' && morse[counter+1] == ' ' && morse[counter+2] == ' ' ){
cout<<" ";
counter=counter+2;
}
else { counter++; }
word ="";
}
{
if (morse[counter]==' '&&morse[counter+1]==' '&&morse[counter+2]==' '){
cout<<" ";
counter=counter+2;
}
else {counter++;}
word ="";
}}
else {
cout <<"your choose not correct";
}
return 0;
}