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 106 107
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void getFile (ifstream&, ofstream&, string);
void getNum (int&);
void shiftString (int&, string, ifstream&, ofstream&);
void stringFlip (int&, string);
void printEncode (string, ofstream&);
int main()
{
// Declare vaiables
ifstream dataIn;
ofstream dataOut;
string stringInput;
int userChoice;
string outputStringShift;
// Call Functions
getFile (dataIn, dataOut, stringInput);
getNum (userChoice);
shiftString (userChoice, stringInput, dataIn, dataOut);
stringFlip (userChoice, stringInput);
return 0;
}
void getFile (ifstream& inData, ofstream& outData, string inputString)
{
// Call file
inData.open("plaintext.txt");
// Check that open succeeded
if(inData.fail())
{
cout << "Failed to open file!" << endl;
exit(1);
}
// Extract data
inData >> inputString;
// Continue to extract data until file is done
while(!inData.eof())
{
inData >> inputString;
}
}
// Parameters: an int reference parameter to get users choice
// Returns: none
// Description: gets users choice
void getNum (int& userNum)
{
cout << "Please enter the number of letters you want the encoder to be based off of" << endl;
cin >> userNum;
}
// Parameters: int reference parameter of users choice
// Returns:
// Description: program to shift the letters of the input
void shiftString (int& userNum, string inputString, ifstream& inData, ofstream& outData)
{
int i = 0;
// know I need some loop here - not sure what
while (i < inputString.length());
{
inputString[i] = int(inputString[i]) + userNum;
i ++;
cout << inputString;
}
}
// Parameters: int reference parameter of users choice
// Returns:
// Description: program to reverse the letters of the input (after they have been shifted)
void stringFlip (int& userNum, string inputString)
{
int i = 0;
while (i < inputString.length());
{
inputString = string (inputString.rbegin(), inputString.rend());
cout << inputString;
}
}
// Parameters:
// Returns:
// Description: write encoded text to an output file
void printEncript (string inputString, ofstream& outData)
{
outData << inputString;
}
|