#include #include #include #include //---------------------- char menu(); void insert(); void edit(); void search(); void del(); void sort(); //---------------------- struct drog { long int code; char name[30]; char mark[30]; char type[30]; long int number; long int price; }d; FILE *fp1; char fn1[10]="drog.dat"; //---------------------- int main() { char ch; while (ch != '7') { clrscr(); ch=menu(); switch(ch) { case '1': insert(); break; case '2': break; case '3': search(); break; case '4': break; case '5': break; case '6': break; } } return(0); } //--------------------- char menu() { cout<<"1>Insert\n"; cout<<"2>Edit\n"; cout<<"3>Search\n"; cout<<"4>Delete\n"; cout<<"5>List\n"; cout<<"6>Sort\n"; cout<<"7>Exit\n"; cout<<"Enter your choice<1-7>:"; return(getch()); } //------------------------ void insert() { fp1=fopen(fn1,"a+b"); if (!fp1) //if (fp1 == NULL) exit(0); gotoxy(10,20); cout<<"Enter code=-1 to Exit"; gotoxy(0,0); while(1) { cout<<"\n--------------------------\n"; cout<<"code:"; cin>>d.code; if(d.code == -1)break; cout<<"name:"; cin>>d.name; cout<<"mark:"; cin>>d.mark; cout<<"type:"; cin>>d.type; cout<<"number:"; cin>>d.number; cout<<"price:"; cin>>d.price; cout<<"Save(y/n)?"; if (getch() == 'y') fwrite(&d,sizeof(d),1,fp1); } fclose(fp1); } //--------------------------- void edit() { } //------------------------- void search() { long int c; fp1=fopen(fn1,"a+b"); if (!fp1) //if (fp1 == NULL) exit(0); cout<<"Enter code:"; cin>>c; fseek(fp1,0,2); int len=ftell(fp1); fseek(fp1,0,0); int f=0; for(int i=0;i