#include #include #include #include #include #include #include #include void insbef(char name[20]); void del(char *); void delfile(void); void insdel(int x); int input(void); void entry(void); void filing(int x); void link(void); void trav(void); void InitLinkList(void); void detail(void); void details(void); void sortname(void); void sortnum(void); char *getsch(char *name); void start(void); //graphics void next(void); void menu(void); void credits(void); int search(char name[20]); FILE *fptr; int y=0; char c,o; /* Basic Structure */ struct numlist { char name[10], num[4], batch[5], sem[4], disc[10], sec[2]; struct numlist *ptrnext; }; struct numlist *first, *temp, *newp, *ins, data; /* Main function */ void main(void) { int md, dr; detectgraph(&md ,&dr); initgraph(&md, &dr, "c:\\tc\\bgi"); start(); next(); cleardevice(); first=(struct numlist *)NULL; filing(0); do { menu(); cleardevice(); }while(c!=27); } /* Entry Funtcion */ void entry(void) { if(input()==1) return; temp=newp; link(); filing(1); } /* Linked list Initialization */ void InitLinkList(void) { newp= new numlist; if (first==(struct numlist *) NULL) first=temp=newp;//=first->ptrprev; } /* Linked List */ void link(void) { InitLinkList(); temp->ptrnext=newp; temp=newp; data.ptrnext=temp->ptrnext; *temp=data; temp->ptrnext=(struct numlist *)NULL; } /* Traversing and file Writing */ void trav(void) { int x=0; setcolor(YELLOW); if (first==(struct numlist *)NULL) { outtextxy(0,0,"The list is empty"); return; } else { temp=first; outtextxy(140,20,"Name Roll no"); do { if (c=='w') filing(1); if (o!='d') { outtextxy(140,60+x,temp->name); outtextxy(400,60+x,temp->num); } else detail(); temp=temp->ptrnext; x+=20; }while(temp!= (struct numlist *)NULL ); temp=newp; } } /* Filing Function */ void filing( int x) { if ((fptr=fopen("myfile.rec", "rb+"))==NULL) fptr=fopen("myfile.rec", "wb+"); if (x==1) // file write { fseek(fptr,0L,2); fwrite(temp,sizeof(*temp),1,fptr); fclose(fptr); } else { // file read if ((y==1) && (first==(struct numlist *)NULL)) { outtextxy(220,200,"File is Empty"); return; } if (y==1) { outtextxy(200,230," This will delete the existing records "); outtextxy(200,250," Are you sure to read the file ( 'y' or 'n' ) "); while(1) { c=getch(); if (c=='y') { y=0; break; } else if (c=='n') return; } } if (y==0) { first=(struct numlist *) NULL; temp=newp=first; fseek(fptr,0L,0); } else fseek(fptr,0L,2); while(fread(&data,sizeof(data),1,fptr)) link(); if(y!=0) outtextxy(210,270,"Read Success... \n"); fclose(fptr); y++; } } /* Search Function */ int search(char name[20]) { temp=first; if (strcmpi(first->name, name)==0) return(1); do { if (strcmpi(temp->ptrnext->name, name)==0) return(1); temp=temp->ptrnext; } while(temp != (struct numlist *) NULL); return(0); } /* Menu Function */ void menu(void) { c=o=NULL; setcolor(WHITE); settextstyle(TRIPLEX_FONT, HORIZ_DIR, 5); outtextxy(50,0,"Main Menu"); setcolor(BLUE); settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 2); setbkcolor(BLACK); setcolor(10); outtextxy(200,100,"Enter e to enter entry"); outtextxy(200,130,"Enter r to read entries"); outtextxy(200,160,"Enter w to write entries"); outtextxy(200,190,"Enter l to list entries"); outtextxy(200,220,"Enter s to search entry"); outtextxy(200,250,"Enter i to insert entry"); outtextxy(200,280,"Enter d to delete entry"); outtextxy(200,310,"Enter o to sort entries"); outtextxy(200,340,"Enter esc to exit"); outtextxy(200,370,"Enter X to delete record file"); outtextxy(300,400,"Press c to display credits"); c=getch(); cleardevice(); if (c==27) exit(0); else if (c=='e') entry(); else if (c=='X') delfile(); else if (c=='c') credits(); else if (c=='r') filing(0); else if (c=='l' || c=='w') { if (c=='w') delfile(); trav(); if (first!=(struct numlist *)NULL) outtextxy(340,360,"Enter d for detailed records\n"); } else if (c=='i' || c=='d') if (c=='i') insdel(1); else insdel(0); else if (c=='o') { cleardevice(); outtextxy(180,220,"Sort by name or by roll no ('n'\'r')"); o=getch(); if (o=='n') sortname(); else sortnum(); } else if (c=='s') { char name[20]; outtextxy(0,0,"Enter name to search"); moveto(260,0); getsch(name); if (first == (struct numlist *) NULL) outtextxy(40,120,"The list is empty"); else { search(name); if (temp == (struct numlist *) NULL) outtextxy(20,140,"Search is unsuccessful"); else if(strcmpi(name,first->name)==0) { outtextxy(0,100,temp->name); outtextxy(80,100,"is at Location"); outtextxy(230,100,temp->num); outtextxy(340,440,"search is successful"); } else { outtextxy(0,100,temp->ptrnext->name); outtextxy(80,100,"is at Location"); outtextxy(230,100,temp->ptrnext->num); outtextxy(340,440,"search is successful"); } } } settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 2); setbkcolor(BLACK); setcolor(10); if(c!='c'); { outtextxy(240,380,"press any key to return to main menu "); outtextxy(310,400," .. . .. . .. . ..or hit ESC to exit"); } o=getch(); if (o==27) exit(0); else if (o=='d') { char name[10]; setcolor(9); outtextxy(0,340,"Enter name of the student"); moveto(0,360); search(getsch(name)); if (strcmpi(name, first->name)!=0) temp=temp->ptrnext; detail(); } setcolor(YELLOW); } /* Insertion & Deletion Function */ void insdel(int x) // x=1 for insertion & 0 for deletion. { char name[20]; trav(); if (x==0) outtextxy(0,340,"Enter name which has to be deleted"); else outtextxy(0,340,"Enter name before which insertion has to be done"); moveto(0,360); getsch(name); if (search(name)==1) if (x!=0) { ins=temp; insbef(name); } else del(name); else { cleardevice(); outtextxy(220,220,"Entry not found"); } } /* Details */ void detail(void) { cleardevice(); details(); outtextxy(140,160,"Name: "); outtextxy(340,160,temp->name); outtextxy(140,190,"Roll no: "); outtextxy(340,190,temp->num); outtextxy(140,220,"Semester "); outtextxy(340,220,temp->sem); outtextxy(140,250,"Discipline "); outtextxy(340,250,temp->disc); outtextxy(140,280,"Batch "); outtextxy(340,280,temp->batch); outtextxy(140,310,"Section "); outtextxy(340,310,temp->sec); gotoxy(24,24); getch(); } /* Input Data */ int input(void) { cleardevice(); outtextxy(4,20,"Enter a name.\n"); moveto(300,20); getsch(data.name); if (search(data.name)==1) { cleardevice(); outtextxy(180,220,"This name already exist"); strcpy(data.name,NULL); return(1); } outtextxy (4,40,"Enter Roll no."); moveto(300,40); getsch(data.num); outtextxy (4,60,"Enter Batch."); moveto(300,60); getsch(data.batch); outtextxy (4,80,"Enter Department."); moveto(300,80); getsch(data.disc); outtextxy (4,100,"Enter Semester."); moveto(300,100); getsch(data.sem); outtextxy (4,120,"Enter Section."); moveto(300,120); getsch(data.sec); return(0); } void delfile(void) { fptr=fopen("myfile.rec", "wb+"); setcolor(2); if (c!='w') outtextxy(160,220,"Myfile.rec has been deleted successfully"); fclose(fptr); return; } void del(char name[20]) { if (strcmpi(first->name,name)==0) { ins=first; first=first->ptrnext; } else { ins=temp; if (ins->ptrnext==(struct numlist *)NULL) temp->ptrnext=(struct numlist *)NULL; else temp->ptrnext=ins->ptrnext->ptrnext; } } void insbef(char name[20]) { ins = new numlist; if (strcmpi(name,first->name)==0) { temp=first; ins->ptrnext=temp; first=ins; } else { ins->ptrnext=temp->ptrnext; temp->ptrnext=ins; } data.ptrnext=ins->ptrnext; if (c!='o') if(input()==1) { temp->ptrnext=ins->ptrnext; free(ins); return; } *ins=data; temp=temp->ptrnext; temp=ins; } void sortname(void) { struct numlist *p, *q, *r; p = new numlist; q = new numlist; r = new numlist; ins=first; while(ins->ptrnext!=(struct numlist *)NULL) { temp=first; do{ if (strcmpi(first->name,first->ptrnext->name)>0) { p=first; q=first->ptrnext; p->ptrnext=q->ptrnext; q->ptrnext=p; first=q; } else { r=temp; temp=temp->ptrnext; if (strcmpi(temp->name,temp->ptrnext->name)>0) { p=temp; q=temp->ptrnext; p->ptrnext=q->ptrnext; q->ptrnext=p; r->ptrnext=q; temp=r->ptrnext; } } }while(r->ptrnext->ptrnext->ptrnext!=(struct numlist *)NULL); ins=ins->ptrnext; } } void sortnum(void) { struct numlist *p, *q, *r; p = new numlist; q = new numlist; r = new numlist; ins=first; while(ins->ptrnext!=(struct numlist *)NULL) { temp=first; do{ if( (atoi(first->num)) > (atoi(first->ptrnext->num))) { p=first; q=first->ptrnext; p->ptrnext=q->ptrnext; q->ptrnext=p; first=q; } else { r=temp; temp=temp->ptrnext; if((atoi(temp->num))>(atoi(temp->ptrnext->num))) { p=temp; q=temp->ptrnext; p->ptrnext=q->ptrnext; q->ptrnext=p; r->ptrnext=q; temp=r->ptrnext; } } }while(r->ptrnext->ptrnext->ptrnext!=(struct numlist *)NULL); ins=ins->ptrnext; } } char *getsch(char *name) { char cht[1],tname[20]; for(int t=0; t<=20; t++) { cht[0]=getch(); cht[1]=NULL; if((cht[0]>=65 && cht[0]<=90) || (cht[0]>=97 && cht[0]<=122) || cht[0]==13 || (cht[0]>=48 && cht[0]<=57)) { if (cht[0]==13) break; strcpy(name,cht); tname[t]=cht[0]; outtext(name); } else t--; } tname[t]='\x0'; strcpy(name,tname); return(name); } void start(void) { int i,j; settextstyle(TRIPLEX_FONT,HORIZ_DIR,2); setcolor(GREEN); for(i=440;i>=200;i--) { if(kbhit()) break; cleardevice(); moveto(40,i); outtext("IN THE NAME OF ALLAH MOST GRACIOUS AND MERCIFUL"); delay(10); } getch(); } void next(void) { int i,j; settextstyle(TRIPLEX_FONT,HORIZ_DIR,5); setcolor(4); for(i=0;i<=150;i++) { cleardevice(); moveto(100,i); outtext("STUDENT INFORMATION"); moveto(250,400-i); outtext("SYSTEM"); delay(25); } settextstyle(TRIPLEX_FONT,HORIZ_DIR,1); setcolor(12); moveto(250,400); outtext("PRESS ANY KEY"); settextstyle(TRIPLEX_FONT,HORIZ_DIR,5); setcolor(4); for(i=0;i>=0;i++) { if(kbhit()) break; for(j=0;j<=15;j++) { setcolor(i); moveto(100,150); outtext("STUDENT INFORMATION"); moveto(250,250); outtext("SYSTEM"); } } getch(); } void credits(void) { int j,op; setcolor(9); for(j=400;j>=-220;j--) { if(kbhit()) return; cleardevice(); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,6); moveto(150,j); outtext("PROGRAMMERS"); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,4); moveto(200,j+80); outtext("FAHAD AZIZ QIDWAI"); moveto(200,j+110); outtext("M.FAIZAN"); delay(25); } getch(); } void details(void) { int i; cleardevice(); setfillstyle(1,BLACK); bar3d(125,50,510,410,5,5); rectangle(125,50,510,410); line(125,100,510,100); line(125,370,510,370); moveto(150,375); outtext("[B] TO MENU"); }