Algorithm Help

Hello, I've been assigned an encoding/decoding project and I have not the slightest clue how I should start; I have a piece of code written, but i'm not sure if i'm working in the right direction. Can someone please help? I must take a user string input, turn it into capital letters, remove punctuation and whitespace, then place it into a six by six grid without having any letters repeat. If the grid does not fill all the way through, the remaining places should be used up by #'s 0-9 and any unused letter. Below is an example and what I have so far and and example grid/user input, which is not much :(

Example:

Phrase- "The Quick Brown Fox Jumps over the Lazy Dog"

grid-

T H E Q U I
C K B R O W
N F X J M P
S V L A Z Y
D G 0 1 2 3
4 5 6 7 8 9

#include <iostream>
#include <vector>
#include <fstream>
#include <string>
using namespace std;

int main(void)
{
string output;
string dotTxt;
int size;
string white;
int first;
cout << "Name of file to encode: ";
cin >> output;
dotTxt = output.substr(output.size()-4, 4);
if(dotTxt != ".txt")
{
return 0;
}

string keyphrase;
string standard = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
cout << "Keyphrase: ";
cin.ignore();
getline(cin, keyphrase);
int keySize = keyphrase.size();
char keyChar[10000];
int keyNum[10000];
for(int i = 0; i < keySize; i++)
{
keyChar[i] = keyphrase[i]; //takes string and assigns them into array as characters
keyNum[i] = keyChar[i]; //takes array of characters and turns them into array of integers
if(keyNum[i] >= 97 && keyNum[i] <= 122) //capitalizes letters
{
keyNum[i] = keyNum[i] - 32;
keyChar[i] = keyNum[i];
}
cout << keyChar[i] << " " << keyNum[i] << "\n";
}

/*ofstream newFile;
newFile.open(output);
//Put what needs to be in file here; encoded code.
newFile.close();*/

system("pause");
return 0;
}
Last edited on
You dont have to make a grid to display a sentence on the screen...unless you want it to display like that. And to make the letters capital you can use the "touper" command.
I intend to place the final phrase into an array, ive edited it once more to remove the unnecessary vector grid; thank you, i'll try the command
Topic archived. No new replies allowed.