Morse Code Converter

A lightweight C++ utility that converts text to Morse code and vice versa. Perfect for learning, amateur radio enthusiasts, and developers.

HELLO WORLD
.... . .-.. .-.. --- / .-- --- .-. .-.. -..

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

Terminal Commands
git clone https://github.com/HarshYadav152/Morse-Code.git
cd Morse-Code
g++ -std=c++17 MorseCodeConverter.cpp -O2 -o morse

Using Makefile

Make Commands
make        # Build the project
make run    # Build and run
make clean  # Remove build artifacts
Note: On Windows, use MinGW or WSL for compilation.

Usage

Learn how to use the Morse Code Converter effectively.

Running the Program

Command Line
./morse

Interactive Menu

After running the program, you'll see this menu:

Program Output
====== 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

C++ Code
MorseConverter();

Initializes the converter with Morse code mappings.

Methods

textToMorse()

C++ Code
string textToMorse(const string& text);

Description: Converts plain text to Morse code.

Parameters: text - Input text string

Returns: Space-separated Morse code

morseToText()

C++ Code
string morseToText(const string& morse);

Description: Converts Morse code back to text.

Parameters: morse - Space-separated Morse code

Returns: Decoded text string

saveToFile()

C++ Code
void saveToFile(const string& filename, const string& content);

Description: Saves content to a file.

Parameters: filename - Output file path, content - Text to save

loadFromFile()

C++ Code
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 & Output
Input:  HELLO WORLD
Output: .... . .-.. .-.. --- / .-- --- .-. .-.. -..

Morse to Text

Input & Output
Input:  .... . .-.. .-.. --- / .-- --- .-. .-.. -..
Output: HELLO WORLD

With Digits

Input & Output
Input:  TEST 123
Output: - . ... - / .---- ..--- ...--

With Punctuation

Input & Output
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
Note: See CONTRIBUTING.md in the repository for detailed guidelines.