SlideShare a Scribd company logo
// Killian Vigna (10129758)
// This program will help you with your first project.

#include   <iostream>
#include   <iomanip>
#include   <string>
#include   <windows.h>
#include   <algorithm>

using namespace std;

// Declare a structure of 2 parts - Character and string.
struct Code{
      char letter;
      stringmorse;
};

// Array of the structure Code.
Code convert[] ={
      { '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', "--.. " },{ '0', "---- " },
      { '1', ".--- " },{ '2', "..--- "},{ '3', "...-- "},
      { '4', "....- "},{ '5', "..... "},{ '6', "-.... "},
      { '7', "--... "},{ '8', "---.. " },{ '9', "----. "},
      { '.', ".-.-.- "},{ ',', "--..-- "},{ '?', "..--.. "}
};

voidconvert_to_morse(string); // This function uses the string type.
voidmorse_out(string);              // Performs the beeping.
voidmorse_to_text();           // Converts string entered to text
voidtext_to_morse();                // Converts string entered to Morse

voidconvert_to_text(string);     // Uses string type, function prototype


int main ()
{
      int menu;
      int num1, num2;
      string text;

      while(1)
      {
            // Menu on screen outputs
            cout<< "What is your Selection: n";
            cout<< " 1 - Convert Text to Morse: n";
            cout<< " 2 - Convert Morse to Text: n";
            cout<< " 3 - Exit nn";

              cin>> menu;

              // Output of selected menu option
              switch (menu)
              {
case 1: cout<<"Convert Text to Morse Selected: ";
                  cout<<"Enter Your Conversion: ";
                         cin>> text;
                         convert_to_morse(text);
                         break;
            case 2: cout<<"Convert Morse to Text Selected: ";
                  cin>> text;
                  morse_to_text();
                  break;
            case 3: return 0;
                  break;

            }
     }


     system("pause");
     // terminate program
     return 0;
}

voidtext_to_morse()
{
             // we loop until the menu is processed
            string text;

            // The next 4 lines use the structure (Code) above to convert
to morse code.
            cout<< "Enter a string to convert to Morse Code: " ;

            fflush(stdin);
            getline(cin, text);

            // The function below performs the conversion to Morse
            convert_to_morse(text);

}

// the functions below convert text to morse using the structure Code
above.
voidconvert_to_morse(string s)
{
       unsignedinti, j;

      // step through character by character up to length of input string s
      for ( i = 0; i<s.length(); i++ )
      {
            // only 54 characters in the structure...expand this
            for ( j = 0; j < 54; j++ )
            {
                  // Convert characters in s to uppercase before checking
for them
                  if ( toupper(s[i]) == convert[j].letter )
                  {
                        morse_out(convert[j].morse); // display morse code
of letter
                        break;
                  }
            }
      }
cout<< "n";
}

voidmorse_out(string str)
{
      int x;
      charch;

      for (x = 0; x!= str.length(); x++) // keep going until the end
(length) is reached
      {
            ch = str[x];
            cout<<ch;    // Display on screen;

            // Shows the compiler the size and length of output
            switch(ch)
            {
                  case '.': Beep(523, 200);
                                     Sleep(100);
                        break;
                  case '-':    Beep(700, 400);
                                     Sleep(100);
                        break;
                  case ' ':
                                     cout<< " ";
                                     Sleep(700);
                        break;


            }
      }
}

// Part two: Morse - Text
voidmorse_to_text()
{
      stringmorse;

      cout<< "Enter a string to convert to Morse Code: " ;

      fflush(stdin);
      getline(cin, morse);

      if (morse[morse.length() - 1] != ' ')
            morse = morse + " ";

      // the variable starts by pointing to the beginning of the input
mores string
      //use the compare method to compare the inoutmorse string against
what tou have stored in the convert structure

      convert_to_text(morse);
}

      // insert code here for comparing morse
voidconvert_to_text(string s)
{
      unsignedint a, b;


      //step through all charachters in the structure
for ( a = 0; a <s.length(); )
      {
            for( b = 0; b < 54; b++)

             {
                    //convert the characters in b to uppercase before you
check them

                  if(s.compare(a, convert[b].morse.length(),
convert[b].morse) == 0)
                  {
                        a = a + convert[b].morse.length();
                        // this moved past the matching morse string and on
to the next one

                          cout<< convert[b].letter;
                          //display letter

                          break;
                          // Ends output
                    }
             }
      }
      cout<<"n";
}

More Related Content

PDF
Javascript foundations: scope
PPT
Lec 38.39 - pointers
PDF
Manipulating strings
PDF
Степан Кольцов — Rust — лучше, чем C++
PDF
Computer Security (Cryptography) Ch02
PDF
Promises generatorscallbacks
PPT
Lec 37 - pointers
PDF
F# delight
Javascript foundations: scope
Lec 38.39 - pointers
Manipulating strings
Степан Кольцов — Rust — лучше, чем C++
Computer Security (Cryptography) Ch02
Promises generatorscallbacks
Lec 37 - pointers
F# delight

What's hot (20)

PPTX
caeser chiper
PPTX
How To VIM
PPTX
Groovy closures
PPT
VI Editors
PPTX
1.3 core programming [identify the appropriate method for handling repetition]
PDF
Introducing Rust
PDF
Introducing Rust
TXT
PDF
05 c++-strings
PPT
Lec 36 - pointers
PDF
Vi CheatSheet
PDF
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
PDF
Vim For Php
PDF
String.ppt
DOC
How To Define An Integer Constant In C
PDF
Format String Vulnerability
PDF
Strinng Classes in c++
PDF
Logging in JavaScript - part-2
PPTX
String handling
caeser chiper
How To VIM
Groovy closures
VI Editors
1.3 core programming [identify the appropriate method for handling repetition]
Introducing Rust
Introducing Rust
05 c++-strings
Lec 36 - pointers
Vi CheatSheet
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Vim For Php
String.ppt
How To Define An Integer Constant In C
Format String Vulnerability
Strinng Classes in c++
Logging in JavaScript - part-2
String handling
Ad

Viewers also liked (9)

PDF
Dctv co op report
PDF
Good Business Symposium
PPT
Virus komputer
PPT
Tugasmulokxii ipa4cpu-120129064945-phpapp01
ODT
Final cal
PPTX
Industrial design killian vigna
PDF
Requirements engineering 1st assignment
PPTX
Instalasi Windows 7
PDF
The musical influence on fashion and design of clothing over the 20th century
Dctv co op report
Good Business Symposium
Virus komputer
Tugasmulokxii ipa4cpu-120129064945-phpapp01
Final cal
Industrial design killian vigna
Requirements engineering 1st assignment
Instalasi Windows 7
The musical influence on fashion and design of clothing over the 20th century
Ad

Similar to Killian Vigna Morse code (20)

PDF
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
PPT
Computer Programming- Lecture 6
PPT
Week7.ppt
PPT
Basics of c++
PDF
C reference manual
PPTX
Programming - Marla Fuentes
PDF
In Java Write a program that reads an English language phrase and en.pdf
PPTX
PPTX
Final requirement (2)
PDF
C++primer
PDF
C++ Quick Reference Sheet from Hoomanb.com
PPT
sav_ch09.ppt
PPTX
Demystifying Unicode - Longhorn PHP 2021
PDF
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
PPT
Savitch ch 08
PDF
Chapter 5
PDF
Data structures / C++ Program examples
PDF
2 1. variables & data types
PPT
Savitch Ch 08
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
Computer Programming- Lecture 6
Week7.ppt
Basics of c++
C reference manual
Programming - Marla Fuentes
In Java Write a program that reads an English language phrase and en.pdf
Final requirement (2)
C++primer
C++ Quick Reference Sheet from Hoomanb.com
sav_ch09.ppt
Demystifying Unicode - Longhorn PHP 2021
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
Savitch ch 08
Chapter 5
Data structures / C++ Program examples
2 1. variables & data types
Savitch Ch 08

More from Killian Vigna (13)

PDF
Project Management and Practice
PDF
Applied Interaction Design - Balanced University Lifestyle (P2)
PDF
Applied Interaction Design - Balanced University Lifestyle (P1)
PDF
The Production Process of a Video Campaign for The UL Vikings Club.
PPTX
Role of the Working Mother
DOCX
Protectourwater.ie SRS
ODP
Design visualisation power point
PPTX
Design Visualisation - Redesign Project
PDF
Cs4044 final mix report
PDF
Last minute decisions 'Chubby-Checker 3000'
PDF
The Abuse Of Sporting Supplements Amongst Adolescents
DOCX
Interaction Design Project
DOCX
Computer Aided Learning
Project Management and Practice
Applied Interaction Design - Balanced University Lifestyle (P2)
Applied Interaction Design - Balanced University Lifestyle (P1)
The Production Process of a Video Campaign for The UL Vikings Club.
Role of the Working Mother
Protectourwater.ie SRS
Design visualisation power point
Design Visualisation - Redesign Project
Cs4044 final mix report
Last minute decisions 'Chubby-Checker 3000'
The Abuse Of Sporting Supplements Amongst Adolescents
Interaction Design Project
Computer Aided Learning

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Big Data Technologies - Introduction.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Empathic Computing: Creating Shared Understanding
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Approach and Philosophy of On baking technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Electronic commerce courselecture one. Pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPT
Teaching material agriculture food technology
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Cloud computing and distributed systems.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Building Integrated photovoltaic BIPV_UPV.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Unlocking AI with Model Context Protocol (MCP)
Big Data Technologies - Introduction.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MYSQL Presentation for SQL database connectivity
Empathic Computing: Creating Shared Understanding
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation_ Review paper, used for researhc scholars
Approach and Philosophy of On baking technology
Network Security Unit 5.pdf for BCA BBA.
20250228 LYD VKU AI Blended-Learning.pptx
Electronic commerce courselecture one. Pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Teaching material agriculture food technology
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Review of recent advances in non-invasive hemoglobin estimation
Cloud computing and distributed systems.

Killian Vigna Morse code

  • 1. // Killian Vigna (10129758) // This program will help you with your first project. #include <iostream> #include <iomanip> #include <string> #include <windows.h> #include <algorithm> using namespace std; // Declare a structure of 2 parts - Character and string. struct Code{ char letter; stringmorse; }; // Array of the structure Code. Code convert[] ={ { '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', "--.. " },{ '0', "---- " }, { '1', ".--- " },{ '2', "..--- "},{ '3', "...-- "}, { '4', "....- "},{ '5', "..... "},{ '6', "-.... "}, { '7', "--... "},{ '8', "---.. " },{ '9', "----. "}, { '.', ".-.-.- "},{ ',', "--..-- "},{ '?', "..--.. "} }; voidconvert_to_morse(string); // This function uses the string type. voidmorse_out(string); // Performs the beeping. voidmorse_to_text(); // Converts string entered to text voidtext_to_morse(); // Converts string entered to Morse voidconvert_to_text(string); // Uses string type, function prototype int main () { int menu; int num1, num2; string text; while(1) { // Menu on screen outputs cout<< "What is your Selection: n"; cout<< " 1 - Convert Text to Morse: n"; cout<< " 2 - Convert Morse to Text: n"; cout<< " 3 - Exit nn"; cin>> menu; // Output of selected menu option switch (menu) {
  • 2. case 1: cout<<"Convert Text to Morse Selected: "; cout<<"Enter Your Conversion: "; cin>> text; convert_to_morse(text); break; case 2: cout<<"Convert Morse to Text Selected: "; cin>> text; morse_to_text(); break; case 3: return 0; break; } } system("pause"); // terminate program return 0; } voidtext_to_morse() { // we loop until the menu is processed string text; // The next 4 lines use the structure (Code) above to convert to morse code. cout<< "Enter a string to convert to Morse Code: " ; fflush(stdin); getline(cin, text); // The function below performs the conversion to Morse convert_to_morse(text); } // the functions below convert text to morse using the structure Code above. voidconvert_to_morse(string s) { unsignedinti, j; // step through character by character up to length of input string s for ( i = 0; i<s.length(); i++ ) { // only 54 characters in the structure...expand this for ( j = 0; j < 54; j++ ) { // Convert characters in s to uppercase before checking for them if ( toupper(s[i]) == convert[j].letter ) { morse_out(convert[j].morse); // display morse code of letter break; } } }
  • 3. cout<< "n"; } voidmorse_out(string str) { int x; charch; for (x = 0; x!= str.length(); x++) // keep going until the end (length) is reached { ch = str[x]; cout<<ch; // Display on screen; // Shows the compiler the size and length of output switch(ch) { case '.': Beep(523, 200); Sleep(100); break; case '-': Beep(700, 400); Sleep(100); break; case ' ': cout<< " "; Sleep(700); break; } } } // Part two: Morse - Text voidmorse_to_text() { stringmorse; cout<< "Enter a string to convert to Morse Code: " ; fflush(stdin); getline(cin, morse); if (morse[morse.length() - 1] != ' ') morse = morse + " "; // the variable starts by pointing to the beginning of the input mores string //use the compare method to compare the inoutmorse string against what tou have stored in the convert structure convert_to_text(morse); } // insert code here for comparing morse voidconvert_to_text(string s) { unsignedint a, b; //step through all charachters in the structure
  • 4. for ( a = 0; a <s.length(); ) { for( b = 0; b < 54; b++) { //convert the characters in b to uppercase before you check them if(s.compare(a, convert[b].morse.length(), convert[b].morse) == 0) { a = a + convert[b].morse.length(); // this moved past the matching morse string and on to the next one cout<< convert[b].letter; //display letter break; // Ends output } } } cout<<"n"; }