enum command help

I have to program a Caesar Cipher for my programming class. Basically, it takes in a line: type,shift,message_text_all_lowercase (ie. e,-5,test bla bla bla)
Basically, I am on the final function that I have to write the definition for, and I cannot figure out how to tell the program to read what letter is stored in my character array in my structure and insert it into the enum string.
The problem function is "void ProcessOneLine(Line telegram[], int n)

My code:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

// Global constants
const int MAXMSG = 64; // Maximum message length
const int MAXLINES = 6; // Maximum number of message lines in telegram


// Structure declaration
struct Line // Represents one line input from file
{
char mode; // Stores mode: e = encrypt, d = decrypt
int shift; // Stores amount of alphabet shift
int length; // Number of chars in message (<= MAXMSG)
char ptext[MAXMSG]; // Stores unencrypted message (plaintext)
char ctext[MAXMSG]; // Stores encrypted message (ciphertext)
};


// Function prototypes for functions you must implement in the file project01.cpp

void OpenInputFile(string filename, ifstream& inFile, bool& status);
// OpenInputFile(...) attempts to open the given file for input. If the file
// is opened successfully, status should be set to true. Otherwise, status
// should be set to false.

void LoadOneLine(ifstream& inFile, Line telegram[], int n);
// LoadOneLine(...) attempts to load a single line of the telegram from the
// input file stream assuming that the stream has been opened successfully.
// n is the index within the telegram array where the new line should be stored.

void ProcessOneLine(Line telegram[], int n);
// ProcessOneLine(...) encrypts or decrypts the line at index n within telegram
// based upon the mode and shift values stored for that particular line.


// Function prototypes for provided functions provided
void PrintOneLine(Line telegram[], int count);



int main(int argc, char* argv[]) // Use command line arguments
{
ifstream inFile; // Input file stream variable
bool status = false; // Stores file status: true = opened successfully
string comment; // Stores line of text from input file
Line telegram[MAXLINES]; // Stores up to MAXLINES messages input from file

// Verify command line arguments present
if (argc != 2)
{
// Program usage error
cout << "Usage:\n ./project01 <inputfilenamehere>\n";
return 1;
}
else
{
// Convert command line argument into c++ string
string filename(argv[1]);

// Attempt to open file for input
OpenInputFile(filename, inFile, status);

// Verify file status
if (status) // If file opened successfully, process telegram
{
// Input and echo print comment
getline(inFile, comment);
cout << endl << comment << endl;;

// Loop to process up to MAXLINES messages from input file
int count = 0;

// Attempt to input first line of telegram array
LoadOneLine(inFile, telegram, count);

while ( inFile )
{
// Perform encryption/decryption operation
ProcessOneLine(telegram, count);

// Output processed line of input
PrintOneLine(telegram, count);

// Count processed message
count++;

// If a total of MAXLINES have been processed, then exit loop
if (count == MAXLINES)
break;

// Attempt to input next line into telegram array
LoadOneLine(inFile, telegram, count);
} // End WHILE

cout << endl;
}
else // ...else unable to open file
{
cout << "Error: unable to open file '" << filename << "' for input." << endl;
cout << "Terminating program now..." << endl;
}

return 0;
}

} // End main()


void PrintOneLine(Line telegram[], int count)
{
cout << "******************************************************************" << endl;
cout << " line: " << count+1 << endl;
cout << " mode: " << telegram[count].mode << endl;

cout << "shift: " << telegram[count].shift << endl;

cout << " ";
for(int k = 0; k < telegram[count].length; k++)
{
if (k % 10 == 0)
cout << k/10;
else
cout << ' ';
}
cout << endl;

cout << " ";
for(int k = 0; k < telegram[count].length; k++)
{
cout << k%10;
}
cout << endl;


cout << "ptext: ";
for(int k = 0; k < telegram[count].length; k++)
cout << telegram[count].ptext[k];
cout << endl;

cout << "ctext: ";
for(int k = 0; k < telegram[count].length; k++)
cout << telegram[count].ctext[k];
cout << endl;
cout << "******************************************************************" << endl;
} // End PrintOneLine()

void OpenInputFile(string filename, ifstream& inFile, bool& status)
{
inFile.open(filename.c_str());
if(!inFile)
{status=false;}
else
{status=true;}
}

void LoadOneLine(ifstream& inFile, Line telegram[], int n)
{
inFile >> telegram[].mode;
inFile.ignore(1,',');
inFile >> telegram[].shift;
inFile.ignore(1,',');
n=0;
while(inFile&&n<=MAXMSG)
{
if(telegram[].mode='e')
{
inFile >> telegram[].ptext[n];
}
if(telegram[].mode='d')
{
inFile >> telegram[].ctext[n];
}
n++;
}
}
if(n==(MAXMSG-1))
{
inFile.ignore(2000,'\n')
}
telegram[].length=n;
}

void ProcessOneLine(Line telegram[], int n)
{
enum alpha{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};
alpha standard;
standard=a;
n=0;
while(n<=telegram[].length)
{
if(telegram[].mode='e')
{
//I am stuck here!!!
}
if(telegram[].mode='d')
{
//This will be very similar to the above
}
}
That's too much code to read through.

Can you condense it to show us the concepts that you are having problems with?
Sure, I just wanted to be thorough.
Basically, I need this function definition:

void ProcessOneLine(Line telegram[], int n)
{
enum alpha{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};
alpha standard;
standard=a;
n=0;
while(n<=telegram[].length)
{
if(telegram[].mode='e')
{
//I am stuck here!!!
}
if(telegram[].mode='d')
{
//This will be very similar to the above
}
}

The structure Line telegram[] contains the following:

struct Line // Represents one line input from file
{
char mode; // Stores mode: e = encrypt, d = decrypt
int shift; // Stores amount of alphabet shift
int length; // Number of chars in message (<= MAXMSG)
char ptext[MAXMSG]; // Stores unencrypted message (plaintext)
char ctext[MAXMSG]; // Stores encrypted message (ciphertext)
};

Basically, the previous function takes one line of code in the format
e,-5,message bla bla bla \n
and stores e into telegram.mode, the integer into telegram[].shift, the length of the message (<=64 characters) into telegram.length[], and each character of the message into the array ctext or ptext.
In the function I am having trouble with, I cannot figure out how to take the alphabetic character stored into ptext or ctext and feed it into the enum function, then shift it forward or backward by telegram[].shift, then put it back into the ptext or ctext.
Any help would be greatly appreciated!!!!
closed account (DSLq5Di1)
albrittbrat wrote:
I cannot figure out how to take the alphabetic character stored into ptext or ctext and feed it into the enum function

To translate character literals 'a' to 'z' into an index,
'a' - 'a' = 0
'b' - 'a' = 1
'c' - 'a' = 2

and so on..
wow, I feel so stupid right now...
Thank you!!!! =D
Topic archived. No new replies allowed.