Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GOT IT NIGGA
- //Zachary Mitchell
- //Period 5
- //C++ Class Project
- #include <string> // so i can declare strings
- #include <sstream> // for my stringstreams<3
- #include <iostream> // for cout/cin
- #include <fstream>
- using namespace std; // so i dont have to use the obnoxious std:: on every other line
- //global variables
- string stringHolder = "";
- string arr[3];
- double arr2[3];
- double option;
- char charHolder[256];
- int count;
- //my class
- class Ascii {
- public:
- //outputs the options
- void output() {
- cout<< "1Encrypt-2Decrypt-3Both" << endl;
- cin >> option;
- cout << endl << "Enter String(Dont make it longer than four words):";
- cin.ignore();
- getline(cin,stringHolder);
- }
- //breaks string into words
- void stringBreaker() {
- int i = 0;
- stringstream ssin(stringHolder);
- while (ssin.good() && i < 4){
- ssin >> arr[i];
- ++i;
- }
- for(i = 0; i < 4; i++) {
- cout << arr[i] << endl;
- }
- }
- //will output both encrypted and decrypted versions
- string all() {
- stringBreaker();
- return (arr[0], arr[1], arr[2], arr[3]);
- }
- //encrypts to ascii
- void encrypt() {
- int count2 = -1;
- cout << "Before String Breaker:"<<endl;
- stringBreaker();
- cout <<"Before Char Breaker:"<< endl;
- charBreaker();
- while(count2 <= 256) {
- count2++;
- if(charHolder[count2] == 'a') {
- charHolder[count2] == '1';
- }
- cout << " " << charHolder[count2];
- }
- }
- //decrypts from ascii
- void decrypt() {
- stringBreaker();
- }
- //breaks string into char[]
- void charBreaker() {
- int count=stringHolder.size();
- for (int a=0;a<count;a++)
- {
- charHolder[a]=stringHolder[a];
- }
- }
- //saves data to .txt
- void saveData() {
- ofstream myfile;
- myfile.open ("4 word string.txt");
- myfile << "Pre encyrption: " << arr[0] << endl << arr[1] << endl << arr[2] << endl << arr[3] << endl << endl << endl << endl;
- myfile << "After encyrption: " << arr2[0] << endl << arr2[1] << endl << arr[22] << endl << arr2[3];
- myfile.close();
- }
- private:
- //you dont have privates
- };
- int main() {
- //local variables
- string output;
- Ascii ascii;
- //output
- ascii.output();
- //checking option to see what to do
- if (option == 1) {
- ascii.encrypt();
- } else if(option == 2) {
- ascii.decrypt();
- } else {
- ascii.all();
- }
- //pause then, then save, then close
- system("Pause");
- ascii.saveData();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment