Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string>
  3. #include <iostream>
  4. #include <Windows.h>
  5. #include <conio.h>
  6. #include <fstream>
  7.  
  8. using namespace std;
  9. string buff;
  10. typedef string* Text[100];
  11. int n;
  12.  
  13. ifstream fin;
  14. ofstream fout;
  15.  
  16. short menu();
  17. void vvod();
  18. void list();
  19. void out(Text X, bool& l);
  20. void deleteStr(Text X, int i);
  21. void clearFile();
  22.  
  23. int main() {
  24.     SetConsoleCP(1251);
  25.     SetConsoleOutputCP(1251);
  26.     Text X;
  27.     short choise;
  28.     bool k = true;
  29.     do {
  30.         choise = menu();
  31.         switch (choise) {
  32.         case 1:
  33.             system("cls");
  34.             vvod();
  35.             system("pause");
  36.             system("cls");
  37.             break;
  38.         case 2:
  39.             system("cls");
  40.             list();
  41.             system("pause");
  42.             system("cls");
  43.             break;
  44.         case 3:
  45.             system("cls");
  46.             out(X, k);
  47.             system("pause");
  48.             system("cls");
  49.             break;
  50.         case 4:
  51.             if (k) {
  52.                 system("cls");
  53.                 cout << "Текст не был разделён на строчки! Для начала выполните соответствующую функцию." << endl;
  54.                 system("pause");
  55.                 system("cls");
  56.                 break;
  57.             }
  58.             system("cls");
  59.             int i, j;
  60.             cout << "Кол-во строк: " << n << endl;
  61.             cout << "Введите индекс строки, которую хотите удалить(считать с нуля):" << endl;
  62.             cin >> i;
  63.             deleteStr(X, i);
  64.             system("pause");
  65.             system("cls");
  66.             break;
  67.         case 5:
  68.             system("cls");
  69.             clearFile();
  70.             system("pause");
  71.             system("cls");
  72.             break;
  73.         case 0:
  74.             cout << "До свидания!!!" << endl;
  75.             system("pause");
  76.             break;
  77.         default:
  78.             cout << "Неверный выбор!!!" << endl;
  79.             cout << "\n\nPress Enter..." << endl;
  80.             system("pause");
  81.             system("cls");
  82.             break;
  83.         }
  84.     } while (choise);
  85.     cout << endl;
  86.     return 0;
  87. }
  88.  
  89. short menu() {
  90.     short v;
  91.     cout << "           МЕНЮ" << endl;
  92.     cout << " Введите [1] для ввода текста\n";
  93.     cout << " Введите [2] для просмотра текста\n";
  94.     cout << " Введите [3] для разделения текста на строчки\n";
  95.     cout << " Введите [4] для удаления i-ой строки из текста\n";
  96.     cout << " Введите [5] для очистки файла\n";
  97.     cout << " Введите [0] для выхода\n";
  98.     cout << " Пункт: ";
  99.     cin >> v;
  100.     return v;
  101. }
  102.  
  103. void vvod() {
  104.     fout.open("Text.txt", ios_base::app);
  105.     system("cls");
  106.     getline(cin, buff);
  107.     string s;
  108.     cout << "Введите строку: ";
  109.     getline(cin, s);
  110.     fout << s;
  111.     fout.close();
  112.     cout << "Текст введен в файл: " << endl;
  113.     cout << s << endl;
  114. }
  115.  
  116. void list() {
  117.     ifstream fin("Text.txt");
  118.     if (fin.peek() == EOF) cout << "Ваш файл пуст! Введите текст.\n"; // если первый символ конец файла
  119.     else {
  120.         string text;
  121.         getline(fin, text);
  122.         cout << text << endl;
  123.         fin.close();
  124.     }
  125. }
  126.  
  127. void out(Text X, bool& l) {
  128.     system("cls");
  129.     ifstream fin("Text.txt");
  130.     if (fin.peek() == EOF) cout << "Ваш файл пуст! Введите текст.\n"; // если первый символ конец файла
  131.     else {
  132.         int d;
  133.         cout << "Введите длину строки: ";
  134.         cin >> d;
  135.         string text;
  136.         int c = 0;
  137.         int i = 0;
  138.         getline(fin, text);
  139.         while (c < text.length()) {
  140.             string TX = text.substr(c, d);
  141.             c += d;
  142.             X[i] = new string;
  143.             *X[i] = TX;
  144.             i++;
  145.         }
  146.         for (int g = -1; g < i; g++) {
  147.             for (int j = 0; j < i; j++) {
  148.                 l = false;
  149.                 n = i;
  150.                 g++;
  151.                 cout << g << ". " << *X[j] << endl;
  152.             }
  153.         }
  154.         cout << "Кол-во строк: " << n << endl;
  155.         cout << "Запомните номер строки, которую вы вдруг захотите удалить и длину всех строк.\n";
  156.         fin.close();
  157.     }
  158. }
  159.  
  160. void deleteStr(Text X, int i) {
  161.     ifstream fin("Text.txt");
  162.     if (fin.peek() == EOF) cout << "Ваш файл пуст! Введите текст.\n"; // если первый символ конец файла
  163.     else {
  164.         string text;
  165.         int c = 0, m = 0;
  166.         getline(fin, text);
  167.         int d;
  168.         cout << "Повторите длину строки: " << endl;
  169.         cin >> d;
  170.         cout << "Изначальный текст:" << endl;
  171.         while (c < text.length()) {
  172.             cout << text.substr(c, d) << endl;
  173.             c += d;
  174.             m += 1;
  175.         }
  176.         delete(X[i]);
  177.         cout << endl << "Измененный текст:" << endl;
  178.         for (int k = 0; k < m; k++) cout << *X[k] << endl;
  179.         fin.close();
  180.     }
  181. }
  182.  
  183. void clearFile() {  //очистка файла
  184.     cout << "Файл успешно очищен! \n";
  185.     ofstream fclear("Text.txt", ios_base::trunc);
  186.     fclear.close();
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement