Поможем написать учебную работу
Если у вас возникли сложности с курсовой, контрольной, дипломной, рефератом, отчетом по практике, научно-исследовательской и любой другой работой - мы готовы помочь.
Если у вас возникли сложности с курсовой, контрольной, дипломной, рефератом, отчетом по практике, научно-исследовательской и любой другой работой - мы готовы помочь.
#include<conio.h>
#include<stdio.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
/*-------------------cursor--------------------*/
void cursor(int state){
if (state==0)
asm{
mov ah,1
mov ch,0x20
int 0x10
}
else
asm {
mov ah,1
mov ch,5
mov cl,7
int 0x10
}
}
/*-------------------cursor--------------------*/
/*--------------------Ramka-----------------------------------*/
void ramka(int kyt_vl_x,int kyt_vl_y,int dov_x,int dov_y)
{
int i1;
for(i1=kyt_vl_x;i1<dov_x;i1++){
gotoxy(i1,kyt_vl_y-1);
putchar(205);
}
for(i1=kyt_vl_y;i1<dov_y;i1++){
gotoxy(dov_x,i1);
putchar(186);
}
for(i1=dov_x-1;i1>kyt_vl_x-1;i1--){
gotoxy(i1,dov_y);
putchar(205);
}
for(i1=dov_y-1;i1>kyt_vl_y-1;i1--){
gotoxy(kyt_vl_x-1,i1);
putchar(186);
}
gotoxy(kyt_vl_x-1,kyt_vl_y-1);
putchar(201);
gotoxy(dov_x,kyt_vl_y-1);
putchar(187);
gotoxy(dov_x,dov_y);
putchar(188);
gotoxy(kyt_vl_x-1,dov_y);
putchar(200);
}
/*--------------------Ramka-----------------------------------*/
int page=0;
int page_count=0;
int pos=0;
struct value
{
char name[30];
char adress[30];
char phone[15];
char countf[5];
char duplom[30];
};
struct mai
{
int count;
value m[100];
};
mai list;
void refresh_list()
{
int li=6;
int dest;
page_count = 0;
int tmpl=list.count;
while (tmpl-15>0)
{
tmpl=tmpl-15;
page_count++;
}
if (page*15+15>list.count)
{
dest=list.count;
}
else
{
dest=page*15+14;
}
for (int i=0;i<15;i++)
{
gotoxy(9,i+6);
printf(" ");
}
for (i=page*15;i<=dest;i++)
{
gotoxy(12,li);
printf(list.m[i].name);
gotoxy(24,li);
printf(list.m[i].adress);
gotoxy(38,li);
printf(list.m[i].phone);
gotoxy(51,li);
printf(list.m[i].countf);
gotoxy(65,li);
printf(list.m[i].duplom);
li++;
}
}
void insert_list()
{
char s[100];
list.count++;
gotoxy(1,1);
printf("%d",list.count);
gotoxy(3,23);
printf("Enter Name ");
scanf("%s",&s);
strcat(list.m[list.count].name,s);
gotoxy(3,23);
printf(" ");
gotoxy(3,23);
printf("Enter Adress ");
scanf("%s",&s);
strcat(list.m[list.count].adress,s);
gotoxy(3,23);
printf(" ");
gotoxy(3,23);
printf("Enter Phone ");
scanf("%s",&s);
strcat(list.m[list.count].phone,s);
gotoxy(3,23);
printf(" ");
gotoxy(3,23);
printf("Enter Count Fakultet ");
scanf("%s",&s);
strcat(list.m[list.count].countf,s);
gotoxy(3,23);
printf(" ");
gotoxy(3,23);
printf("Enter Duplom ");
scanf("%s",&s);
strcat(list.m[list.count].duplom,s);
gotoxy(3,23);
printf(" ");
refresh_list();
}
void save_list()
{
FILE *f;
f=fopen("ñ:\\vuz.my","w+");
for (int i=0;i<=list.count;i++)
{
char tmp[150];
strcpy(tmp,list.m[i].name);
strcat(tmp,",");
strcat(tmp,list.m[i].adress);
strcat(tmp,",");
strcat(tmp,list.m[i].phone);
strcat(tmp,",");
strcat(tmp,list.m[i].countf);
strcat(tmp,",");
strcat(tmp,list.m[i].duplom);
fprintf(f,"%s\n",tmp);
}
fclose(f);
}
void delete_list()
{
if (page*15+pos<=list.count)
{
for (int i=page*15+pos;i<list.count;i++)
{
list.m[i]=list.m[i+1];
}
list.count--;
refresh_list();
}
}
void sort_list(int vub)
{
value tmpv;
if (vub==0)
{
for (int i=0;i<=list.count;i++)
{
for (int j=0;j<=list.count;j++)
{
if (strcmp(list.m[i].name,list.m[j].name)<0)
{
tmpv=list.m[i];
list.m[i]=list.m[j];
list.m[j]=tmpv;
}
}
}
}
if (vub==1)
{
for (int i=0;i<=list.count;i++)
{
for (int j=0;j<=list.count;j++)
{
if (strcmp(list.m[i].adress,list.m[j].adress)<0)
{
tmpv=list.m[i];
list.m[i]=list.m[j];
list.m[j]=tmpv;
}
}
}
}
if (vub==2)
{
for (int i=0;i<=list.count;i++)
{
for (int j=0;j<=list.count;j++)
{
if (strcmp(list.m[i].phone,list.m[j].phone)<0)
{
tmpv=list.m[i];
list.m[i]=list.m[j];
list.m[j]=tmpv;
}
}
}
}
if (vub==3)
{
for (int i=0;i<=list.count;i++)
{
for (int j=0;j<=list.count;j++)
{
if (strcmp(list.m[i].countf,list.m[j].countf)<0)
{
tmpv=list.m[i];
list.m[i]=list.m[j];
list.m[j]=tmpv;
}
}
}
}
if (vub==4)
{
for (int i=0;i<=list.count;i++)
{
for (int j=0;j<=list.count;j++)
{
if (strcmp(list.m[i].duplom,list.m[j].duplom)<0)
{
tmpv=list.m[i];
list.m[i]=list.m[j];
list.m[j]=tmpv;
}
}
}
}
refresh_list();
}
void find_list()
{
int vub;
mit_1:
gotoxy(3,23);
printf(" ");
gotoxy(3,23);
printf("FIND: | Name-1 | Adress-2 | Phone-3 | CountF-4 | Duplom-5 | ");
cursor(1);
scanf("%d",&vub);
if((vub<1)||(vub>5)){goto mit_1;}
gotoxy(3,23);
printf(" ");
gotoxy(3,23);
printf("Find Text: ");
char s[50];
scanf("%s",&s);
for (int i=0;i<=list.count;i++)
{
char s1[50];
switch(vub)
{
case 1: strcpy(s1,list.m[i].name);break;
case 2: strcpy(s1,list.m[i].adress);break;
case 3: strcpy(s1,list.m[i].phone);break;
case 4: strcpy(s1,list.m[i].countf);break;
case 5: strcpy(s1,list.m[i].duplom);break;
}
if (strcmp(s1,s)==0)
{
gotoxy(3,pos+6);
printf(" ");
int j=i;
int l=0;
while (j-15>=0)
{
j=j-15;
l++;
}
page=l;
pos=j;
refresh_list();
gotoxy(3,pos+6);
printf(">");
gotoxy(3,23);
printf("Press ENTER ");
mit_2:
int c=getche();
if (c !=13){goto mit_2;}
}
}
cursor(0);
gotoxy(3,23);
printf(" ");
}
void new_window(int vub)
{
clrscr();
cursor(0);
ramka(2,2,80,3);
ramka(2,5,80,21);
ramka(2,23,80,24);
gotoxy(2,2);
printf("| Save-1 | Insert-2 | Delete-3 | Sort-4,5,6,7,8 | Find-9 | Close-ESC |");
gotoxy(12,5);
printf("NAME ADRESS PHONE COUNTF DUPLOM");
if (vub==1)
{
refresh_list();
}
pos=0;
mi2:
gotoxy(3,23);
int c=getche();
switch (c)
{
case 49:save_list(); break;
case 50:insert_list(); break;
case 51:delete_list(); break;
case 52:sort_list(0); break;
case 53:sort_list(1); break;
case 54:sort_list(2); break;
case 55:sort_list(3); break;
case 56:sort_list(4); break;
case 57:find_list(); break;
case 72:
if (pos!=0)
{
gotoxy(3,pos+6);
printf(" ");
pos--;
gotoxy(3,pos+6);
printf(">");
}
else
{
if (page !=0)
{
page--;
gotoxy(3,pos+6);
printf(" ");
pos=14;
refresh_list();
}
}
break;
case 80:
if (pos!=14)
{
gotoxy(3,pos+6);
printf(" ");
pos++;
gotoxy(3,pos+6);
printf(">");
}
else
{
if (page_count>page)
{
gotoxy(3,pos+6);
printf(" ");
page++;
pos=0;
refresh_list();
}
}
break;
case 27:goto mi1;break;
}
goto mi2;
mi1:
}
void open_list()
{
clrscr();
FILE *f;
f=fopen("ñ:\\vuz.my","r");
char *s;
list.count=-1;
while(! feof(f))
{
list.count++;
fscanf(f,"%s\n",s);
// printf("%s\n",s);
char *p;
p = strtok(s,",");
int l=0;
while (p)
{
switch(l)
{
case 0:strcpy(list.m[list.count].name,p);break;
case 1:strcpy(list.m[list.count].adress,p);break;
case 2:strcpy(list.m[list.count].phone,p);break;
case 3:strcpy(list.m[list.count].countf,p);break;
case 4:strcpy(list.m[list.count].duplom,p);break;
}
l++;
p = strtok(NULL,",");
}
}
fclose(f);
}
void main_menu()
{
mit_3:
clrscr();
ramka(2,2,80,24);
ramka(20,8,60,16);
gotoxy(35,10);
printf("New list - 1");
gotoxy(35,12);
printf("Open list - 2");
gotoxy(35,14);
printf("Exit - 3 ");
cursor(0);
mit_1:
gotoxy(45,14);
char c=getche();
if ((c!='1')&&(c!='2')&&(c!='3'))
{
goto mit_1;
}
switch (c)
{
case '1':page_count=0;page=0;list.count=-1; new_window(0);goto mit_3; break;
case '2':open_list();new_window(1);goto mit_3; break;
case '3':goto mit2; break;
}
goto mit_1;
mit2:
}
void main()
{
list.count=-1;
main_menu();
//
//
open_list();
// new_window();
char s[10];
// scanf("%s",&s);
}