Guest User

Untitled

a guest
Nov 28th, 2012
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #define _Z 'z'
  5. #define _A 'a'
  6.  
  7. using namespace std;
  8.  
  9. string input;
  10. int shift;
  11. int length;
  12.  
  13. void codeString(){
  14.    for (int i = 0; i < length; i++){
  15.         if (isalpha(input[i])){
  16.            input[i] = tolower(input[i]);
  17.            for (int j = 0; j < shift; j++){
  18.                if (input[i] == _Z){
  19.                   input[i] = _A;
  20.                }
  21.                else
  22.                input[i]++;
  23.            }                      
  24.         }    
  25.     }
  26. }
  27.  
  28. void printString(){
  29.     cout << "\nResult:  " << input << endl;      
  30. }
  31.  
  32. void getString (){
  33.     char* doc = new char;                                          
  34.     cout << "Enter FILENAME: ";
  35.     cin >> doc;
  36.     ifstream str(doc);
  37.     if (str.fail()){
  38.        cout << "Can't open file: " << doc << endl;
  39.        system("pause");
  40.        exit(1);
  41.     }
  42.     delete doc;      
  43.     while (getline(str, input));
  44.     length = (int)input.length();    
  45. }
  46.  
  47. int main(){
  48.     getString();
  49.    
  50.     cout << "Enter SHIFT: ";
  51.     cin >> shift;
  52.    
  53.     codeString();
  54.     printString();
  55.        
  56.     system("pause");
  57.     return 0;    
  58. }
Advertisement
Add Comment
Please, Sign In to add comment