Advertisement
VictoriaLodochkina

lab 6 2 sem z1

Apr 8th, 2020
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <string.h>
  5. #include <cstdlib>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <Windows.h>
  9. using namespace std;
  10. inline void eatline() { while (cin.get() != '\n') continue; }
  11.  
  12. struct Information
  13. {
  14.     char Name[20];
  15.     char Date[10];
  16.     char Problem[100];
  17.     char Status[14];
  18. };
  19.  
  20. int main()
  21. {
  22.     /*SetConsoleCP(1251);
  23.     SetConsoleOutputCP(1251);*/
  24.     cout << left;
  25.     int n;
  26.     cout << "Enter n: ";
  27.     cin >> n;
  28.     vector<Information> list(n);
  29.     //vector<Information> list2(n);
  30.     cin.ignore(100, '\n');
  31.     cin.clear();
  32.     unsigned int i = 0;
  33.     while (i < list.size())
  34.     {
  35.         cout << "Fill list " << i + 1 << ":" << endl << "Name: ";
  36.         cin.get(list.at(i).Name, 20);
  37.         eatline();
  38.         cout << "Date: ";
  39.         cin.get(list.at(i).Date, 10);
  40.         eatline();
  41.         cout << "Problem: ";
  42.         cin.get(list.at(i).Problem, 100);
  43.         eatline();
  44.         cout << "Status: ";
  45.         cin.get(list.at(i).Status, 20);
  46.         eatline();
  47.         i++;
  48.     }
  49.     ofstream ss("text.dat", ios::out | ios::app | ios::binary);
  50.     ss.write((char*)(&list[0]), sizeof(list[0]) * list.size());
  51.     ss.close();
  52.     //
  53.     ifstream num("text.dat", ios::binary);
  54.     num.seekg(0, ios::end);
  55.     int count = num.tellg() / sizeof(Information);
  56.     num.seekg(0, ios::beg);
  57.     num.close();
  58.     cout << "Count: " << count;
  59.     //
  60.     vector<Information> list2(count);
  61.     //
  62.  
  63.     ifstream iss;
  64.     iss.open("text.dat", ios::in | ios::binary);
  65.     iss.read((char*)(&list2[0]), sizeof(list2[0]) * list2.size());
  66.     cout << "****************************************************************" << endl;
  67.     iss.close();
  68.     for (unsigned int j = 0; j < list2.size(); j++)
  69.     {
  70.         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;
  71.     }
  72.  
  73.  
  74.     char st[10];
  75.     *st = 0;
  76.     strcat(st, "processed");
  77.     for (unsigned int k = 0; k < list2.size(); k++)
  78.     {
  79.  
  80.         if (strstr(list2.at(k).Status, st) != NULL)
  81.         {
  82.             list2.erase(list2.begin() + k);
  83.         }
  84.     }
  85.  
  86.  
  87.     cout << "Done!!!!!!!" << endl;
  88.  
  89.     for (unsigned int j = 0; j < list2.size(); j++)
  90.     {
  91.         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;
  92.     }
  93.     return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement