#include <iostream>
#include <unistd.h>
#include <stdlib.h>
#include <sstream>
#include <string>
using namespace std;

void lpp (string msg){
 string imsg = msg;
 const char* E = "echo \"";
 const char* L = "\" | lp  ";  
 string total = string(E) + string(imsg) + string(L);
 //cout << total << "\n\n";
 const char* cmd = total.c_str();
 system(cmd);
}
 
int main(int argc, char** argv)
{
    int opt;
    string input = "";
    bool flagA = false;
    bool flagB = false;
    // Retrieve the (non-option) argument:
    if ( (argc <= 1) || (argv[argc-1] == NULL) || (argv[argc-1][0] == '-') )
       {    // there is NO input...
           cerr << "No argument provided!" << endl;
           //return 1;
       }
    else
       {  // there is an input...
          input = argv[argc-1];
       }
 
    // Debug:
    cout << "input = " << input << endl;
    // Shut GetOpt error messages down (return '?'):
    opterr = 0;
    // Retrieve the options:
    while ( (opt = getopt(argc, argv, "ab")) != -1 ) {  // for each option...
        switch ( opt ) {
            case 'a':
                    flagA = true;
                break;
            case 'b':
                    flagB = true;
                break;
            case '?':  // unknown option...
                    cerr << "Unknown option: '" << char(optopt) << "'!" << endl;
                break;
        }
    }
 
//read number associated with the options flag for bit shifting.    
stringstream strValue;
strValue << argv[2];
int intValue;
strValue >> intValue;

 
string::iterator it;
it = input.begin();
string msg = "";
for (int index = 0; it < input.end(); ++index)
    {
     int x = (int)*it - intValue;
     //output the character values shifted over by the number  in argument argv[2]
 
         if ((x<65) || (x>90))
              x=x+26;
 
         if ((x > 90)||(x<65))
            {
                cout << " ";  
				msg += " ";
                ++it;
             }
 
          else
             {  
                char z = (char)x;      
                cout << z;
                msg += z;
                ++it;
              }
     }
         if (flagA == true)
	          lpp(msg);
				
    	 if (flagB == true)
			  cout << "I hope you enjoyed my program\n";

return 0;
}