Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <cstring>
- char inputString[256], outputString[256];
- char encrypt[3]={'l','a', '\0'};
- char vowels[7]={'a','e','y','u','i','o','\0'};
- int s;
- std::ofstream myfile;
- void function1 (char*){
- myfile.open ("example.txt");
- std::cout << "Enter words\n";
- std::cin >> (inputString);
- myfile << inputString;
- myfile.close();
- }
- void function2 (char*){
- std::ifstream ("example.txt");
- myfile.open ("example.txt");
- std::cout << "Entered: " << inputString << "\n";
- }
- void function3 (char*, char*, char*){
- for (int i = 0; i < strlen(inputString); i++){
- char buff[256]="";
- strncpy(buff, inputString+i, 1);
- for (int j = 0; j < strlen(vowels); j++){
- if (buff[0] == vowels[j]){
- strcat(buff, encrypt);
- break;
- }
- }
- strcat(outputString, buff);
- }
- strcpy(inputString, outputString);
- std::cout << "Encrypt: " << inputString << "\n";
- myfile << inputString;
- myfile.close();
- }
- void function4 (char*, char*, char*, char*){
- std::ifstream("example.txt");
- myfile.open ("example.txt");
- char outputString[256]="";
- for (int i=0; i < strlen(inputString); i++){
- char buff[256] = "";
- strncpy(buff, inputString+i, 1);
- for (int j=0; j < strlen(vowels); j++){
- if (buff[0] == vowels[j]){
- char twoSymbols[256]="";
- strncpy(twoSymbols, inputString+i+1, 2);
- if (strcmp(twoSymbols, encrypt) == 0){
- i+=2;
- break;
- }
- }
- }
- strcat(outputString,buff);
- }
- std::cout <<"Decrypt: " << outputString;
- myfile << "Encrypted word: " <<inputString << "\n" << "Decrypted word: " << outputString;
- myfile.close();
- }
- void function5(){
- //exit(5);
- }
- int defaultFunction(){
- s=0;
- std::cout <<("Choose one of case\n");
- std::cout <<("1 = Сформировать с клавиатуры строку и записать в файл\n");
- std::cout <<("2 = Считать строку из файла и распечатать\n");
- std::cout <<("3 = Зашифровать строку и записать в файл\n");
- std::cout <<("4 = Расшифровать строку и записать в файл\n");
- std::cout <<("5 = Exit\n");
- std::cin >> s;
- return 0;
- }
- int main() {
- defaultFunction();
- switch(s) {
- case 1: function1(inputString); return defaultFunction();
- case 2: function2(inputString); break;
- case 3: function3(inputString, vowels, encrypt); break;
- case 4: function4(inputString, outputString, vowels, encrypt); break;
- case 5: function5(); break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement