Doubly Linked List Implementation

harshchandra 0 Tallied Votes 343 Views Share

This program maintains a employee's record using Doubly linked list.It was a weekly project submission by me for the course CI 031 .Invloves simple graphics and a login menu where i had used file handling to maintain a record of 3 user's name and their password .So before running the program kindly create a text document in d:\ with the name LOGIN.txt .In this just add the following data :

ceo computer
manager mouse
admin hello123

i.e only 3 persons can be allowed to login with their respective passwrd.
Platforn : Turbo c++ IDE

///////////////////////////////////////////////////////////////////////////
///////////////////                EMPLOYEE RECORDS 	      //////////////
/////////////////////////////////////////////////////////////////////////

/*  REFERENCES : DATA STRUCTURES THROUGH C - Y. KARNETKAR.
		 GRAPHICS UNDER C          - Y. KARNETKAR.
		 LET US C                  - Y. KARNETKAR.
		 PROGRAMMING WITH C        - SCAUM'S OUTLINE.
		 THE C LANGUAGE            - E. BALAGURUSWAMY.
		 WWW.PROGRAMMERSHEAVEN.COM
		 TURBO C++ IDE HELP INDEX
*/
/**********************************************************************
  This project is submitted by Harsh Chandra B.Tech ,2nd year,CSE on
  account of  regular project submission as mentioned in the coarse
  prescribed CI031-Data Structures.This project can be used by anyone
  in future.If any changes made plzz do inform us on harshchandra@gmail.com.  Since this project is highly commented,so i dont think that anymore explanation is needed,however for any further queries plzz contact   on above Email ID.
**********************************************************************/


#include<dos.h>
#include<string.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<alloc.h>
struct login           /* Used for records of authorised login */
{  char username[30];
   char password[15];
};
struct login l[3];/* as authorised users are ceo,manager and administrator */

struct employee
{                       /* structure of Double linked list */
 int employee_no;
 char employee_name[20];
 float grosspay;
 char designation[10];
 int age;
 char sex[6];
 struct employee *nextptr;
 struct employee *previousptr;
};

typedef struct employee employee;
/*********************************FUNCTION PROTOTYPE***************************/
void music(int);                          /*    FOR GENERATING SOUND       */
void border_margin(void);               /*     CREATING BORDER           */
void printmain(void);                 /*     PRINTING MAIN             */
void new_employee();                /*   APPEND FUNCTIONS            */
void display(employee *);         /*  PRINTING THE RECORDS         */
void delete_employee();         /*  DELETING THE RECORDS         */
void update();                /*    TO MODIFY FUNCTION         */
void search_employee(int);  /*    SEARCHING RECORDS          */
void printdetail(void);
employee *getnode(int);       /* FOR CREATING NEW NODES (MALLOC) */
employee *head=NULL;      /* INITIALLY LINKED LIST IS EMPTY  */
employee *tail=NULL;

/******************************************************************************/

int k,i,j,count=0;
char ans,choice,choice1,choice2,choice3; /* for accessing menu */
void main()
{     /* request auto detection */
	 int gdriver = DETECT, gmode, errorcode;
	 int maxx, maxy,i,count=0,flag=0;
	 /* initialize graphics, local variables */
	 initgraph(&gdriver, &gmode, "c:\\tc\\bgi");

	 /* read result of initialization */
	 errorcode = graphresult();
	 if (errorcode != grOk) /* If an error occurred as grOK means no error */
	 {  clrscr();
		 printf("Graphics Error Detected : %s\n", grapherrormsg(errorcode));
		 printf("Press any key to halt....");
		 printf("\nThank You.\t\n- Comp. Science Students.\n  Batch : C-5 and C6");
		 printf("\n  Jaypee University Of Information Technology , Waknaghat");
		 getch();
		 exit(0);  /* Terminate with an error code */
	 }

	  maxx = getmaxx();
	  maxy = getmaxy();
	  setcolor(YELLOW);              /*    select drawing color           */
	  setfillstyle(SOLID_FILL,BLUE);  /*     select fill color             */
	  rectangle(0, 0, maxx, maxy);   /*   draw a border around the screen */
	  bar(0,0,maxx,maxy);           /*    for painting background blue   */
	  settextstyle(5,0,6);
	  outtextxy(130,50,"Employee Records");
	  outtextxy(250,130,"Of A");
	  outtextxy(210,210,"Company");
	  settextstyle(2,0,7);
	  outtextxy(120,300,"A DOUBLY LINKED LIST IMPLEMENTATION");
	  settextstyle(2,0,4);
	  outtextxy(100,360,"PRESS A KEY TO CONTINUE ....");
	  music(3);
/********************** END OF INTRO SCREEN **************************************/

	 cleardevice();  /* CLEARS THE SCREEN */
	 settextstyle(0,0,0);
	 setfillstyle(SOLID_FILL,BLUE);  /*  select fill color               */
	 rectangle(0, 0, maxx, maxy);   /*   draw a border around the screen */
	 bar(0,0,maxx,maxy);           /*    for painting background blue      */
	 setcolor(YELLOW);
	 outtextxy(25,30,"ÿ");outtextxy(30,30,"Î");
	 outtextxy(30,25,"º");
	 for(i=35;i<=450;i+=5)
		outtextxy(30,i,"º");
	 for(i=35;i<=600;i+=5)
		outtextxy(i,30,"ÿ");
	 settextstyle(5,0,5);outtextxy(90,50,"About the Project");
	 char str1[70]={"Programmers : Students Of Batch C5 & C6"};
	 char str2[30]={"Platform    : Turbo C++ IDE"};
	 char str3[30]={"Duration    : Approx 10 Days"};
	 char str4[34]={"Instructor  : Mr.Satish Chandra"};
	 char str5[30]={"Contacts    : +919816184767"};
	 char str6[30]={"®® Press A Key To Continue ¯¯"};
	 int j=10,k=12;
	 settextstyle(0,0,0);
	 for(i=0;str1[i]!='\0';i++)
	 {  gotoxy(j,k);printf("");delay(5);
	    gotoxy(j,k);printf("%c",str1[i]);
	    music(4);
	    j++;
	 }
	 music(5);
	 j=10;k=14;
	 for(i=0;str2[i]!='\0';i++)
	 {  gotoxy(j,k);printf("");delay(5);
	    gotoxy(j,k);printf("%c",str2[i]);
	    music(4);
	    j++;
	 }
	 music(5);
	 j=10;k=16;
	 for(i=0;str3[i]!='\0';i++)
	 {  gotoxy(j,k);printf("");delay(5);
	    gotoxy(j,k);printf("%c",str3[i]);
	    music(4);
	    j++;
	 }
	 music(5);
	 j=10;k=18;
	 for(i=0;str4[i]!='\0';i++)
	 {  gotoxy(j,k);printf("");delay(5);
	    gotoxy(j,k);printf("%c",str4[i]);
	    music(4);
	    j++;
	 }
	 music(5);
	 j=10;k=20;
	 for(i=0;str5[i]!='\0';i++)
	 {  gotoxy(j,k);printf("");delay(5);
	    gotoxy(j,k);printf("%c",str5[i]);
	    music(4);
	    j++;
	 }
	 music(5);
	 j=25;k=24;
	 for(i=0;str6[i]!='\0';i++)
	 {  gotoxy(j,k);printf("");delay(5);
		 gotoxy(j,k);printf("%c",str6[i]);
		 music(4);
		 j++;
	 }
	 getch();
/*************************** END OF SECOND SCREEN **********************************/

// LOGIN MENU
	 cleardevice();
	 logi:  /* label to return in case access is denied */
	 setfillstyle(SOLID_FILL,BLUE);  /*  select fill color               */
	 rectangle(0, 0, maxx, maxy);   /*   draw a border around the screen */
	 bar(0,0,maxx,maxy);           /*    for painting background blue      */
	 settextstyle(5,0,5);
	 setcolor(YELLOW);
	 outtextxy(110,90,"®® Login Menu ¯¯");
	 settextstyle(0,0,0);
	 k = 155;
	 outtextxy(150,220,"É");
	 for(i=0;i<=1050;i+=4)
	 {   outtextxy(k,220,"ÿ");
		  k++;
	 }
	 outtextxy(424,220,"»");outtextxy(150,225,"º");
	 outtextxy(150,230,"º");outtextxy(150,235,"º");
	 outtextxy(150,240,"º");outtextxy(150,245,"Ì");
	 outtextxy(424,225,"º");outtextxy(424,230,"º");
	 outtextxy(424,235,"º");outtextxy(424,240,"º");
	 outtextxy(424,245,"¹");outtextxy(150,250,"º");
	 outtextxy(150,255,"º");outtextxy(150,260,"º");
	 outtextxy(150,265,"È");outtextxy(424,250,"º");
	 outtextxy(424,255,"º");outtextxy(424,260,"º");
	 outtextxy(424,265,"¼");outtextxy(160,235,"USERNAME : ");
	 outtextxy(160,255,"PASSWORD : ");
	 k=155;
	 char str7[15],str8[10],character;
	 for(i=0;i<=1050;i+=4)
	 {   outtextxy(k,245,"ÿ");
	k++;
	 }
	 k=155;
	 for(i=0;i<=1050;i+=4)
	 {   outtextxy(k,265,"ÿ");
	k++;
	 }
	 gotoxy(31,15);gets(str7);
	 i=0;k=31;
	 do
	 {      character=getch(); /* These thing is done so that password is not visible*/
		gotoxy(k,17) ;printf("*");
		str8[i]=character;
		k++;
		i++;
	 }while(character != '.');
	 i--;
	 str8[i]='\0';
	 /* NOW COMING THE FILE HANDLING */
	FILE *fp;
	i=0;flag=0;
	fp=fopen("d:\LOGIN.txt","r+");/* login.txt already contains the username n paswd*/
	while(fscanf(fp,"%s\t%s\n",l[i].username,l[i].password)!= EOF)
	{
	  if(strcmp(str7,l[i].username)==0 && strcmp(str8,l[i].password)==0)
	  { flag=1;
	  }
	  i++;
	}
	settextstyle(10,0,1);
	if(flag==0)
	{  outtextxy(140,275,"®® ACCESS DENIED ¯¯ ");music(1);music(1);
		outtextxy(140,320,"PRESS A KEY TO CONTINUE...");
		getch();
		count++;
		if(count< 3)
		{  goto logi; /* i m giving 3 chances in case user make any mistakes */
		}
		else
		exit(0);/* go out of program as access is denied */
	}
	else
	{ outtextxy(140,275,"ACCESS GRANTED ¯ ¯ ¯");music(1);music(1);
	  outtextxy(140,320,"PRESS A KEY TO CONTINUE...");
	}
	fclose(fp);
	getch();
	closegraph();
	restorecrtmode();

/**********************************************************************************
			 Now coming to main menu if access granted                             */

 int key;
 main:
 printmain();  /* WILL PRINT THE MAIN MENU */
 gotoxy(45,21);choice=getche();
 switch(choice)
  {
	case '1':
	new_employee();   /* APPENDING THE RECORD */
	getch();
	goto main;


	case '2':
	clrscr();
	display(head);    /* PRINTING THE RECORDS */
	goto main;


	case '3':
	delete_employee();
	goto main;

	case '4':
	update();   /* MODIFYING THE RECORDS */
	goto main;

	case '5':
	clrscr();
	border_margin();
	gotoxy(25,6);cprintf("R E C O R D    S E A R C H");
	gotoxy(5,8);cprintf("ENTER THE EMPLOYEE NUMBER WHICH IS TO BE UPDATED : ");
	gotoxy(57,8);scanf("%d",&key);
	search_employee(key);
	getch();
	goto main;

	case '6':
		 border_margin();
		 gotoxy(25,11);cprintf("É");
		 k=26;
		 for(i=1;i<=24;i++)
		 { gotoxy(k,11);cprintf("ÿ");
			k++;
		 }
		 gotoxy(50,11);cprintf("»");
		 gotoxy(25,12);cprintf("º                        º");
		 gotoxy(25,13);cprintf("È");gotoxy(50,13);cprintf("¼");
		 k=26;
		 for(i=1;i<=24;i++)
		 { gotoxy(k,13);cprintf("ÿ");
			k++;
		 }
		 gotoxy(32,9);cprintf("QUITING ....");
		 k=26;
		 for(i=1;i<=24;i++)
		 { gotoxy(k,12);cprintf("ÿ");delay(50);
			k++;
		 }
		 gotoxy(22,19);textcolor(YELLOW + BLINK);
		 cprintf("PRESS A KEY TO RETURN TO WINDOWS");
		 gotoxy(30,17);textcolor(YELLOW);cprintf("B Y E    B Y E !!");
		 gotoxy(24,79);
		 getch();
		 break;

	default:
	goto main;

  }
  }


void new_employee()
{      clrscr();
       border_margin();
       employee *emp;
       textcolor(YELLOW);
       gotoxy(25,3);cprintf("E N T E R I N G   R E C O R D");
       printdetail();
       if(head==NULL&&tail==NULL)
       {    count++;
	    emp=getnode(count);
	    head=emp;
	    tail=emp;
	    emp->previousptr=NULL;
	    emp->nextptr=NULL;
	}

	else
	{    count++;
	     emp=getnode(count);
	     emp->previousptr=tail;
	     tail->nextptr=emp;
	     emp->nextptr=NULL;
	     tail=emp;
	}

  }



void display(employee *temp)
{ if(head==NULL)  /* EMPTY LINKED LIST */
  { clrscr();
    border_margin();
    gotoxy(25,10);cprintf("É");
      k=26;
  for(i=1;i<=24;i++)
  { gotoxy(k,10);cprintf("ÿ");
    k++;
  }
  gotoxy(50,10);cprintf("»");
  gotoxy(25,11);cprintf("º   NO RECORDS AVAILABLE º");
  gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");
  k=26;
  for(i=1;i<=24;i++)
  { gotoxy(k,12);cprintf("ÿ");
    k++;
  }
  music(1);music(1);

  }
  else
  { if(temp==head)
    do
    { clrscr();
      border_margin();
      gotoxy(25,5);cprintf("P R I N T I N G   R E C O R D");
      printdetail();
      gotoxy(20,7);cprintf("%d",temp->employee_no);
      gotoxy(20,9);puts(temp->employee_name);
      gotoxy(20,11);cprintf("%f",temp->grosspay);fflush(stdin);
      gotoxy(20,13);puts(temp->designation);
      gotoxy(20,15);cprintf("%d",temp->age);fflush(stdin);
      gotoxy(20,17);puts(temp->sex);

      gotoxy(25,20);cprintf("É");
      k=26;
  for(i=1;i<=24;i++)
  { gotoxy(k,20);cprintf("ÿ");
    k++;
  }
  gotoxy(50,20);cprintf("»");
  gotoxy(25,21);cprintf("º HIT KEY FOR NEXT RECORDº");
  gotoxy(25,22);cprintf("È");gotoxy(50,22);cprintf("¼");
  k=26;
  for(i=1;i<=24;i++)
  { gotoxy(k,22);cprintf("ÿ");
    k++;
  }
  music(1);music(1);
  getch();
  temp=temp->nextptr;

  }while(temp!=NULL);

   }
}

void delete_employee()
{
  int key,flag;
  employee *temp;
  temp=head;
  if(head==NULL)  /* EMPTY LINKED LIST */
  { clrscr();
    border_margin();
    gotoxy(25,10);cprintf("É");
      k=26;
  for(i=1;i<=24;i++)
  { gotoxy(k,10);cprintf("ÿ");
    k++;
  }
  gotoxy(50,10);cprintf("»");
  gotoxy(25,11);cprintf("º   NO RECORDS AVAILABLE º");
  gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");
  k=26;
  for(i=1;i<=24;i++)
  { gotoxy(k,12);cprintf("ÿ");
    k++;
  }
  music(1);music(1);
  goto last;
  }
  else
  { clrscr();
    border_margin();
    gotoxy(10,7);cprintf("ENTER THE EMPLOYEE NUMBER YOU WANT TO DELETE : ");
    gotoxy(55,7);scanf("%d",&key);
    border_margin();
    gotoxy(25,11);cprintf("É");
    k=26;
    for(i=1;i<=24;i++)
    { gotoxy(k,11);cprintf("ÿ");
      k++;
    }
    gotoxy(50,11);cprintf("»");
    gotoxy(25,12);cprintf("º                        º");
    gotoxy(25,13);cprintf("È");gotoxy(50,13);cprintf("¼");
    k=26;
    for(i=1;i<=24;i++)
    { gotoxy(k,13);cprintf("ÿ");
      k++;
    }
    gotoxy(25,9);cprintf("SEARCHING FOR RECORDS ...");
    k=26;
    for(i=1;i<=24;i++)
    { gotoxy(k,12);cprintf("ÿ");delay(50);
      k++;
    }
    gotoxy(22,19);textcolor(YELLOW);
    cprintf("PRESS A KEY TO RETURN TO CONTINUE ...");
    gotoxy(28,17);cprintf("SEARCHING COMPLETE");
    getch();

    /* traverse the entire linked list */
    while(temp!=NULL)
    {  if(temp->employee_no == key)
     {   flag++;
	 if(temp==head)   /* if node is first */
	 {   head=head->nextptr;
	     head->previousptr=NULL;
	 }
	 else
	 {  if(temp->nextptr==NULL) /* if node is last */
	    temp->previousptr->nextptr=NULL;
	    else
	    {  temp->previousptr->nextptr = temp->nextptr;
	       temp->nextptr->previousptr = temp->previousptr;
	    }
	    free(temp);
	  }
     }
      temp=temp->nextptr;
  }
  }
  if(flag==0)
  {   clrscr();
      border_margin();
      gotoxy(25,10);cprintf("É");
      k=26;
      for(i=1;i<=24;i++)
      { gotoxy(k,10);cprintf("ÿ");
	k++;
      }
      gotoxy(50,10);cprintf("»");
      gotoxy(25,11);cprintf("º     NO RECORDS FOUND   º");
      gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");
      k=26;
      for(i=1;i<=24;i++)
     { gotoxy(k,12);cprintf("ÿ");
       k++;
     }
     music(1);music(1);
     getch();
  }
  if(flag==1)
  { clrscr();
    border_margin();
    gotoxy(25,10);cprintf("É");
    k=26;
    for(i=1;i<=24;i++)
  { gotoxy(k,10);cprintf("ÿ");
    k++;
  }
  gotoxy(50,10);cprintf("»");
  gotoxy(25,11);cprintf("º     RECORD DELETED     º");
  gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");
  k=26;
  for(i=1;i<=24;i++)
  { gotoxy(k,12);cprintf("ÿ");
    k++;
  }
  music(1);music(1);
  getch();
  }
  last:
  getch();
}

void update()
{ int choice;
  char str[30];
  char f;
  employee *temp;
  temp=head;
  if(head==NULL)  /* EMPTY LINKED LIST */
  { clrscr();
    border_margin();
    gotoxy(25,10);cprintf("É");
      k=26;
  for(i=1;i<=24;i++)
  { gotoxy(k,10);cprintf("ÿ");
    k++;
  }
  gotoxy(50,10);cprintf("»");
  gotoxy(25,11);cprintf("º   NO RECORDS AVAILABLE º");
  gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");
  k=26;
  for(i=1;i<=24;i++)
  { gotoxy(k,12);cprintf("ÿ");
    k++;
  }
  music(1);music(1);

  }
  else
  { clrscr();
    border_margin();
    gotoxy(25,3);cprintf("R E C O R D    U P D A T E");
    gotoxy(5,5);cprintf("ENTER THE EMPLOYEE NUMBER WHICH IS TO BE UPDATED : ");
    gotoxy(57,5);scanf("%d",&choice);
    if(choice > count)
    { clrscr();
      border_margin();
      gotoxy(10,10);cprintf("EMPLOYEE NO NOT FOUND");
      getch();
      goto last;
    }
    again:
    gotoxy(5,10);cprintf("1. NAME ");gotoxy(5,11);cprintf("2. GROSS PAY");
    gotoxy(5,12);cprintf("3. DESIGNATION");gotoxy(5,13);cprintf("4. AGE");
    gotoxy(5,14);cprintf("5. SEX");
    gotoxy(5,16);cprintf("ENTER THE FIELD YOU WANT TO EDIT : ");
    gotoxy(41,16);fflush(stdin);f=getch();
    switch(f)
    {  case '1':
     fflush(stdin);
     gotoxy(5,18);cprintf("ENTER NEW NAME : ");gets(str);
     while(choice!=temp->employee_no)
     temp=temp->nextptr;
     clrscr();
     printdetail();
     gotoxy(20,7);printf("%d",temp->employee_no);
     strcpy(temp->employee_name,str);
     gotoxy(20,9);printf("%s",temp->employee_name);
     gotoxy(20,11);printf("%f",temp->grosspay);
     gotoxy(20,13);puts(temp->designation);
     gotoxy(20,15);printf("%d",temp->age);
     gotoxy(20,17);puts(temp->sex);
     break;
     case '2':
     float gp;
     fflush(stdin);
     gotoxy(20,18);cprintf("ENTER NEW GROSS : ");scanf("%f",&gp);
     while(choice!=temp->employee_no)
     temp=temp->nextptr;
     clrscr();
     printdetail();
     gotoxy(20,7);printf("%d",temp->employee_no);
     temp->grosspay = gp;
     gotoxy(20,9);printf("%s",temp->employee_name);
     gotoxy(20,11);printf("%f",temp->grosspay);
     gotoxy(20,13);puts(temp->designation);
     gotoxy(20,15);printf("%d",temp->age);
     gotoxy(20,17);puts(temp->sex);
     break;
     case '3':
     fflush(stdin);
     gotoxy(20,18);cprintf("ENTER NEW DESIGNATION : ");gets(str);
     while(choice!=temp->employee_no)
     temp=temp->nextptr;
     clrscr();
     printdetail();
     gotoxy(20,7);printf("%d",temp->employee_no);
     strcpy(temp->designation,str);
     gotoxy(20,9);printf("%s",temp->employee_name);
     gotoxy(20,11);printf("%f",temp->grosspay);
     gotoxy(20,13);puts(temp->designation);
     gotoxy(20,15);printf("%d",temp->age);
     gotoxy(20,17);puts(temp->sex);
     break;
     case '4':
     int gp1;
     fflush(stdin);
     gotoxy(20,18);cprintf("ENTER NEW AGE : ");scanf("%d",&gp1);
     while(choice!=temp->employee_no)
     temp=temp->nextptr;
     clrscr();
     printdetail();
     gotoxy(20,7);printf("%d",temp->employee_no);
     temp->age = gp1;
     gotoxy(20,9);printf("%s",temp->employee_name);
     gotoxy(20,11);printf("%f",temp->grosspay);
     gotoxy(20,13);puts(temp->designation);
     gotoxy(20,15);printf("%d",temp->age);
     gotoxy(20,17);puts(temp->sex);
     break;
     case '5':
     fflush(stdin);
     gotoxy(20,18);cprintf("ENTER NEW SEX : ");gets(str);
     while(choice!=temp->employee_no)
     temp=temp->nextptr;
     clrscr();
     printdetail();
     gotoxy(20,7);printf("%d",temp->employee_no);
     strcpy(temp->sex,str);
     gotoxy(20,9);printf("%s",temp->employee_name);
     gotoxy(20,11);printf("%f",temp->grosspay);
     gotoxy(20,13);puts(temp->designation);
     gotoxy(20,15);printf("%d",temp->age);
     gotoxy(20,17);puts(temp->sex);
     break;
     default:
     goto again;
  }
	gotoxy(25,20);cprintf("É");
	k=26;
	for(i=1;i<=24;i++)
	{ gotoxy(k,20);cprintf("ÿ");
	  k++;
	}
	gotoxy(50,20);cprintf("»");
	gotoxy(25,21);cprintf("º    RECORD    UPDATED   º");
	gotoxy(25,22);cprintf("È");gotoxy(50,22);cprintf("¼");
	k=26;
	for(i=1;i<=24;i++)
	{ gotoxy(k,22);cprintf("ÿ");
	  k++;
	}
	music(1);music(1);
   }
   last:
   getch();
}

employee *getnode(int count)
{ employee *nodeptr;
  nodeptr=(employee *)malloc(sizeof(employee));
  nodeptr->employee_no=count;
  gotoxy(20,7);printf("%d",nodeptr->employee_no);fflush(stdin);
  gotoxy(20,9);gets(nodeptr->employee_name);
  gotoxy(20,11);scanf("%f",&nodeptr->grosspay);fflush(stdin);
  gotoxy(20,13);gets(nodeptr->designation);
  gotoxy(20,15);scanf("%d",&nodeptr->age);fflush(stdin);
  gotoxy(20,17);gets(nodeptr->sex);
  gotoxy(25,20);cprintf("É");
  k=26;
  for(i=1;i<=24;i++)
  { gotoxy(k,20);cprintf("ÿ");
    k++;
  }
  gotoxy(50,20);cprintf("»");
  gotoxy(25,21);cprintf("º RECORD ENTRY SUCESSFUL º");
  gotoxy(25,22);cprintf("È");gotoxy(50,22);cprintf("¼");
  k=26;
  for(i=1;i<=24;i++)
  { gotoxy(k,22);cprintf("ÿ");
    k++;
  }
  music(1);music(1);
  nodeptr->previousptr=NULL;
  nodeptr->nextptr=NULL;
  return nodeptr;
}

void search_employee(int key)
{   employee *temp;
    clrscr();
    border_margin();
    gotoxy(25,11);cprintf("É");
    k=26;
    for(i=1;i<=24;i++)
    { gotoxy(k,11);cprintf("ÿ");
      k++;
    }
    gotoxy(50,11);cprintf("»");
    gotoxy(25,12);cprintf("º                        º");
    gotoxy(25,13);cprintf("È");gotoxy(50,13);cprintf("¼");
    k=26;
    for(i=1;i<=24;i++)
    { gotoxy(k,13);cprintf("ÿ");
      k++;
    }
    gotoxy(32,9);cprintf("SEARCHING...");
    k=26;
    for(i=1;i<=24;i++)
    { gotoxy(k,12);cprintf("ÿ");delay(50);
      k++;
    }
    gotoxy(22,19);textcolor(YELLOW);
    cprintf("PRESS A KEY TO RETURN TO CONTINUE >>");
    gotoxy(28,17);cprintf("SEARCHING COMPLETE");
    getch();
    temp=head;
    int flag=0;
    if(temp==NULL) /* LINKED LIST IS EMPTY */
    { clrscr();
      border_margin();
      gotoxy(25,10);cprintf("É");
      k=26;
      for(i=1;i<=24;i++)
      { gotoxy(k,10);cprintf("ÿ");
	k++;
      }
      gotoxy(50,10);cprintf("»");
      gotoxy(25,11);cprintf("º   NO RECORDS AVAILABLE º");
      gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");
      k=26;
      for(i=1;i<=24;i++)
      { gotoxy(k,12);cprintf("ÿ");
	k++;
      }
      music(1);music(1);
      goto last;
    }
    while(temp!=NULL)
    {   if(temp->employee_no==key)
	{ flag++;
	  printdetail();
	  gotoxy(20,7);printf("%d",temp->employee_no);
	  gotoxy(20,9);puts(temp->employee_name);
	  gotoxy(20,11);printf("%f",temp->grosspay);
	  gotoxy(20,13);gets(temp->designation);
	  gotoxy(20,15);printf("%d",temp->age);
	  gotoxy(20,17);puts(temp->sex);
	  gotoxy(25,20);cprintf("É");
	  k=26;
	  for(i=1;i<=24;i++)
	  { gotoxy(k,20);cprintf("ÿ");
	    k++;
	  }
	  gotoxy(50,20);cprintf("»");
	  gotoxy(25,21);cprintf("º       RECORD FOUND     º");
	  gotoxy(25,22);cprintf("È");gotoxy(50,22);cprintf("¼");
	  k=26;
	  for(i=1;i<=24;i++)
	  { gotoxy(k,22);cprintf("ÿ");
	    k++;
	  }
	  music(1);music(1);
	}
	temp=temp->nextptr;
     }
      if(flag==0)
      { clrscr();
	border_margin();
	clrscr();
	border_margin();
	gotoxy(25,10);cprintf("É");
	k=26;
	for(i=1;i<=24;i++)
	{ gotoxy(k,10);cprintf("ÿ");
	  k++;
	}
	gotoxy(50,10);cprintf("»");
	gotoxy(25,11);cprintf("º    RECORDS NOT FOUND   º");
	gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");
	k=26;
	for(i=1;i<=24;i++)
	{ gotoxy(k,12);cprintf("ÿ");
	  k++;
	}
	music(1);music(1);
      }
   last:
}

void music(int no)
{   /* Natural frequncies of 7 notes */
	 float octave[7]={130.81,146.83,164.81,174.61,196,220,246.94};
	 int n,i;
	 switch(no)
	 {  case 1:
	 for(i=0;i<7;i++)
	 {  sound(octave[i] * 8);
		 delay(30);
	 }
	 nosound();
	 break;
		 case 2:
		 for(i=0;i<15;i++)
	 {  n=random(7);
		 sound(octave[n] * 4);
		 delay(100);
	 }
	 nosound();
	 break;
		 case 3:
		 while(!kbhit())
	 {  n=random(7);
		 sound(octave[n] * 4);
		 delay(100);
	 }
	 nosound();
	 if(getch()==0)
	 getch();
	 break;
		 case 4:
		 for(i=4;i>=0;i--)
	 {  sound(octave[i] * 4);
		 delay(15);
	 }
	 nosound();
	 break;
		 case 5:
		 sound(octave[6] * 2);
		 delay(50);

	 nosound();
	 }
 }

void border_margin()
{    clrscr();
	  textcolor(YELLOW);
	  int i,j=3;
	  gotoxy(2,2);cprintf("É");
	  for(i=0;i<74;i++)
	  { gotoxy(j,2);cprintf("ÿ");
		 j++;
	  }
	  gotoxy(77,2);cprintf("»");
	  j=3;
	  for(i=0;i<20;i++)
	  { gotoxy(2,j) ;cprintf("º");
		 gotoxy(77,j);cprintf("º");
		 j++;
	  }
	  gotoxy(2,23);cprintf("È");
	  j=3;
	  for(i=0;i<74;i++)
	  { gotoxy(j,23);cprintf("ÿ");
		 j++;
	  }
	  gotoxy(77,23);cprintf("¼");
}
void printmain()
{  int k,i;
	border_margin(); /* user defined function to draw margin */
	textbackground(0); /* sets background none */
	textcolor(YELLOW);/* set text color */
	textbackground(RED);
	gotoxy(6,4);cprintf("É");
	k=7;
	for(i=1;i<=24;i++)
	{ gotoxy(k,4);cprintf("ÿ");
	  k++;
	}
	gotoxy(31,4);cprintf("»");
	gotoxy(6,5);cprintf("º 1. ADD  RECORDS        º");
	gotoxy(6,6);cprintf("È");gotoxy(31,6);cprintf("¼");
	k=7;
	for(i=1;i<=24;i++)
	{ gotoxy(k,6);cprintf("ÿ");
	  k++;
	}

	gotoxy(43,4);cprintf("É");
	k=44;
	for(i=1;i<=24;i++)
	{ gotoxy(k,4);cprintf("ÿ");
	  k++;
	}
	gotoxy(68,4);cprintf("»");
	gotoxy(43,5);cprintf("º 2. DISPLAY  RECORDS    º");
	gotoxy(43,6);cprintf("È");gotoxy(68,6);cprintf("¼");
	k=44;
	for(i=1;i<=24;i++)
	{ gotoxy(k,6);cprintf("ÿ");
	  k++;
	}

	gotoxy(6,9);cprintf("É");
	k=7;
	for(i=1;i<=24;i++)
	{ gotoxy(k,9);cprintf("ÿ");
	  k++;
	}
	gotoxy(31,9);cprintf("»");
	gotoxy(6,10);cprintf("º 3. DELETE  RECORDS     º");
	gotoxy(6,11);cprintf("È");gotoxy(31,11);cprintf("¼");
	k=7;
	for(i=1;i<=24;i++)
	{ gotoxy(k,11);cprintf("ÿ");
	  k++;
	}

	gotoxy(43,9);cprintf("É");
	k=44;
	for(i=1;i<=24;i++)
	{ gotoxy(k,9);cprintf("ÿ");
	  k++;
	}
	gotoxy(68,9);cprintf("»");
	gotoxy(43,10);cprintf("º 4. UPDATE  RECORDS     º");
	gotoxy(43,11);cprintf("È");gotoxy(68,11);cprintf("¼");
	k=44;
	for(i=1;i<=24;i++)
	{ gotoxy(k,11);cprintf("ÿ");
	  k++;
	}

	gotoxy(6,14);cprintf("É");
	k=7;
	for(i=1;i<=24;i++)
	{ gotoxy(k,14);cprintf("ÿ");
	  k++;
	}
	gotoxy(31,14);cprintf("»");
	gotoxy(6,15);cprintf("º 5. SEARCH FOR RECORDS  º");
	gotoxy(6,16);cprintf("È");gotoxy(31,16);cprintf("¼");
	k=7;
	for(i=1;i<=24;i++)
	{ gotoxy(k,16);cprintf("ÿ");
	  k++;
	}

	gotoxy(43,14);cprintf("É");
	k=44;
	for(i=1;i<=24;i++)
	{ gotoxy(k,14);cprintf("ÿ");
	  k++;
	}
	gotoxy(68,14);cprintf("»");
	gotoxy(43,15);cprintf("º 6. QUIT                º");
	gotoxy(43,16);cprintf("È");gotoxy(68,16);cprintf("¼");
	k=44;
	for(i=1;i<=24;i++)
	{ gotoxy(k,16);cprintf("ÿ");
	  k++;
	}
	gotoxy(25,21);cprintf("ENTER YOUR CHOICE :   ");

}
void printdetail()
{      border_margin();
       gotoxy(5,7);cprintf("EMPLOYEE NO  : ");
       gotoxy(20,8);cprintf("____________________________________________");
       gotoxy(5,9);cprintf("NAME         : ");
       gotoxy(20,10);cprintf("____________________________________________");
       gotoxy(5,11);cprintf("GROSS PAY    : ");
       gotoxy(20,12);cprintf("____________________________________________");
       gotoxy(5,13);cprintf("DESIGNATION  : ");
       gotoxy(20,14);cprintf("____________________________________________");
       gotoxy(5,15);cprintf("AGE          : ");
       gotoxy(20,16);cprintf("____________________________________________");
       gotoxy(5,17);cprintf("SEX          : ");
       gotoxy(20,18);cprintf("____________________________________________");
}
free_eagle 0 Light Poster

Wow that's great ...

Xmm you know I wonder ...nowadays I am trying to learn C language through analysing this kind of code's how do you think is it good way or not ... I am just studying myself ...selflearner...

Anyway let men know see your code..

Best wishes.

ylnsagar 0 Newbie Poster

hey its a very good program. the way you are programming is very good, i need your phone number, so that i can contact you.

sagar

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.