Morse Code Converter
A lightweight C++ utility that converts text to Morse code and vice versa. Perfect for learning, amateur radio enthusiasts, and developers.
Key Features
Bidirectional Conversion
Convert text to Morse code and decode Morse code back to text.
File I/O Support
Load text from files and save Morse code output to files.
40+ Characters
Supports letters, digits, and common punctuation marks.
High Performance
Efficient lookups with unordered_map for fast conversions.
Supported Characters
| Category | Characters | Example |
|---|---|---|
| Letters | A–Z (case-insensitive) | A = .- |
| Digits | 0–9 | 1 = .---- |
| Punctuation | . , ? : ; - / " ' ( ) = + $ _ @ | ? = ..--.. |
Installation
Get started with Morse Code Converter in just a few steps.
Requirements
- C++17 capable compiler (GCC 7+, Clang 5+, MSVC 2017+)
- Make (optional, for Makefile)
Build from Source
git clone https://github.com/HarshYadav152/Morse-Code.git
cd Morse-Code
g++ -std=c++17 MorseCodeConverter.cpp -O2 -o morse
Using Makefile
make # Build the project
make run # Build and run
make clean # Remove build artifacts
Usage
Learn how to use the Morse Code Converter effectively.
Running the Program
./morse
Interactive Menu
After running the program, you'll see this menu:
====== Morse Code Converter ======
1. Convert Text to Morse
2. Convert Morse to Text
3. Load from File
4. Save to File
5. Exit
==================================
Menu Options
| Option | Description |
|---|---|
| 1 | Converts plain text input to Morse code |
| 2 | Decodes space-separated Morse code to text |
| 3 | Load text from a file |
| 4 | Save Morse code output to a file |
| 5 | Exit the program |
API Reference
Complete reference for the MorseConverter class and its methods.
MorseConverter Class
Constructor
MorseConverter();
Initializes the converter with Morse code mappings.
Methods
textToMorse()
string textToMorse(const string& text);
Description: Converts plain text to Morse code.
Parameters: text - Input text string
Returns: Space-separated Morse code
morseToText()
string morseToText(const string& morse);
Description: Converts Morse code back to text.
Parameters: morse - Space-separated Morse code
Returns: Decoded text string
saveToFile()
void saveToFile(const string& filename, const string& content);
Description: Saves content to a file.
Parameters: filename - Output file path, content - Text to save
loadFromFile()
string loadFromFile(const string& filename);
Description: Loads content from a file.
Parameters: filename - Input file path
Returns: File contents as string
Examples
Practical examples of using the Morse Code Converter.
Text to Morse
Input: HELLO WORLD
Output: .... . .-.. .-.. --- / .-- --- .-. .-.. -..
Morse to Text
Input: .... . .-.. .-.. --- / .-- --- .-. .-.. -..
Output: HELLO WORLD
With Digits
Input: TEST 123
Output: - . ... - / .---- ..--- ...--
With Punctuation
Input: HELLO?
Output: .... . .-.. .-.. --- ..--..
Frequently Asked Questions
Find answers to common questions about the Morse Code Converter.
What is Morse code?
Morse code is a method of transmitting information using sequences of dots and dashes. It's represented here as "." and "-" characters.
How do I separate words in Morse code?
Words are separated by "/" in the Morse code output. When entering Morse code, spaces separate characters and "/" separates words.
What happens if I enter an unsupported character?
Unsupported characters are represented as "?" in the output. The program supports 40+ common characters.
Can I use lowercase letters?
Yes! The program converts all input to uppercase automatically before processing.
How do I save/load files?
Use menu options 3 and 4. Provide the filename when prompted, and the program will handle file operations.
Is this project open source?
Yes! This project is licensed under the MIT License. Contributions are welcome!
Contribute
Help improve the Morse Code Converter by contributing to the project.
How to Contribute
We welcome contributions from the community! Here's how you can help:
- Report bugs and issues
- Suggest new features
- Improve documentation
- Submit pull requests with code improvements
CONTRIBUTING.md in the repository for detailed guidelines.