Guest User

Untitled

a guest
May 19th, 2014
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <string>
  2. #include <sstream>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6.     //global variables
  7.     string stringHolder = "";
  8.     string arr[4];
  9.     double option;
  10.  
  11. class Ascii {
  12.  
  13. public:
  14.     //outputs the options
  15.     void output() {
  16.         cout<< "1Encrypt-2Decrypt-3Both" << endl;
  17.         cin >> option;
  18.         cout << endl << "Enter String(Dont make it longer than four words):";
  19.         cin.ignore();
  20.         getline(cin,stringHolder);
  21.     }
  22.     //breaks string into words
  23.     void stringBreaker() {
  24.         int i = 0;
  25.         stringstream ssin(stringHolder);
  26.         while (ssin.good() && i < 4){
  27.         ssin >> arr[i];
  28.         ++i;
  29.     }
  30.         for(i = 0; i < 4; i++) {
  31.              cout << arr[i] << endl;
  32.         }
  33.     }
  34.  
  35.     //breaks string into char array
  36.     void charBreaker() {
  37.  
  38.     }
  39.     //will output both encrypted and decrypted versions
  40.     string all() {
  41.         stringBreaker();
  42.         return (arr[1], " ", arr[2], " ", arr[3], " ", arr[4]);
  43.     }
  44.     //encrypts to ascii
  45.     string encyrpt() {
  46.         stringBreaker();
  47.         return (arr[1], " ", arr[2], " ", arr[3], " ", arr[4]);
  48.     }
  49.     //decrypts from ascii
  50.     string decrypt() {
  51.                 stringBreaker();
  52.         return (arr[1], " ", arr[2], " ", arr[3], " ", arr[4]);
  53.     }
  54.  
  55.     private:
  56.     //you dont have privates
  57.     };
  58.  
  59. int main() {
  60.     //local variables
  61.     string result;
  62.     string output;
  63.     Ascii ascii;
  64.  
  65.     //output
  66.     ascii.output();
  67.  
  68.     if (option == 1) {
  69.             result = ascii.encyrpt();
  70.     } else if(option == 2) {
  71.             result = ascii.decrypt();
  72.     } else {
  73.         result = ascii.all();
  74.     }
  75.     cout << "Result " << result;
  76.     system("Pause");
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment