SHARE
TWEET

Untitled

a guest May 23rd, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. #include "pch.h"
  4. #include <iostream>
  5. #include "string.h"
  6. #include "io.h"
  7. #include "stdlib.h"
  8. #include "iomanip"
  9. using namespace std;
  10.  
  11. struct info
  12. {
  13.     char FIO;
  14.     char kafedra[50];
  15.     char dolgnost[15];
  16.     char chasy[15];
  17. };
  18.  
  19. void add()
  20. {
  21.     info w;
  22.     FILE *zap;
  23.     fopen_s(&zap, "spisok.txt", "a");
  24.     cout << "FIO:           "; cin >> w.FIO;
  25.     cout << "kafedra:          "; cin.ignore(50, '\n');  gets_s(w.kafedra);
  26.     cout << "dolgnost:       "; gets_s(w.dolgnost);
  27.     cout << "chasy:       "; gets_s(w.chasy);
  28.     fwrite(&w, sizeof(info), 1, zap);
  29.     fclose(zap);
  30. }
  31.  
  32. void view()
  33. {
  34.     info w;
  35.     FILE *zap;
  36.     fopen_s(&zap, "spisok.txt", "r");
  37.     cout << setw(8) << "FIO" << setw(30) << "kafedra" << setw(15) << "dolgnost" << setw(15) << "chasy\n" << setw(60);
  38.     while (fread(&w, sizeof(info), 1, zap))
  39.         cout << setw(8) << w.FIO << setw(30) << w.kafedra << setw(15) << w.dolgnost << setw(15) << w.chasy << endl;
  40.     fclose(zap);
  41.     cout << "\n\n";
  42. }
  43.  
  44. void search()
  45. {
  46.     FILE *zap;
  47.     info w;
  48.     int num;
  49.     fopen_s(&zap, "spisok.txt", "r");
  50.     cout << "FIO ";
  51.     cin >> num;
  52.     cout << setw(30) << "kafedra" << setw(15) << "dolgnost" << setw(15) << "chasy\n";
  53.     while (fread(&w, sizeof(info), 1, zap))
  54.         if (w.FIO == num)
  55.             cout << setw(30) << w.kafedra << setw(15) << w.dolgnost << setw(15) << w.chasy << endl;
  56.     fclose(zap);
  57.     cout << "\n\n";
  58. }
  59.  
  60. void pr_vibor(info *w, int kol)
  61. {
  62.     int i, j, q;
  63.     info r;
  64.     for (i = 0; i < kol - 1; i++)
  65.     {
  66.         q = i;
  67.         for (j = i + 1; j < kol; j++)
  68.             if (strcmp(w[j].chasy, w[q].chasy) > 0) q = j;
  69.         if (i != q)
  70.         {
  71.             r = w[q];
  72.             w[q] = w[i];
  73.             w[i] = r;
  74.         }
  75.     }
  76. }
  77.  
  78.  
  79. void qsort(info *w, int beg, int en)
  80. {
  81.     info q;
  82.     int left = beg, right = en;
  83.     char* x;
  84.     x = w[(left + right) / 2].chasy;
  85.     do
  86.     {
  87.         while (strcmp(x, w[left].chasy) < 0) left++;
  88.         while (strcmp(x, w[right].chasy) > 0) right--;
  89.         if (left <= right)
  90.         {
  91.             q = w[left];
  92.             w[left] = w[right];
  93.             w[right] = q;
  94.             left++;
  95.             right--;
  96.         }
  97.     } while (left <= right);
  98.     if (beg < right) qsort(w, beg, right);
  99.     if (left < en) qsort(w, left, en);
  100. }
  101.  
  102. void sort()
  103. {
  104.     FILE *zap;
  105.     int kol, i = 0, vibor, num;
  106.     fopen_s(&zap, "spisok.txt", "r");
  107.     kol = _filelength(_fileno(zap)) / sizeof(info);
  108.     info *w = new info[kol];
  109.     while (fread(&w[i++], sizeof(info), 1, zap));
  110.     cout << "FIO ";
  111.     cin >> num;
  112.     cout << "metod sortirovki \n1.priamoi vibor \n2.QuickSort \n";
  113.     cin >> vibor;
  114.     switch (vibor)
  115.     {
  116.     case 1: pr_vibor(w, kol); break;
  117.     case 2: qsort(w, 0, kol - 1); break;
  118.     }
  119.     cout << setw(30) << "kafedra" << setw(15) << "dolgnost" << setw(15) << "chasy\n";
  120.     for (i = 0; i < kol; i++)
  121.         if (w[i].FIO == num)
  122.             cout << setw(30) << w[i].kafedra << setw(15) << w[i].dolgnost << setw(15) << w[i].chasy << endl;
  123. }
  124.  
  125. void main()
  126. {
  127.     int menu;
  128.     while (true)
  129.     {
  130.         cout << "viberite: \n1.dobavit\n2.prosmotr \n3. poisk \n4. sort \n0.vihod\n";
  131.         cin >> menu;
  132.         switch (menu)
  133.         {
  134.         case 1: add();      break;
  135.         case 2: view();     break;
  136.         case 3: search();   break;
  137.         case 4: sort();     break;
  138.         case 0: return;
  139.         }
  140.     }
  141. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top