Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #define _Z 'z'
- #define _A 'a'
- using namespace std;
- string input;
- int shift;
- int length;
- void codeString(){
- for (int i = 0; i < length; i++){
- if (isalpha(input[i])){
- input[i] = tolower(input[i]);
- for (int j = 0; j < shift; j++){
- if (input[i] == _Z){
- input[i] = _A;
- }
- else
- input[i]++;
- }
- }
- }
- }
- void printString(){
- cout << "\nResult: " << input << endl;
- }
- void getString (){
- char* doc = new char;
- cout << "Enter FILENAME: ";
- cin >> doc;
- ifstream str(doc);
- if (str.fail()){
- cout << "Can't open file: " << doc << endl;
- system("pause");
- exit(1);
- }
- delete doc;
- while (getline(str, input));
- length = (int)input.length();
- }
- int main(){
- getString();
- cout << "Enter SHIFT: ";
- cin >> shift;
- codeString();
- printString();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment