Смекни!
smekni.com

Написание программы для удаления элементов и очистки внешних таблиц (стр. 4 из 4)

Рисунок В.5 – Загрузка файла справки

Рисунок В.6 – Запрос о выходе из программы


Приложение Г

ЛИСТИНГ ПРОГРАММЫ

#include <stdio.h>

#include <conio.h>

#include <graphics.h>

#include <alloc.h>

#include <dos.h>

#include <string.h>

#include <stdlib.h>

int a,b,d=1,d2=1,i,j,m,l=0,x=0,z=0,n,p=0,r=0,k=0,nomer=0,nom;

int mode=VGAHI;

int driver=VGA;

char kluch[10];

int nach, con;

FILE *in;

char ch,*v,h[10],cd[50],*str,c[5],s[50],cf[50],cb;

void *buf,*buf1, *buf2, *buf3;

struct type

{

char nazv[10];

char kol[10];

char sum[10];

char kl[10];

} tablica[15],*ukz;

void imya();

void del()

{FILE *in;

char fname[11];

setfillstyle(SOLID_FILL,0);

bar(200,100,500,300);

setcolor(4);

outtextxy(300,152,"‚ўҐ¤ЁвҐЁ¬пд ©« !!!(*.in)");

outtextxy(315,162,"max 2 бЁ¬ў®« :_");

rectangle(301,174,463,185);

imya();

in = fopen(s,"w");

fclose(in);

outtextxy(300,152,"” ©« ®зЁйҐ­!!!");

}

void record(void)

{ char ch,name[11];

FILE *out;

int j=0;

clrscr();

printf("•®вЁвҐб®еа ­ЁвмЁ­д®а¬ жЁоўд ©«(y - ¤ , Ё­ зҐ ­Ґв):");

ch=getch();

if (ch=='y')

{

do

{

clrscr();

printf("‚ўҐ¤ЁвҐЁ¬пд ©« (*.out):");

scanf("%s",name);

out=fopen(name,"w");

}while (out==NULL);

for (j=0;j<=n;j++)

{

fprintf(out,"%s&bsol;n",tablica[j].nazv);

fprintf(out,"%s&bsol;n",tablica[j].kol);

fprintf(out,"%s&bsol;n",tablica[j].sum);

fprintf(out,"%s&bsol;n",tablica[j].kl);}

clrscr();

gotoxy(32,13);

printf("‡ ЇЁбмЇа®Ё§ўҐ¤Ґ­ гбЇҐи­®!");

getch();

fclose(out);

}

}

void interval()

{

setfillstyle(SOLID_FILL,0);

setcolor(4);

outtextxy(300,202,"‚ўҐ¤ЁвҐ ­Ё¦­ооЈа ­Ёжг!!!(*.in)");

outtextxy(315,212,"max 2 бЁ¬ў®« :_");

rectangle(301,224,463,235);

p=0;

do{

a=getch();

if ((a!=13)&&(a!=8)&&(a!=27))

{ s[p]=a; p++; s[p]='&bsol;x0';}

bar(302,225,302+textwidth(s),226+textheight(s));

if (a==8) if (p>0) s[--p]='&bsol;x0';

outtextxy(302,225,s);

if(strlen(s)>15)

{

outtextxy(250,220,"Ѓ®«миҐбЁ¬ў®«®ўўўҐбвЁ ­Ґ«м§п!!!!");

outtextxy(250,230," „«пЇа®¤®«¦Ґ­Ёп ­ ¦¬ЁвҐ Enter");

do

{

a=getch();

}while (a!=13);

}

}while(a!=13);

setfillstyle(SOLID_FILL,0);

bar(300,202,600,235);

nach=atoi(s);

setfillstyle(SOLID_FILL,0);

setcolor(4);

outtextxy(300,202,"‚ўҐ¤ЁвҐўҐае­ооЈа ­Ёжг!!!(*.in)");

outtextxy(315,212,"max 2 бЁ¬ў®« :_");

rectangle(301,224,463,235);

p=0;

do{

a=getch();

if ((a!=13)&&(a!=8)&&(a!=27))

{ s[p]=a; p++; s[p]='&bsol;x0';}

bar(302,225,302+textwidth(s),226+textheight(s));

if (a==8) if (p>0) s[--p]='&bsol;x0';

outtextxy(302,225,s);

if(strlen(s)>15)

{

outtextxy(250,220,"Ѓ®«миҐбЁ¬ў®«®ўўўҐбвЁ ­Ґ«м§п!!!!");

outtextxy(250,230," „«пЇа®¤®«¦Ґ­Ёп ­ ¦¬ЁвҐ Enter");

do

{

a=getch();

}while (a!=13);

}

}while(a!=13);

setfillstyle(SOLID_FILL,0);

bar(164,24,606,446);

con=atoi(s);

i=0;j=0;x=0;k=0;

outtextxy(175,30,"Ќ®¬ €­¤ҐЄбЌ §ў ­ЁҐ‘㬬 Љ«оз");

do

{

i++;x+=10;j++;

if (i==nach)

{

do

{

i++;

}

while (i>=con);

}

itoa(j,c,10);

outtextxy(180,50+x,c);

outtextxy(220,50+x,ukz[i].nazv);

outtextxy(290,50+x,ukz[i].kol);

outtextxy(390,50+x,ukz[i].sum);

outtextxy(460,50+x,ukz[i].kl);

}while (i!=n);

getch();

}

void load(void)

{

FILE *in;

char fname[11];

int i=1;

setfillstyle(SOLID_FILL,0);

setcolor(4);

outtextxy(300,152,"‚ўҐ¤ЁвҐЁ¬пд ©« !!!(*.in)");

outtextxy(315,162,"max 20 бЁ¬ў®«®ў:_");

rectangle(301,174,463,185);

imya();

in = fopen(s,"r");

do

{ fgets(ukz->nazv,10,in);

fgets(ukz->kol,10,in);

fgets(ukz->sum,10,in);

fgets(ukz->kl,10,in);

i++;

k++;

} while(!feof(in));

rewind(in);

i=1;

outtextxy(175,30,"Ќ®¬ €­¤ҐЄбЌ §ў ­ЁҐ‘㬬 Љ«оз");

ukz=(struct type *)malloc(sizeof(struct type)*k);

do

{i++;

itoa(i-1,c,10);

x+=10;

outtextxy(180,50+x,c);

fscanf(in,"%s",ukz[i-1].nazv);

outtextxy(220,50+x,ukz[i-1].nazv);

fscanf(in,"%s",ukz[i-1].kol);

outtextxy(290,50+x,ukz[i-1].kol);

fscanf(in,"%s",ukz[i-1].sum);

outtextxy(390,50+x,ukz[i-1].sum);

fscanf(in,"%s",ukz[i-1].kl);

outtextxy(460,50+x,ukz[i-1].kl);

n=i;

}while (!feof(in));

fclose(in);

}

openf (char s[20])

{

setfillstyle(SOLID_FILL,0);

bar(164,24,606,446);

z=0;

k=0;

in=fopen(s,"r");

setviewport(164,24,606,446,0);

rewind(in);

while(fgets(cd,53,in)!=NULL)

{

a=strlen(cd);

if(cd[a-1]=='&bsol;n')

cd[a-1]=' ';

setcolor(7);

outtextxy(10,10+x,cd);

x+=10;

k++;

}

a=getch();

while (a!=27)

{

a=getch();

}

k=0;

x=0;

clearviewport();

setviewport(0,0,639,479,0);

fclose(in);

return(0);

}

void imya()

{

p=0;

do{

a=getch();

if ((a!=13)&&(a!=8)&&(a!=27))

{ s[p]=a; p++; s[p]='&bsol;x0';}

bar(302,175,302+textwidth(s),176+textheight(s));

if (a==8) if (p>0) s[--p]='&bsol;x0';

outtextxy(302,175,s);

if(strlen(s)>19)

{

outtextxy(250,200,"Ѓ®«миҐбЁ¬ў®«®ўўўҐбвЁ ­Ґ«м§п!!!!");

outtextxy(250,210," „«пЇа®¤®«¦Ґ­Ёп ­ ¦¬ЁвҐ Enter");

do

{

a=getch();

}while (a!=13);

}

}while(a!=13);

setfillstyle(SOLID_FILL,0);

bar(164,24,606,446);

}

liniya (int k,int m,int n)

{ setcolor(n);

line(130,20+k*60,130,50+k*60);

line(20,50+k*60,130,50+k*60);

setcolor(m);

line(20,20+k*60,20,50+k*60);

line(20,20+k*60,130,20+k*60);

return 0;

}

liniya2(int i,int m,int n)

{

setcolor (m);

line(20,300+i*60,20,330+i*60);

line(20,300+i*60,130,300+i*60);

setcolor (n);

line(130,300+i*60,130,330+i*60);

line(20,330+i*60,130,330+i*60);

return 0;

}

void nomer1()

{

setfillstyle(SOLID_FILL,0);

setcolor(4);

outtextxy(300,202,"‚ўҐ¤ЁвҐ ­®¬Ґа § ЇЁбЁ!!!(*.in)");

outtextxy(315,212,"max 2 бЁ¬ў®« :_");

rectangle(301,224,463,235);

p=0;

do{

a=getch();

if ((a!=13)&&(a!=8)&&(a!=27))

{ s[p]=a; p++; s[p]='&bsol;x0';}

bar(302,225,302+textwidth(s),226+textheight(s));

if (a==8) if (p>0) s[--p]='&bsol;x0';

outtextxy(302,225,s);

if(strlen(s)>15)

{

outtextxy(250,220,"Ѓ®«миҐбЁ¬ў®«®ўўўҐбвЁ ­Ґ«м§п!!!!");

outtextxy(250,230," „«пЇа®¤®«¦Ґ­Ёп ­ ¦¬ЁвҐ Enter");

do

{

a=getch();

}while (a!=13);

}

}while(a!=13);

setfillstyle(SOLID_FILL,0);

bar(164,24,606,446);

nom=atoi(s);

i=0;j=0;x=0;

outtextxy(175,30,"Ќ®¬ €­¤ҐЄбЌ §ў ­ЁҐ‘㬬 Љ«оз");

m=n;

do

{ x+=10;

i++; j++;

if((i==nom)&&(i==n)) break;

if(i==nom){i++;m-=1;}

itoa(j,c,10);

outtextxy(180,50+x,c);

outtextxy(220,50+x,ukz[i].nazv);

outtextxy(290,50+x,ukz[i].kol);

outtextxy(390,50+x,ukz[i].sum);

outtextxy(460,50+x,ukz[i].kl);

}while (i!=m);

getch();

}

void kluchik()

{

setfillstyle(SOLID_FILL,0);

setcolor(4);

outtextxy(300,202,"‚ўҐ¤ЁвҐЄ«оз (*.in)");

outtextxy(315,212,"max 2 бЁ¬ў®« :_");

rectangle(301,224,463,235);

p=0;

do{

a=getch();

if ((a!=13)&&(a!=8)&&(a!=27))

{ s[p]=a; p++; s[p]='&bsol;x0';}

bar(302,225,302+textwidth(s),226+textheight(s));

if (a==8) if (p>0) s[--p]='&bsol;x0';

outtextxy(302,225,s);

if(strlen(s)>15)

{

outtextxy(250,220,"Ѓ®«миҐбЁ¬ў®«®ўўўҐбвЁ ­Ґ«м§п!!!!");

outtextxy(250,230," „«пЇа®¤®«¦Ґ­Ёп ­ ¦¬ЁвҐ Enter");

do

{

a=getch();

}while (a!=13);

}

}while(a!=13);

setfillstyle(SOLID_FILL,0);

bar(164,24,606,446);

strcpy(kluch,s);

v=s;

i=0;j=0;x=0;

outtextxy(175,30,"Ќ®¬ €­¤ҐЄбЌ §ў ­ЁҐ‘㬬 Љ«оз");

do

{ x+=10;

i++;j++;

if (ukz[i-2].kl==v) i++;

itoa(j,c,10);

outtextxy(180,50+x,c);

outtextxy(220,50+x,ukz[i-1].nazv);

outtextxy(290,50+x,ukz[i-1].kol);

outtextxy(390,50+x,ukz[i-1].sum);

outtextxy(460,50+x,ukz[i-1].kl);

}while (i!=n);

getch();

}

file (char str1[5],char str2[5],char str3[5])

{

d2=1;

setfillstyle(SOLID_FILL,1);

for (i=0;i<3;i++)

{

bar(20,300+i*60,130,330+i*60);

liniya2(i,9,0);

}

while (a!=27)

{

setcolor(6);

outtextxy(27,310,str1);

outtextxy(27,370,str2);

outtextxy(27,430,str3);

if ((a==80)||(a==72))

{

if (a==80) d2++;

if (a==72) d2--;

if (d2>3) d2=1;

if (d2<1) d2=3;

}

if ((d2==1)&&(nomer==1))

{

setcolor(4);

outtextxy(27,310,str1);

liniya2(0,0,9);

a=getch();

liniya2(0,9,0);

if (a==13)

{

del();

}else continue;

}

if ((d2==1)&&(nomer==2))

{

setcolor(4);

outtextxy(27,310,str1);

liniya2(0,0,9);

a=getch();

if (a==13)

{

nomer1();

}

liniya2(0,9,0);

}

if ((d2==2)&&(nomer==1))

{

setcolor(4);

outtextxy(27,370,str2);

liniya2(1,0,9);

a=getch();

if (a==13)

{

load();

}

liniya2(1,9,0);

}

if ((d2==2)&&(nomer==2))

{

setcolor(4);

outtextxy(27,370,str2);

liniya2(1,0,9);

a=getch();

if (a==13)

{

kluchik();

}

liniya2(1,9,0);

}

if ((d2==3)&&(nomer==2))

{

setcolor(4);

outtextxy(27,430,str3);

liniya2(2,0,9);

a=getch();

liniya2(2,9,0);

if (a==13)

{

interval();

}

else continue;

liniya2(2,9,0);

}

}

setfillstyle(SOLID_FILL,8);

bar(20,300,130,460);

return 0;

}

void interfice()

{

setfillstyle(SOLID_FILL,8);

bar(0,0,640,480);

setfillstyle(SOLID_FILL,0);

bar(164,24,606,446);

setfillstyle(SOLID_FILL,1);

for (i=0;i<4;i++)

{

bar(20,20+i*60,130,50+i*60);

liniya(i,9,0);

}

setfillstyle (SOLID_FILL,1);

bar(160,20,163,450);

bar(20,265,163,268);

bar(160,20,610,23);

bar(607,20,610,450);

bar(160,447,610,450);

d=1;

while (ch!=27)

{

setcolor(6);

outtextxy(60,30,"”Ђ‰‹");

outtextxy(45,90,"“„Ђ‹…Ќ€…");

outtextxy(45,150,"‘ЏђЂ‚ЉЂ");

outtextxy(55,210,"‚›•Ћ„");

if ((a==80)||(a==72))

{

if (a==80) d++;

if (a==72) d--;

if (d>4) d=1;

if (d<1) d=4;

}

if (d==1)

{

nomer=1;

setcolor(4);

outtextxy(60,30,"”Ђ‰‹");

liniya(0,0,9);

a=getch();

liniya(0,9,0);

if (a==13)

{

file("Ћ—€‘’ЉЂ","‡Ђѓђ“‡ЉЂ","");

}else continue;

}

if (d==2)

{

setcolor(4);

nomer=2;

outtextxy(45,90,"“„Ђ‹…Ќ€…");

liniya(1,0,9);

a=getch();

liniya(1,9,0);

if (a==13)

{

file("ЏЋЌЋЊ…ђ“","ЏЋЉ‹ћ—“","ЏЋ €Ќ’…ђ‚Ђ‹“");

}else continue;

}

if ((d==3))

{

setcolor(4);

outtextxy(45,150,"‘ЏђЂ‚ЉЂ");

liniya(2,0,9);

a=getch();

liniya(2,9,0);

if (a==13)

{

openf("e:&bsol;bc31&bsol;bin&bsol;help.dat");

}

else continue;

}

if (d==4)

{

setcolor(4);

outtextxy(55,210,"‚›•Ћ„");

liniya(3,0,9);

a=getch();

liniya(3,9,0);

if (a==13)

{

break;

}

else continue;

}

}

}

void main(void)

{

initgraph(&driver,&mode,"e:&bsol;bc31&bsol;bin");

interfice();

closegraph();

}