Hello Everyone,
I am trying to code, in C++, a program that will convert user input into Morse code. The mappings for the morse code will be received from two separate files, and the entire program will be broken up into 4 functions:
file input- if the file is not opened properly, there should be an error message to let the user know otherwise.
Character translation
the primary procession loop-that will read in the cin from the user and translate into Morse code
the main function
The text to be translated will be received from the cin from the user, as long as "quit" has not been entered by the user. Characters
read in from cin should be folded into upper case (input of a and A should both map to the Morse
code . - character sequence. A space character should map to a space character. A character that does
not map to Morse code (such as $) should be output in double quotes (such as "$" ) to indicate that the
text was not translated. Finally, any Morse code output should be separated by a space from other
output.
There should be no global variables
Here is what I have so far, there are comments to help make the code easier to read:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
// This program will translate a string of input from the user
// and translate this input into morse code
#include <iostream>
#include <string>
#include <cstdlib>
#include <fstream>
#include <cctype>
#include <cstring>
using namespace std;
string fileIO(string morsecode[], char morseletter[]);
// This will be the program that reads the information from the files and verifies that it opened properly
string charTranslate();
// This program should translate the input from the user into morse code, according to the file input
string getFromUser();
// this will recieve input from the user, fold all the characters to their uppercase value,
// and then pass it on to the function that will translate to morse code
int main()
{
string morsecode[50];
char morseletter[50];
//arrays in main.. and you need to pass them to functions
fileIO(morsecode,morseletter);
//print out the arrays and makes sure they match the file
getFromUser();
charTranslate();
return 0;
}
string fileIO(string morsecode[], char morseletter[])
// this function will ask for the name of the file from the user and fill both arrays with the proper values.
// the first array will be filled with the characters, the second will hold the equivalent morse code translation.
// this function will return both arrays for later use?
{
// the file has been opened, and this series of statements will verify whether the file was opened or not.
ifstream file;
string name;
cout << "Enter in the name of the input file that contains the mappings " << endl;
cin >> name;
file.open(name.c_str());
if (file.fail())
{
cout << "The file could not be opened." << endl;
}
// this is the part where the arrays are filled with their respective values
int numlines;
file >> numlines;
/*
// this should contain the chars to be translated
char* morseletter = new char[numlines];
// this should contain the strings of morse code
string * morsecode = new string[numlines];
*/
for (int i = 0; i < numlines; i++) {
file >> morseletter[i];
getline(file, morseletter[i], " ");
file >> morsecode[i];
getline(morsecode[i]);
/*
getline(file, morseletter[i]," "); //delimit by space.
getline(morsecode[i]);
*/
}
file.close();
return 0;
// this function will return back to function main so that the program can continue.
}
string getFromUser()
// this function will receive the sentence to be translated from the user.
// if the sentence is not "quit", the function will pass this input onto the translator function.
// if the sentence is "quit", the function will end.
// this function will also fold all the lower case values to their uppercase values
{
string input;
cout << "Enter the string to be translated (or quit to exit)" << endl;
getline(cin, input);
// this is where the function will receive the input to be translated from the user
// the string obtained must be folded up to uppercase letters.
// this is where we will validate the phrase, either to continue the program, or end it.
if (input == "quit")
{
return 0;// end the program
}
return 0;
}
string charTranslate()
// this function will translate the input from the user into the proper morse code.
// if the character to be translated cannot be found in the file, this function will
// print out the character surrounded by quotation marks.
// ex. 2 will be "2" if 2 cannot be found from the input file.
{
return 0;
}
|
I realize this isn't much, but I could really use some help with this.