SlideShare a Scribd company logo
1 of 4
// 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

What's hot

VI Editors
VI EditorsVI Editors
VI Editors
Deivanai
 
1.3 core programming [identify the appropriate method for handling repetition]
1.3 core programming [identify the appropriate method for handling repetition]1.3 core programming [identify the appropriate method for handling repetition]
1.3 core programming [identify the appropriate method for handling repetition]
tototo147
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Yandex
 
Strinng Classes in c++
Strinng Classes in c++Strinng Classes in c++
Strinng Classes in c++
Vikash Dhal
 

What's hot (20)

caeser chiper
caeser chiper caeser chiper
caeser chiper
 
How To VIM
How To  VIMHow To  VIM
How To VIM
 
Groovy closures
Groovy closuresGroovy closures
Groovy closures
 
VI Editors
VI EditorsVI Editors
VI Editors
 
1.3 core programming [identify the appropriate method for handling repetition]
1.3 core programming [identify the appropriate method for handling repetition]1.3 core programming [identify the appropriate method for handling repetition]
1.3 core programming [identify the appropriate method for handling repetition]
 
Chap03[1]
Chap03[1]Chap03[1]
Chap03[1]
 
Introducing Rust
Introducing RustIntroducing Rust
Introducing Rust
 
Introducing Rust
Introducing RustIntroducing Rust
Introducing Rust
 
T@xi
T@xiT@xi
T@xi
 
05 c++-strings
05 c++-strings05 c++-strings
05 c++-strings
 
Lec 36 - pointers
Lec 36 -  pointersLec 36 -  pointers
Lec 36 - pointers
 
Vi CheatSheet
Vi CheatSheetVi CheatSheet
Vi CheatSheet
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
 
Vim For Php
Vim For PhpVim For Php
Vim For Php
 
String.ppt
String.pptString.ppt
String.ppt
 
How To Define An Integer Constant In C
How To Define An Integer Constant In CHow To Define An Integer Constant In C
How To Define An Integer Constant In C
 
Format String Vulnerability
Format String VulnerabilityFormat String Vulnerability
Format String Vulnerability
 
Strinng Classes in c++
Strinng Classes in c++Strinng Classes in c++
Strinng Classes in c++
 
Logging in JavaScript - part-2
Logging in JavaScript - part-2Logging in JavaScript - part-2
Logging in JavaScript - part-2
 
String handling
String handlingString handling
String handling
 

Viewers also liked (9)

Dctv co op report
Dctv co op reportDctv co op report
Dctv co op report
 
Good Business Symposium
Good Business SymposiumGood Business Symposium
Good Business Symposium
 
Virus komputer
Virus komputer Virus komputer
Virus komputer
 
Tugasmulokxii ipa4cpu-120129064945-phpapp01
Tugasmulokxii ipa4cpu-120129064945-phpapp01Tugasmulokxii ipa4cpu-120129064945-phpapp01
Tugasmulokxii ipa4cpu-120129064945-phpapp01
 
Final cal
Final calFinal cal
Final cal
 
Industrial design killian vigna
Industrial design killian vignaIndustrial design killian vigna
Industrial design killian vigna
 
Requirements engineering 1st assignment
Requirements engineering 1st assignmentRequirements engineering 1st assignment
Requirements engineering 1st assignment
 
Instalasi Windows 7
Instalasi Windows 7Instalasi Windows 7
Instalasi Windows 7
 
The musical influence on fashion and design of clothing over the 20th century
The musical influence on fashion and design of clothing over the 20th centuryThe musical influence on fashion and design of clothing over the 20th century
The musical influence on fashion and design of clothing over the 20th century
 

Similar to Killian Vigna Morse code

The Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdfThe Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
bhim1213
 
Programming - Marla Fuentes
Programming - Marla FuentesProgramming - Marla Fuentes
Programming - Marla Fuentes
mfuentessss
 
Can anyone fix this code, I use Visual StudiosThe Errors im getti.pdf
Can anyone fix this code, I use Visual StudiosThe Errors im getti.pdfCan anyone fix this code, I use Visual StudiosThe Errors im getti.pdf
Can anyone fix this code, I use Visual StudiosThe Errors im getti.pdf
arjunhassan8
 
Final requirement (2)
Final requirement (2)Final requirement (2)
Final requirement (2)
Anjie Sengoku
 
Rust-lang
Rust-langRust-lang
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
aksachdevahosymills
 
Start with the inclusion of libraries#include iostream .docx
 Start with the inclusion of libraries#include iostream .docx Start with the inclusion of libraries#include iostream .docx
Start with the inclusion of libraries#include iostream .docx
MARRY7
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
aassecuritysystem
 
Write a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdfWrite a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdf
jillisacebi75827
 
IT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdf
IT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdfIT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdf
IT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdf
DhanuskarSankar1
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
JawadTanvir
 

Similar to Killian Vigna Morse code (20)

Beyond javascript using the features of tomorrow
Beyond javascript   using the features of tomorrowBeyond javascript   using the features of tomorrow
Beyond javascript using the features of tomorrow
 
Rustlabs Quick Start
Rustlabs Quick StartRustlabs Quick Start
Rustlabs Quick Start
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdfThe Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
 
Programming - Marla Fuentes
Programming - Marla FuentesProgramming - Marla Fuentes
Programming - Marla Fuentes
 
For this project, you must complete the provided partial C++ program.pdf
For this project, you must complete the provided partial C++ program.pdfFor this project, you must complete the provided partial C++ program.pdf
For this project, you must complete the provided partial C++ program.pdf
 
Can anyone fix this code, I use Visual StudiosThe Errors im getti.pdf
Can anyone fix this code, I use Visual StudiosThe Errors im getti.pdfCan anyone fix this code, I use Visual StudiosThe Errors im getti.pdf
Can anyone fix this code, I use Visual StudiosThe Errors im getti.pdf
 
Final requirement (2)
Final requirement (2)Final requirement (2)
Final requirement (2)
 
Rust-lang
Rust-langRust-lang
Rust-lang
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
 
Formatted Console I/O Operations in C++
Formatted Console I/O Operations in C++Formatted Console I/O Operations in C++
Formatted Console I/O Operations in C++
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Start with the inclusion of libraries#include iostream .docx
 Start with the inclusion of libraries#include iostream .docx Start with the inclusion of libraries#include iostream .docx
Start with the inclusion of libraries#include iostream .docx
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
 
Write a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdfWrite a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdf
 
IT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdf
IT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdfIT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdf
IT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdf
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
 
String searching
String searchingString searching
String searching
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
 
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
 

More from Killian Vigna

Project Management and Practice
Project Management and PracticeProject Management and Practice
Project Management and Practice
Killian Vigna
 
Applied Interaction Design - Balanced University Lifestyle (P2)
Applied Interaction Design - Balanced University Lifestyle (P2)Applied Interaction Design - Balanced University Lifestyle (P2)
Applied Interaction Design - Balanced University Lifestyle (P2)
Killian Vigna
 
Applied Interaction Design - Balanced University Lifestyle (P1)
Applied Interaction Design - Balanced University Lifestyle (P1)Applied Interaction Design - Balanced University Lifestyle (P1)
Applied Interaction Design - Balanced University Lifestyle (P1)
Killian Vigna
 
The Production Process of a Video Campaign for The UL Vikings Club.
The Production Process of a Video Campaign for The UL Vikings Club.The Production Process of a Video Campaign for The UL Vikings Club.
The Production Process of a Video Campaign for The UL Vikings Club.
Killian Vigna
 
Role of the Working Mother
Role of the Working MotherRole of the Working Mother
Role of the Working Mother
Killian Vigna
 
Protectourwater.ie SRS
Protectourwater.ie SRSProtectourwater.ie SRS
Protectourwater.ie SRS
Killian Vigna
 
Design visualisation power point
Design visualisation power pointDesign visualisation power point
Design visualisation power point
Killian Vigna
 
Design Visualisation - Redesign Project
Design Visualisation - Redesign ProjectDesign Visualisation - Redesign Project
Design Visualisation - Redesign Project
Killian Vigna
 
Cs4044 final mix report
Cs4044 final mix reportCs4044 final mix report
Cs4044 final mix report
Killian Vigna
 
Last minute decisions 'Chubby-Checker 3000'
Last minute decisions   'Chubby-Checker 3000'Last minute decisions   'Chubby-Checker 3000'
Last minute decisions 'Chubby-Checker 3000'
Killian Vigna
 
The Abuse Of Sporting Supplements Amongst Adolescents
The Abuse Of Sporting Supplements Amongst AdolescentsThe Abuse Of Sporting Supplements Amongst Adolescents
The Abuse Of Sporting Supplements Amongst Adolescents
Killian Vigna
 
Interaction Design Project
Interaction Design ProjectInteraction Design Project
Interaction Design Project
Killian Vigna
 
Computer Aided Learning
Computer Aided LearningComputer Aided Learning
Computer Aided Learning
Killian Vigna
 

More from Killian Vigna (13)

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

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

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"; }