I am provided with a coded message, a definition list, and asked to write a program to translate the message.
And the definition list looks like this:
A = F
B = D
C = I
...and so on until the end of the alphabet
--where for every A in the coded message, it should be an F. I will store this entire list of definitions into a string named ourCode[26] so I can iterate through the message and replace letters. But how would you access the final character in an element of the string array?
For example I have "CA" and I want to replace C with I. But as I understand it, the current string array ourCode have | "A = F" | "B = D" | "C = I" | so how would I take the element "C = I", extract the I, and put that where the C in the original code line is?
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
int main() {
int size = 0;
string ourCode[26];
string ourFile;
string codedMessage, decodedMessage;
cout << "Please enter the name of your desired file: " << endl;
cin >> ourFile;
ifstream inFile;
inFile.open(ourFile);
line = "";
while (getline(inFile, line)) {
if (inFile.is_open()) { //confirm that the file is open
for (int i = 0; i < 26; i++) {
ourCode[i] = line; //take the first 26 lines as our decoder information
}
cin >> size; //how many messages there will be; stored for later printing
cin >> codedMessage;
}
else {
cerr << "File can't be opened." << endl;
delete[] Series;
exit(1);}
}
/*for now we assume there is only 1 coded message to resolve*/
int j = 0;
for (int i = 0; i < "\0"; i++) { //we will be going through our codedMessage array
if (codedMessage[i] == ourCode[j]) {
//perform the function to swap letter in ourCode with correct one provided by
//array ourCode
}
j++;
}
decodedMessage = codedMessage;
ofstream outFile;
outFile.open("result.txt");
while (outFile.is_open) {
outFile << "The number of messages are " << size << endl;
outFile << "The decoded message is " << decodedMessage << endl;
outFile.close();
}