Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лабораторная работа по СИАОДу

.CPP
Скачиваний:
8
Добавлен:
01.05.2014
Размер:
9.08 Кб
Скачать
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<dos.h>
#include<stdio.h>
#include <string.h>
#include <math.h>
struct bolnica
       {
       int kod;
       int otd;
       char name[40];
       char pos[40];
       char vyp[40];
       int del;
       };
int razmer ()
{
int k=0;
char t;
ifstream read ("bbb1.txt");
while (!read.eof() )
      {
      read.get(t);
      if (t=='\n')
      k++;
      }
read.close();
return k;
}

void readbol (bolnica bol[], int razm)
{
ifstream read ("bbb1.txt");
int i;
for (i=0; i<razm; i++)
    {
    read >> bol[i].kod >> bol[i].otd >> bol[i].name >> bol[i].pos >> bol[i].vyp >> bol[i].del;
    }
read.close();
}


void recbol (bolnica bol[], int razm)
{
int i;
ofstream write ("bbb1.txt");
for (i=0; i<razm; i++)
    {
    if (bol[i].del!=1)
       {
       write << bol[i].kod << " " << bol[i].otd << " " << bol[i].name
       << " " << bol[i].pos << " " << bol[i].vyp << " "
       << bol[i].del << "\n";
       }
    }
write.close();
}
int getbol (bolnica bol[], int razm, int SIZE)
{
int i;
char t;
for (i=razm; i<SIZE; i++)
    {
    clrscr();
    gotoxy(2,4);
    cout << "Vvedite kod: ";
    cin >> bol[i].kod;
    cout << "\n Vvedite otdelenie: ";
    cin >> bol[i].otd;
    cout << "\n Vvedite FIO: ";
    cin >> bol[i].name;
    cout << "\n Vvedite datu postupleniya: ";
    cin >> bol[i].pos;
    cout << "\n Vvedite datu vypuska: ";
    cin >> bol[i].vyp;
    bol[i].del=0;
    if (i==SIZE-1)
       {
       cout <<"\n baza zapolnenea";
       delay(1000);
       break;
       }
    else
	{
	cout << "\n prodoljit' vvod Y\\N? ";
	cin >> t;
	if ( (t=='Y')||(t=='y') )
	{}
	else
	break;
	}
    }
return i+1;
}

void del_bol(bolnica bol[], int razm, int k)
{int j=0;
char t;
for (int i=0;i<razm;i++)
{
if  (k==bol[i].kod)
    {j=j+1;
    cout<<"\n DELET Y\\N?"<<endl;
    cout<<" ";
    cin >>t;
    if ( (t=='y')||(t=='Y') )
       {
       bol[i].del=1;
       cout<<"\n DELETED!"<<endl;
       }
    }}
if (j==0) cout<<"\n can't delet";
delay(1000);
}

void puzyr_kod(bolnica bol[],int razm)
{for (int i=0;i<razm-1;i++)
for (int j=i+1;j<razm;j++)
if (bol[i].kod>bol[j].kod)
{bolnica r;
r=bol[i];
bol[i]=bol[j];
bol[j]=r;}}

void puzyr_name(bolnica bol[],int razm)
{for (int i=0;i<razm-1;i++)
for (int j=i+1;j<razm;j++)
if (stricmp(bol[i].name,bol[j].name)>0)
{bolnica r;
r=bol[i];
bol[i]=bol[j];
bol[j]=r;}}

void Shell_kod(bolnica bol[],int razm)
{
int step=razm;
while(step>0)
{step=(int) step/2;
for(int i=0;i<step;i++)
  for(int k=i;k<razm-step;k+=step)
    for(int j=k+step;j<razm;j+=step)
     if (bol[k].kod>bol[j].kod)
     {bolnica r;
     r=bol[k];
     bol[k]=bol[j];
     bol[j]=r;}
}}

void Shell_name(bolnica bol[],int razm)
{
int step=razm;
while(step>0)
{step=(int) step/2;
for(int i=0;i<step;i++)
  for(int k=i;k<razm-step;k+=step)
    for(int j=k+step;j<razm;j+=step)
     if (stricmp(bol[k].name,bol[j].name)>0)
     {bolnica r;
     r=bol[k];
     bol[k]=bol[j];
     bol[j]=r;}
}}

void Bin_vkl_kod(bolnica bol[],int razm)
{bolnica r;
int x,j;
for (int i=0;i<razm;i++)
{int x=(int) i/2;
if (bol[i].kod<bol[x].kod) j=0;
else j=x;
for (j;j<i;j++)
{if (bol[i].kod<bol[j].kod)
{r=bol[i];
for (int k=i;k>j;k--) bol[k]=bol[k-1];
         bol[j]=r;
         break;
       }
    }
  }
}

void Bin_vkl_name(bolnica bol[],int razm)
{bolnica r;
int x,j;
for (int i=0;i<razm;i++)
{int x=(int) i/2;
if (stricmp(bol[i].name,bol[x].name)<0) j=0;
else j=x;
for (j;j<i;j++)
{if (stricmp(bol[i].name,bol[j].name)<0)
{r=bol[i];
for (int k=i;k>j;k--) bol[k]=bol[k-1];
         bol[j]=r;
         break;
}}}}

void writebol(bolnica bol[], int razm)
{
clrscr();
int i,n;
n=3;
cout<<" Kod: Otdelenie: FIO:         Data postupleniya:   Data vypiski:"<<endl;
for (i=0; i<razm; i++)
    {
gotoxy(2,n);cout<< bol[i].kod;
gotoxy(7,n);cout<< bol[i].otd;
gotoxy(18,n);cout<< bol[i].name;
gotoxy(32,n);cout<<bol[i].pos;
gotoxy(53,n);cout<< bol[i].vyp<<endl;
n+=2;}
getch();
}

void sort(bolnica bol[],int razm)
{for(int l;;)
  {clrscr();
  gotoxy(2,2);  printf("ЙННННННННННННННННННННННННННННН»");
  gotoxy(2,3);  printf("є 1 - PUZYREK                 є");
  gotoxy(2,4);  printf("є 2 - METOD SHELLA            є");
  gotoxy(2,5);  printf("є 3 - BINARNOE VKLYUCHENIE    є");
  gotoxy(2,6);  printf("ИНННННННННННННННННННННННННННННј");
  gotoxy(34, 47); printf("ЙНННННННННННННННННННННННННННННННННННННННННННН»");
  gotoxy(34, 48); printf("є                                 ESC - BACK є");
  gotoxy(34, 49); printf("ИННННННННННННННННННННННННННННННННННННННННННННј");
  int f=getch();
  switch(f)
  {case 49:{clrscr();
      for(int k;;)
      {clrscr();
      gotoxy(2,2);  printf("ЙННННННННННННННННННННННННННННН»");
      gotoxy(2,3);  printf("є 1 - PO FIO                  є");
      gotoxy(2,4);  printf("є 2 - PO KODU                 є");
      gotoxy(2,5);  printf("ИНННННННННННННННННННННННННННННј");
      gotoxy(34, 47); printf("ЙНННННННННННННННННННННННННННННННННННННННННННН»");
      gotoxy(34, 48); printf("є                                 ESC - BACK є");
      gotoxy(34, 49); printf("ИННННННННННННННННННННННННННННННННННННННННННННј");
      int o=getch();
      switch(o)
      {case 49:{clrscr();
      puzyr_name(bol,razm);
      writebol(bol,razm);}
      break;
      case 50:{clrscr();
      puzyr_kod(bol,razm);
      writebol(bol,razm);}
      break;}
      if (o==27) break;
      cout<<"\n Sohranit otsortirovannyi spisok (Y/N): ";
      char t;
      cin >>t;
      if ( (t=='y')||(t=='Y') ) recbol(bol,razm);
      }}
      break;
   case 50:{clrscr();
      for(int q;;)
      {clrscr();
      gotoxy(2,2);  printf("ЙННННННННННННННННННННННННННННН»");
      gotoxy(2,3);  printf("є 1 - PO FIO                  є");
      gotoxy(2,4);  printf("є 2 - PO KODU                 є");
      gotoxy(2,5);  printf("ИНННННННННННННННННННННННННННННј");
      gotoxy(34, 47); printf("ЙНННННННННННННННННННННННННННННННННННННННННННН»");
      gotoxy(34, 48); printf("є                                 ESC - BACK є");
      gotoxy(34, 49); printf("ИННННННННННННННННННННННННННННННННННННННННННННј");
      int w=getch();
      switch(w)
      {case 49:{clrscr();
      Shell_name(bol,razm);
      writebol(bol,razm);}
      break;
      case 50:{clrscr();
      Shell_kod(bol,razm);
      writebol(bol,razm);}
      break;}
      if (w==27) break;
      cout<<"\n Sohranit otsortirovannyi spisok (Y/N): ";
      char t;
      cin >>t;
      if ( (t=='y')||(t=='Y') ) recbol(bol,razm);
      }}
      break;
   case 51:{clrscr();
      for(int uu;;)
      {clrscr();
      gotoxy(2,2);  printf("ЙННННННННННННННННННННННННННННН»");
      gotoxy(2,3);  printf("є 1 - PO FIO                  є");
      gotoxy(2,4);  printf("є 2 - PO KODU                 є");
      gotoxy(2,5);  printf("ИНННННННННННННННННННННННННННННј");
      gotoxy(34, 47); printf("ЙНННННННННННННННННННННННННННННННННННННННННННН»");
      gotoxy(34, 48); printf("є                                 ESC - BACK є");
      gotoxy(34, 49); printf("ИННННННННННННННННННННННННННННННННННННННННННННј");
      int kk=getch();
      switch(kk)
      {case 49:{clrscr();
      Bin_vkl_name(bol,razm);
      writebol(bol,razm);}
      break;
      case 50:{clrscr();
      Bin_vkl_kod(bol,razm);
      writebol(bol,razm);}
      break;}
      if (kk==27) break;
      cout<<"\n Sohranit otsortirovannyi spisok (Y/N): ";
      char t;
      cin >>t;
      if ( (t=='y')||(t=='Y') ) recbol(bol,razm);}}
   break;}
  if (f==27) break;
  }
}




int main()
{clrscr();
int razm,SIZE,indx;
while (1)
      {clrscr();
      textbackground(1);
      textcolor(15);
  gotoxy(2,2);  printf("ЙННННННННННННННННННННННННННННН»");
  gotoxy(2,3);  printf("є 1 - DOBAVIT ELEMENT         є");
  gotoxy(2,4);  printf("є 2 - VYVOD SPISKA            є");
  gotoxy(2,5);  printf("є 3 - UDALIT ZAPIS            є");
  gotoxy(2,6);  printf("є 4 - SORTIROVKA              є");
  gotoxy(2,7);  printf("ИНННННННННННННННННННННННННННННј");
  gotoxy(34, 47); printf("ЙНННННННННННННННННННННННННННННННННННННННННННН»");
  gotoxy(34, 48); printf("є                                 ESC - EXIT є");
  gotoxy(34, 49); printf("ИННННННННННННННННННННННННННННННННННННННННННННј");
      razm=razmer();
      SIZE=razm+10;
      bolnica *bol;
      bol=new bolnica [SIZE];
      readbol(bol,razm);
      int x=getch();
      switch(x){
      case 49:{razm=getbol(bol,razm,SIZE);
      recbol(bol,razm);
      break;}
      case 50:{writebol(bol,razm);
      recbol(bol,razm);}
      break;
      case 51:{int k;
      clrscr();
      cout << "\n Vvedite kod udaljaemoi zapisi: ";
      cin >> k;
      del_bol(bol,razm,k);
      recbol(bol,razm);}
      break;
      case 52:sort(bol,razm);
      break;}
      if (x==27)
      break;}




return 0;}