Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.87 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <cstring>
  4.  
  5. char inputString[256], outputString[256];
  6. char encrypt[3]={'l','a', '\0'};
  7. char vowels[7]={'a','e','y','u','i','o','\0'};
  8. int s;
  9. std::ofstream myfile;
  10.  
  11. void function1 (char*){
  12.     myfile.open ("example.txt");
  13.     std::cout << "Enter words\n";
  14.     std::cin >> (inputString);
  15.     myfile << inputString;
  16.     myfile.close();
  17. }
  18.  
  19.  
  20. void function2 (char*){
  21.     std::ifstream ("example.txt");
  22.     myfile.open ("example.txt");
  23.     std::cout << "Entered: " << inputString << "\n";
  24. }
  25.  
  26. void function3 (char*, char*, char*){
  27.     for (int i = 0; i < strlen(inputString); i++){
  28.         char buff[256]="";
  29.         strncpy(buff, inputString+i, 1);
  30.         for (int j = 0; j < strlen(vowels); j++){
  31.             if (buff[0] == vowels[j]){
  32.                 strcat(buff, encrypt);
  33.                 break;
  34.             }
  35.         }
  36.         strcat(outputString, buff);
  37.     }
  38.     strcpy(inputString, outputString);
  39.     std::cout << "Encrypt: " << inputString << "\n";
  40.     myfile << inputString;
  41.     myfile.close();
  42. }
  43.  
  44.  
  45. void function4 (char*, char*, char*, char*){
  46.     std::ifstream("example.txt");
  47.     myfile.open ("example.txt");
  48.    
  49.     char outputString[256]="";
  50.    
  51.     for (int i=0; i < strlen(inputString); i++){
  52.         char buff[256] = "";
  53.         strncpy(buff, inputString+i, 1);
  54.         for (int j=0; j < strlen(vowels); j++){
  55.             if (buff[0] == vowels[j]){
  56.                 char twoSymbols[256]="";
  57.                 strncpy(twoSymbols, inputString+i+1, 2);
  58.                 if (strcmp(twoSymbols, encrypt) == 0){
  59.                     i+=2;
  60.                     break;
  61.                 }
  62.             }
  63.         }
  64.         strcat(outputString,buff);
  65.     }
  66.    
  67.     std::cout <<"Decrypt: " << outputString;
  68.     myfile << "Encrypted word: " <<inputString << "\n" << "Decrypted word: " << outputString;
  69.     myfile.close();
  70. }
  71.  
  72. void function5(){
  73.     //exit(5);
  74. }
  75.  
  76. int defaultFunction(){
  77.     s=0;
  78.     std::cout <<("Choose one of case\n");
  79.     std::cout <<("1 = Сформировать с клавиатуры строку  и записать в файл\n");
  80.     std::cout <<("2 = Считать строку из файла и распечатать\n");
  81.     std::cout <<("3 = Зашифровать строку и записать в файл\n");
  82.     std::cout <<("4 = Расшифровать строку и записать в файл\n");
  83.     std::cout <<("5 = Exit\n");
  84.     std::cin >> s;
  85.     return 0;
  86. }
  87.  
  88. int main() {
  89.    
  90.     defaultFunction();
  91.    
  92.     switch(s) {
  93.    
  94.         case 1: function1(inputString); return defaultFunction();
  95.    
  96.         case 2: function2(inputString); break;
  97.    
  98.         case 3: function3(inputString, vowels, encrypt); break;
  99.    
  100.         case 4: function4(inputString, outputString, vowels, encrypt); break;
  101.    
  102.         case 5: function5(); break;
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement