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