Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- void ToUper(char& c)
- {
- if(c >= 'a' && c <= 'z')
- c = c - ('a' - 'A');
- }
- bool isAlpha(char c)
- {
- if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
- return true;
- return false;
- }
- bool isNumber(char c)
- {
- if(c >= '0' && c <= '9')
- return true;
- return false;
- }
- void MorseCodeForAlpha(char c)
- {
- const char alpha[] = {'A','B','C','D','E','F','G','H','I',
- 'J','K','L','M','N','O','P','R',
- 'S','T','U','V','W','X','Y','Z'};
- const char* morse[] = {".-","-...","-.-.","-..",".","..-.",
- "--.","....","..",".---","-.-",".-..","--","-.","---",".--.",
- "--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."
- };
- for(int i=0; i<27; i++)
- {
- if(c == alpha[i])
- {
- cout << morse[i] << " ";
- }
- }
- }
- void MorseCodeForNumber(char c)
- {
- const char number[] = {'0','1','2','3','4','5','6','7','8','9'};
- const char* morse[] = { "-----",".----","..---","...--","....-",
- ".....","-....","--...","---..","----."};
- for(int i=0; i<11; i++)
- {
- if(c == number[i])
- {
- cout << morse[i] << " ";
- }
- }
- }
- int main()
- {
- char message[100];
- cin.get(message,99);
- int length = strlen(message);
- for(int i=0; i<length; i++)
- {
- if(isAlpha(message[i]))
- {
- ToUper(message[i]);
- //cout << message[i] << endl;
- MorseCodeForAlpha(message[i]);
- //cout <<"This is alpha" <<endl;
- }
- else if (isNumber(message[i]))
- {
- MorseCodeForNumber(message[i]);
- // cout << " This is number" << endl; continue;
- }
- else if(message[i] == ' ')
- {
- cout << " "; continue;
- }
- else cout << "Bad input" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement