Advertisement
VictoriaLodochkina

lab 6 all1 2 sem

Apr 8th, 2020
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.75 KB | None | 0 0
  1. #include <iostream>
  2. #define _USE_MATH_DEFINES
  3. #include <math.h>
  4. #include <string>
  5. #include <fstream>
  6. #include <iomanip>
  7. #include <string.h>
  8. #include <cstdlib>
  9. #include <vector>
  10. #include <algorithm>
  11. #include <Windows.h>
  12. using namespace std;
  13. inline void eatline() { while (cin.get() != '\n') continue; }
  14. struct Information
  15. {
  16.     char Name[20];
  17.     char Date[10];
  18.     char Problem[100];
  19.     char Status[14];
  20. };
  21. int main()
  22. {
  23.     using namespace std;
  24.     SetConsoleCP(1251);
  25.     SetConsoleOutputCP(1251);
  26.     long n;
  27.     char ex = 'n';
  28.     do {
  29.         cout << "Введите номер задания: " << endl;
  30.         char task;
  31.         /*cin.ignore(100, '\n');*/
  32.         cin >> task;
  33.         switch (task)
  34.         {
  35.         case '1': {
  36.             /*SetConsoleCP(1251);
  37.    SetConsoleOutputCP(1251);*/
  38.             cout << left;
  39.             int n;
  40.             cout << "Enter n: ";
  41.             cin >> n;
  42.             vector<Information> list(n);
  43.             //vector<Information> list2(n);
  44.             cin.ignore(100, '\n');
  45.             cin.clear();
  46.             unsigned int i = 0;
  47.             while (i < list.size())
  48.             {
  49.                 cout << "Fill list " << i + 1 << ":" << endl << "Name: ";
  50.                 cin.get(list.at(i).Name, 20);
  51.                 eatline();
  52.                 cout << "Date: ";
  53.                 cin.get(list.at(i).Date, 10);
  54.                 eatline();
  55.                 cout << "Problem: ";
  56.                 cin.get(list.at(i).Problem, 100);
  57.                 eatline();
  58.                 cout << "Status: ";
  59.                 cin.get(list.at(i).Status, 20);
  60.                 eatline();
  61.                 i++;
  62.             }
  63.             ofstream ss("text.dat", ios::out | ios::app | ios::binary);
  64.             ss.write((char*)(&list[0]), sizeof(list[0]) * list.size());
  65.             ss.close();
  66.             //
  67.             ifstream num("text.dat", ios::binary);
  68.             num.seekg(0, ios::end);
  69.             int count = num.tellg() / sizeof(Information);
  70.             num.seekg(0, ios::beg);
  71.             num.close();
  72.             cout << "Count: " << count;
  73.             //
  74.             vector<Information> list2(count);
  75.             //
  76.  
  77.             ifstream iss;
  78.             iss.open("text.dat", ios::in | ios::binary);
  79.             iss.read((char*)(&list2[0]), sizeof(list2[0]) * list2.size());
  80.             cout << "****************************************************************" << endl;
  81.             iss.close();
  82.             for (unsigned int j = 0; j < list2.size(); j++)
  83.             {
  84.                 cout << "list " << j + 1 << ":" << endl << "Name: " << endl << setw(5) << list2.at(j).Name << endl << setw(9) << "Date: " << endl << list2.at(j).Date << endl << "Problem: " << endl << setw(1) << list2.at(j).Problem << endl << "Status: " << endl << setw(1) << list2.at(j).Status << endl;
  85.             }
  86.  
  87.  
  88.             char st[11];
  89.             *st = 0;
  90.             strcat(st, "обработано");
  91.             for (unsigned int k = 0; k < list2.size(); k++)
  92.             {
  93.  
  94.                 if (strstr(list2.at(k).Status, st) != NULL)
  95.                 {
  96.                     list2.erase(list2.begin() + k);
  97.                 }
  98.             }
  99.  
  100.  
  101.             cout << "Done!!!!!!!" << endl;
  102.  
  103.             for (unsigned int j = 0; j < list2.size(); j++)
  104.             {
  105.                 cout << "list " << j + 1 << ":" << endl << "Name: " << endl << setw(5) << list2.at(j).Name << endl << setw(9) << "Date: " << endl << list2.at(j).Date << endl << "Problem: " << endl << setw(1) << list2.at(j).Problem << endl << "Status: " << endl << setw(1) << list2.at(j).Status << endl;
  106.             }
  107.             break;
  108.         }
  109.         case '2': {
  110.             string textt, word, rez;
  111.             ifstream ss("text.txt");
  112.             while (ss >> word)
  113.             {
  114.                 bool flag = 1;
  115.                 for (int i = 0; i < word.size() / 2; i++)
  116.                 {
  117.                     if (word.at(i) != word.at(word.size() - i - 1))
  118.                     {
  119.                         flag = 0;
  120.                         break;
  121.                     }
  122.                 }
  123.                 if (flag)
  124.                 {
  125.                     rez += word;
  126.                     rez += " ";
  127.                 }
  128.             }
  129.             ofstream sss("text2.txt");
  130.             sss << rez;
  131.             cout << "Program was completed. You can see result in project folder." << endl;
  132.             break;
  133.         }
  134.         default: {cout << "Нет такой задачи.\n"; } break;
  135.         }
  136.         cout << "Если вы хотите выйти, нажмите \'y\', в противном случае-любую другую клавишу" << endl;
  137.         cin.ignore(100, '\n');
  138.         cin >> ex;
  139.     } while (ex != 'y');
  140.     return 0;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement