Advertisement
Guest User

Untitled

a guest
Oct 7th, 2013
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1.  
  2. #include "Unit1.h"
  3. #include <fstream.h>
  4. #include <iostream.h>
  5. #include <iomanip.h>
  6. #define N 100
  7.  
  8. typedef struct  STR{
  9.     char fio[N];
  10.     char dolzn[N];
  11.     int stage;
  12.     int oklad;
  13.     char fack[N];
  14.     char date_create[N];
  15.     }
  16.     st;
  17.  
  18.     int n=0;
  19.     st sts[N];
  20. void print()
  21.  {
  22.  
  23.  
  24.    for (int i = 0; i < n; i++)
  25.     {
  26.  Form1->StringGrid1->Cells[0][i]=sts[i].fio;
  27.  Form1->StringGrid1->Cells[1][i]=sts[i].dolzn;
  28.  Form1->StringGrid1->Cells[2][i]=sts[i].stage;
  29.  Form1->StringGrid1->Cells[3][i]=sts[i].oklad;
  30.  Form1->StringGrid1->Cells[4][i]=sts[i].fack;
  31.  Form1->StringGrid1->Cells[5][i]=sts[i].date_create;
  32.       }
  33.    }
  34.  
  35. void print2()
  36.   {
  37.  
  38.  
  39.     for (int i = 0; i < n; i++)
  40.      {
  41.  
  42.  
  43. Form1->StringGrid2->Cells[0][i]=sts[i].fio;
  44. Form1->StringGrid2->Cells[1][i]=sts[i].dolzn;
  45. Form1->StringGrid2->Cells[2][i]=sts[i].stage;
  46. Form1->StringGrid2->Cells[3][i]=sts[i].oklad;
  47. Form1->StringGrid2->Cells[4][i]=sts[i].fack;
  48. Form1->StringGrid2->Cells[5][i]=sts[i].date_create;
  49.  
  50.  
  51.       }
  52.    }
  53.  
  54. void __fastcall TForm1::FormCreate(TObject *Sender)
  55. {
  56.  
  57.  
  58.  
  59.     ifstream ar("in.cpp");
  60.     n=count(istreambuf_iterator<char>(ar),
  61.     istreambuf_iterator<char>(), '\n');
  62.  
  63.  
  64.     ifstream in;
  65.     in.open("in.cpp");
  66.    
  67.    for (int i = 0; i < n; ++i)
  68.       {
  69.         in>>sts[i].fio;
  70.         in>>sts[i].dolzn;
  71.         in>>sts[i].stage;
  72.         in>>sts[i].oklad;
  73.         in>>sts[i].fack;
  74.         in>>sts[i].date_create;
  75.           }
  76.  
  77.         print();
  78.     in.close();
  79.  
  80. }
  81.  
  82.  void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
  83. {
  84.  int k=0,q=0,tmp;
  85.  bool fl;
  86.  fl=1;
  87. // for (int i = 0 ; i < n ; i++)
  88.   while (fl)
  89.        {
  90.  
  91.        fl=0;
  92.        for (int j = 0 ; j < n - 1  ; j++)
  93.           {
  94.            q++;
  95.  
  96.           // if (sts[j].oklad > sts[j+1].oklad )
  97.        if (sts[j].oklad > sts[j+1].oklad )
  98.  
  99.              {
  100.                fl=1;
  101.                tmp= sts[j].oklad;
  102.                sts[j].oklad = sts[j+1].oklad;
  103.                sts[j+1].oklad = tmp;
  104.                k++;
  105.              }
  106.         }
  107.     }
  108.  
  109.   print2();
  110.   Label3->Caption=k; // сравнения
  111.   Label4->Caption=q; // перестановки
  112. }
  113.  
  114. int zarp(const void* a, const void* b)
  115. {
  116.     const st* k = (const st*)a;
  117.     const st* m = (const st*)b;
  118.     int s = ((k -> oklad) - (m -> oklad));    
  119.     return s;
  120. }
  121.  
  122.  
  123. void __fastcall TForm1::SpeedButton2Click(TObject *Sender)
  124. {
  125.   qsort(sts, n , sizeof(st), zarp);
  126.   print2();
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement