Question
You are required to create a program called MorseConvert that converts a Text string into Morse CodeLinks to an external site. (kind of).
You are required to create a program called "MorseConvert" that converts a Text string into Morse CodeLinks to an external site. (kind of). The program will not convert the text to dashes and dots but to the words "dash" and "dot".
As an example, if the program is given the text string "1" the output would be "dot dash dash dash dash" Or if the program is given the text string "123" the output would be "dot dash dash dash dash dot dot dash dash dash dot dot dot dash dash"
The file codes.dat contains a mapping of letters and numbers to the Morse Code. Please open and inspect this file.
The questions in this quiz will require you to develop parts of the code (mostly functions) and the put these parts together to develop a working program.
The following files are available (Note: To run make sure the codes.dat file is is in the same folder as the executable MoreseConvert.exe):
codes.dat-
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,--..
1,.----
2,..---
3,...--
4,....-
5,.....
6,-....
7,--...
8,---..
9,----.
0,-----
1.
Define a structure that embodies the data in one line in the file codes.dat
Also:
It can be assumed that the codes will not change therefore you should define a constant equal to the size 36 (the number of codes in the codes.dat file).
Define 2 other constants that will be used in place of the strings "dot" and "dash".
2.
The MorseConvert program will need to load the file "codes.dat" with the mappings of the letters and numbers to the Morse Code.
Develop a function that has the following signature:
bool LoadMorseCodes(Code arrCodes[], const int iTotalCount)
The function will open the file codes.dat, reads its contents and store the data in the array of "Code" structures passed to it. Finally the function should close the file before it exits.
Note: Even though there are exactly 36 codes, develop the function so that it "loops"
const int iTotalCount
times and not a hard-coded 36.
Your function must use std::string functions to parse the data. I recommend functions like find() and substr().
3.
Develop a function that has the following signature:
string GetCode(char c, Code arrCodes[], const int iTotalCount)
The job of this function is to search through the array of Codes and locate the Morse Code that corresponds to the character
char c
that is passed in as a parameter. Once the character is located the function should return a string containing the Morse code.
4.
Develop a function that has the following signature:
string ConvertCodeToDotDash(string sMorseCode)
The job of this function is to convert the Morse Code contained in
string sMorseCode
to an equivalent string containing "dots" and "dashes".
Note: that the returned string will contain the actual words "dot" and "dash" and not some other kind of codes.
5.
Develop a function that has the following signature:
void PlayMorseCode(string sDotDashCode)
The job of this function is to play an audio tone (beep) that corresponds to the "dot"s and "dash"es in the string "sDotDashCode" which contain "dot"s and "dash"es and not "-" or ".".
Your function must use std::string functions to parse the "sDotDashCode"string. I recommend functions like find(), length(), substr(), and erase().
To play a "beep (Links to an external site.)Links to an external site." on the Windows computer, use the function "
Beep(1750, 500);
To play "dot" and
Beep(750, 1000);
To play "dash".
Your program should include "Windows.h"
6.
Develop a function that has the following signature:
int main()
The job of this function is to declare an array of "Codes" as defined in the first function.
Next the function should load the codes into the array of "Codes" using the function
LoadMorsearrCodes(...)
Next prompt the user for the string to convert. Iterate over the characters in the string, converting each one to the equivalent "dot" and "dash" using the functions
GetCode(...) and ConvertCodeToDotDash(...)
to an equivalent string containing "dot"s and "dash"es.
Display the converted user input string as the dotted and dashed code.
Finally used the function
GetCode(...) and ConvertCodeToDotDash(...)
to play out the dotted and dashed code using the function
PlayMorseCode(...)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started