Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Unit1.h"
- #include <fstream.h>
- #include <iostream.h>
- #include <iomanip.h>
- #define N 100
- typedef struct STR{
- char fio[N];
- char dolzn[N];
- int stage;
- int oklad;
- char fack[N];
- char date_create[N];
- }
- st;
- int n=0;
- st sts[N];
- void print()
- {
- for (int i = 0; i < n; i++)
- {
- Form1->StringGrid1->Cells[0][i]=sts[i].fio;
- Form1->StringGrid1->Cells[1][i]=sts[i].dolzn;
- Form1->StringGrid1->Cells[2][i]=sts[i].stage;
- Form1->StringGrid1->Cells[3][i]=sts[i].oklad;
- Form1->StringGrid1->Cells[4][i]=sts[i].fack;
- Form1->StringGrid1->Cells[5][i]=sts[i].date_create;
- }
- }
- void print2()
- {
- for (int i = 0; i < n; i++)
- {
- Form1->StringGrid2->Cells[0][i]=sts[i].fio;
- Form1->StringGrid2->Cells[1][i]=sts[i].dolzn;
- Form1->StringGrid2->Cells[2][i]=sts[i].stage;
- Form1->StringGrid2->Cells[3][i]=sts[i].oklad;
- Form1->StringGrid2->Cells[4][i]=sts[i].fack;
- Form1->StringGrid2->Cells[5][i]=sts[i].date_create;
- }
- }
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- ifstream ar("in.cpp");
- n=count(istreambuf_iterator<char>(ar),
- istreambuf_iterator<char>(), '\n');
- ifstream in;
- in.open("in.cpp");
- for (int i = 0; i < n; ++i)
- {
- in>>sts[i].fio;
- in>>sts[i].dolzn;
- in>>sts[i].stage;
- in>>sts[i].oklad;
- in>>sts[i].fack;
- in>>sts[i].date_create;
- }
- print();
- in.close();
- }
- void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
- {
- int k=0,q=0,tmp;
- bool fl;
- fl=1;
- // for (int i = 0 ; i < n ; i++)
- while (fl)
- {
- fl=0;
- for (int j = 0 ; j < n - 1 ; j++)
- {
- q++;
- // if (sts[j].oklad > sts[j+1].oklad )
- if (sts[j].oklad > sts[j+1].oklad )
- {
- fl=1;
- tmp= sts[j].oklad;
- sts[j].oklad = sts[j+1].oklad;
- sts[j+1].oklad = tmp;
- k++;
- }
- }
- }
- print2();
- Label3->Caption=k; // сравнения
- Label4->Caption=q; // перестановки
- }
- int zarp(const void* a, const void* b)
- {
- const st* k = (const st*)a;
- const st* m = (const st*)b;
- int s = ((k -> oklad) - (m -> oklad));
- return s;
- }
- void __fastcall TForm1::SpeedButton2Click(TObject *Sender)
- {
- qsort(sts, n , sizeof(st), zarp);
- print2();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement