944,087 Members | Top Members by Rank

Ad:
  • C Code Snippet
  • Views: 75052
  • C RSS
0

Doubly Linked List Implementation

by on Nov 21st, 2004
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
C Code Snippet (Toggle Plain Text)
  1. ///////////////////////////////////////////////////////////////////////////
  2. /////////////////// EMPLOYEE RECORDS //////////////
  3. /////////////////////////////////////////////////////////////////////////
  4.  
  5. /* REFERENCES : DATA STRUCTURES THROUGH C - Y. KARNETKAR.
  6. GRAPHICS UNDER C - Y. KARNETKAR.
  7. LET US C - Y. KARNETKAR.
  8. PROGRAMMING WITH C - SCAUM'S OUTLINE.
  9. THE C LANGUAGE - E. BALAGURUSWAMY.
  10. WWW.PROGRAMMERSHEAVEN.COM
  11. TURBO C++ IDE HELP INDEX
  12. */
  13. /**********************************************************************
  14.   This project is submitted by Harsh Chandra B.Tech ,2nd year,CSE on
  15.   account of regular project submission as mentioned in the coarse
  16.   prescribed CI031-Data Structures.This project can be used by anyone
  17.   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.
  18. **********************************************************************/
  19.  
  20.  
  21. #include<dos.h>
  22. #include<string.h>
  23. #include <graphics.h>
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <conio.h>
  27. #include<alloc.h>
  28. struct login /* Used for records of authorised login */
  29. { char username[30];
  30. char password[15];
  31. };
  32. struct login l[3];/* as authorised users are ceo,manager and administrator */
  33.  
  34. struct employee
  35. { /* structure of Double linked list */
  36. int employee_no;
  37. char employee_name[20];
  38. float grosspay;
  39. char designation[10];
  40. int age;
  41. char sex[6];
  42. struct employee *nextptr;
  43. struct employee *previousptr;
  44. };
  45.  
  46. typedef struct employee employee;
  47. /*********************************FUNCTION PROTOTYPE***************************/
  48. void music(int); /* FOR GENERATING SOUND */
  49. void border_margin(void); /* CREATING BORDER */
  50. void printmain(void); /* PRINTING MAIN */
  51. void new_employee(); /* APPEND FUNCTIONS */
  52. void display(employee *); /* PRINTING THE RECORDS */
  53. void delete_employee(); /* DELETING THE RECORDS */
  54. void update(); /* TO MODIFY FUNCTION */
  55. void search_employee(int); /* SEARCHING RECORDS */
  56. void printdetail(void);
  57. employee *getnode(int); /* FOR CREATING NEW NODES (MALLOC) */
  58. employee *head=NULL; /* INITIALLY LINKED LIST IS EMPTY */
  59. employee *tail=NULL;
  60.  
  61. /******************************************************************************/
  62.  
  63. int k,i,j,count=0;
  64. char ans,choice,choice1,choice2,choice3; /* for accessing menu */
  65. void main()
  66. { /* request auto detection */
  67. int gdriver = DETECT, gmode, errorcode;
  68. int maxx, maxy,i,count=0,flag=0;
  69. /* initialize graphics, local variables */
  70. initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
  71.  
  72. /* read result of initialization */
  73. errorcode = graphresult();
  74. if (errorcode != grOk) /* If an error occurred as grOK means no error */
  75. { clrscr();
  76. printf("Graphics Error Detected : %s\n", grapherrormsg(errorcode));
  77. printf("Press any key to halt....");
  78. printf("\nThank You.\t\n- Comp. Science Students.\n Batch : C-5 and C6");
  79. printf("\n Jaypee University Of Information Technology , Waknaghat");
  80. getch();
  81. exit(0); /* Terminate with an error code */
  82. }
  83.  
  84. maxx = getmaxx();
  85. maxy = getmaxy();
  86. setcolor(YELLOW); /* select drawing color */
  87. setfillstyle(SOLID_FILL,BLUE); /* select fill color */
  88. rectangle(0, 0, maxx, maxy); /* draw a border around the screen */
  89. bar(0,0,maxx,maxy); /* for painting background blue */
  90. settextstyle(5,0,6);
  91. outtextxy(130,50,"Employee Records");
  92. outtextxy(250,130,"Of A");
  93. outtextxy(210,210,"Company");
  94. settextstyle(2,0,7);
  95. outtextxy(120,300,"A DOUBLY LINKED LIST IMPLEMENTATION");
  96. settextstyle(2,0,4);
  97. outtextxy(100,360,"PRESS A KEY TO CONTINUE ....");
  98. music(3);
  99. /********************** END OF INTRO SCREEN **************************************/
  100.  
  101. cleardevice(); /* CLEARS THE SCREEN */
  102. settextstyle(0,0,0);
  103. setfillstyle(SOLID_FILL,BLUE); /* select fill color */
  104. rectangle(0, 0, maxx, maxy); /* draw a border around the screen */
  105. bar(0,0,maxx,maxy); /* for painting background blue */
  106. setcolor(YELLOW);
  107. outtextxy(25,30,"ÿ");outtextxy(30,30,"Î");
  108. outtextxy(30,25,"º");
  109. for(i=35;i<=450;i+=5)
  110. outtextxy(30,i,"º");
  111. for(i=35;i<=600;i+=5)
  112. outtextxy(i,30,"ÿ");
  113. settextstyle(5,0,5);outtextxy(90,50,"About the Project");
  114. char str1[70]={"Programmers : Students Of Batch C5 & C6"};
  115. char str2[30]={"Platform : Turbo C++ IDE"};
  116. char str3[30]={"Duration : Approx 10 Days"};
  117. char str4[34]={"Instructor : Mr.Satish Chandra"};
  118. char str5[30]={"Contacts : +919816184767"};
  119. char str6[30]={"®® Press A Key To Continue ¯¯"};
  120. int j=10,k=12;
  121. settextstyle(0,0,0);
  122. for(i=0;str1[i]!='\0';i++)
  123. { gotoxy(j,k);printf("");delay(5);
  124. gotoxy(j,k);printf("%c",str1[i]);
  125. music(4);
  126. j++;
  127. }
  128. music(5);
  129. j=10;k=14;
  130. for(i=0;str2[i]!='\0';i++)
  131. { gotoxy(j,k);printf("");delay(5);
  132. gotoxy(j,k);printf("%c",str2[i]);
  133. music(4);
  134. j++;
  135. }
  136. music(5);
  137. j=10;k=16;
  138. for(i=0;str3[i]!='\0';i++)
  139. { gotoxy(j,k);printf("");delay(5);
  140. gotoxy(j,k);printf("%c",str3[i]);
  141. music(4);
  142. j++;
  143. }
  144. music(5);
  145. j=10;k=18;
  146. for(i=0;str4[i]!='\0';i++)
  147. { gotoxy(j,k);printf("");delay(5);
  148. gotoxy(j,k);printf("%c",str4[i]);
  149. music(4);
  150. j++;
  151. }
  152. music(5);
  153. j=10;k=20;
  154. for(i=0;str5[i]!='\0';i++)
  155. { gotoxy(j,k);printf("");delay(5);
  156. gotoxy(j,k);printf("%c",str5[i]);
  157. music(4);
  158. j++;
  159. }
  160. music(5);
  161. j=25;k=24;
  162. for(i=0;str6[i]!='\0';i++)
  163. { gotoxy(j,k);printf("");delay(5);
  164. gotoxy(j,k);printf("%c",str6[i]);
  165. music(4);
  166. j++;
  167. }
  168. getch();
  169. /*************************** END OF SECOND SCREEN **********************************/
  170.  
  171. // LOGIN MENU
  172. cleardevice();
  173. logi: /* label to return in case access is denied */
  174. setfillstyle(SOLID_FILL,BLUE); /* select fill color */
  175. rectangle(0, 0, maxx, maxy); /* draw a border around the screen */
  176. bar(0,0,maxx,maxy); /* for painting background blue */
  177. settextstyle(5,0,5);
  178. setcolor(YELLOW);
  179. outtextxy(110,90,"®® Login Menu ¯¯");
  180. settextstyle(0,0,0);
  181. k = 155;
  182. outtextxy(150,220,"É");
  183. for(i=0;i<=1050;i+=4)
  184. { outtextxy(k,220,"ÿ");
  185. k++;
  186. }
  187. outtextxy(424,220,"»");outtextxy(150,225,"º");
  188. outtextxy(150,230,"º");outtextxy(150,235,"º");
  189. outtextxy(150,240,"º");outtextxy(150,245,"Ì");
  190. outtextxy(424,225,"º");outtextxy(424,230,"º");
  191. outtextxy(424,235,"º");outtextxy(424,240,"º");
  192. outtextxy(424,245,"¹");outtextxy(150,250,"º");
  193. outtextxy(150,255,"º");outtextxy(150,260,"º");
  194. outtextxy(150,265,"È");outtextxy(424,250,"º");
  195. outtextxy(424,255,"º");outtextxy(424,260,"º");
  196. outtextxy(424,265,"¼");outtextxy(160,235,"USERNAME : ");
  197. outtextxy(160,255,"PASSWORD : ");
  198. k=155;
  199. char str7[15],str8[10],character;
  200. for(i=0;i<=1050;i+=4)
  201. { outtextxy(k,245,"ÿ");
  202. k++;
  203. }
  204. k=155;
  205. for(i=0;i<=1050;i+=4)
  206. { outtextxy(k,265,"ÿ");
  207. k++;
  208. }
  209. gotoxy(31,15);gets(str7);
  210. i=0;k=31;
  211. do
  212. { character=getch(); /* These thing is done so that password is not visible*/
  213. gotoxy(k,17) ;printf("*");
  214. str8[i]=character;
  215. k++;
  216. i++;
  217. }while(character != '.');
  218. i--;
  219. str8[i]='\0';
  220. /* NOW COMING THE FILE HANDLING */
  221. FILE *fp;
  222. i=0;flag=0;
  223. fp=fopen("d:\LOGIN.txt","r+");/* login.txt already contains the username n paswd*/
  224. while(fscanf(fp,"%s\t%s\n",l[i].username,l[i].password)!= EOF)
  225. {
  226. if(strcmp(str7,l[i].username)==0 && strcmp(str8,l[i].password)==0)
  227. { flag=1;
  228. }
  229. i++;
  230. }
  231. settextstyle(10,0,1);
  232. if(flag==0)
  233. { outtextxy(140,275,"®® ACCESS DENIED ¯¯ ");music(1);music(1);
  234. outtextxy(140,320,"PRESS A KEY TO CONTINUE...");
  235. getch();
  236. count++;
  237. if(count< 3)
  238. { goto logi; /* i m giving 3 chances in case user make any mistakes */
  239. }
  240. else
  241. exit(0);/* go out of program as access is denied */
  242. }
  243. else
  244. { outtextxy(140,275,"ACCESS GRANTED ¯ ¯ ¯");music(1);music(1);
  245. outtextxy(140,320,"PRESS A KEY TO CONTINUE...");
  246. }
  247. fclose(fp);
  248. getch();
  249. closegraph();
  250. restorecrtmode();
  251.  
  252. /**********************************************************************************
  253. Now coming to main menu if access granted */
  254.  
  255. int key;
  256. main:
  257. printmain(); /* WILL PRINT THE MAIN MENU */
  258. gotoxy(45,21);choice=getche();
  259. switch(choice)
  260. {
  261. case '1':
  262. new_employee(); /* APPENDING THE RECORD */
  263. getch();
  264. goto main;
  265.  
  266.  
  267. case '2':
  268. clrscr();
  269. display(head); /* PRINTING THE RECORDS */
  270. goto main;
  271.  
  272.  
  273. case '3':
  274. delete_employee();
  275. goto main;
  276.  
  277. case '4':
  278. update(); /* MODIFYING THE RECORDS */
  279. goto main;
  280.  
  281. case '5':
  282. clrscr();
  283. border_margin();
  284. gotoxy(25,6);cprintf("R E C O R D S E A R C H");
  285. gotoxy(5,8);cprintf("ENTER THE EMPLOYEE NUMBER WHICH IS TO BE UPDATED : ");
  286. gotoxy(57,8);scanf("%d",&key);
  287. search_employee(key);
  288. getch();
  289. goto main;
  290.  
  291. case '6':
  292. border_margin();
  293. gotoxy(25,11);cprintf("É");
  294. k=26;
  295. for(i=1;i<=24;i++)
  296. { gotoxy(k,11);cprintf("ÿ");
  297. k++;
  298. }
  299. gotoxy(50,11);cprintf("»");
  300. gotoxy(25,12);cprintf("º º");
  301. gotoxy(25,13);cprintf("È");gotoxy(50,13);cprintf("¼");
  302. k=26;
  303. for(i=1;i<=24;i++)
  304. { gotoxy(k,13);cprintf("ÿ");
  305. k++;
  306. }
  307. gotoxy(32,9);cprintf("QUITING ....");
  308. k=26;
  309. for(i=1;i<=24;i++)
  310. { gotoxy(k,12);cprintf("ÿ");delay(50);
  311. k++;
  312. }
  313. gotoxy(22,19);textcolor(YELLOW + BLINK);
  314. cprintf("PRESS A KEY TO RETURN TO WINDOWS");
  315. gotoxy(30,17);textcolor(YELLOW);cprintf("B Y E B Y E !!");
  316. gotoxy(24,79);
  317. getch();
  318. break;
  319.  
  320. default:
  321. goto main;
  322.  
  323. }
  324. }
  325.  
  326.  
  327. void new_employee()
  328. { clrscr();
  329. border_margin();
  330. employee *emp;
  331. textcolor(YELLOW);
  332. gotoxy(25,3);cprintf("E N T E R I N G R E C O R D");
  333. printdetail();
  334. if(head==NULL&&tail==NULL)
  335. { count++;
  336. emp=getnode(count);
  337. head=emp;
  338. tail=emp;
  339. emp->previousptr=NULL;
  340. emp->nextptr=NULL;
  341. }
  342.  
  343. else
  344. { count++;
  345. emp=getnode(count);
  346. emp->previousptr=tail;
  347. tail->nextptr=emp;
  348. emp->nextptr=NULL;
  349. tail=emp;
  350. }
  351.  
  352. }
  353.  
  354.  
  355.  
  356. void display(employee *temp)
  357. { if(head==NULL) /* EMPTY LINKED LIST */
  358. { clrscr();
  359. border_margin();
  360. gotoxy(25,10);cprintf("É");
  361. k=26;
  362. for(i=1;i<=24;i++)
  363. { gotoxy(k,10);cprintf("ÿ");
  364. k++;
  365. }
  366. gotoxy(50,10);cprintf("»");
  367. gotoxy(25,11);cprintf("º NO RECORDS AVAILABLE º");
  368. gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");
  369. k=26;
  370. for(i=1;i<=24;i++)
  371. { gotoxy(k,12);cprintf("ÿ");
  372. k++;
  373. }
  374. music(1);music(1);
  375.  
  376. }
  377. else
  378. { if(temp==head)
  379. do
  380. { clrscr();
  381. border_margin();
  382. gotoxy(25,5);cprintf("P R I N T I N G R E C O R D");
  383. printdetail();
  384. gotoxy(20,7);cprintf("%d",temp->employee_no);
  385. gotoxy(20,9);puts(temp->employee_name);
  386. gotoxy(20,11);cprintf("%f",temp->grosspay);fflush(stdin);
  387. gotoxy(20,13);puts(temp->designation);
  388. gotoxy(20,15);cprintf("%d",temp->age);fflush(stdin);
  389. gotoxy(20,17);puts(temp->sex);
  390.  
  391. gotoxy(25,20);cprintf("É");
  392. k=26;
  393. for(i=1;i<=24;i++)
  394. { gotoxy(k,20);cprintf("ÿ");
  395. k++;
  396. }
  397. gotoxy(50,20);cprintf("»");
  398. gotoxy(25,21);cprintf("º HIT KEY FOR NEXT RECORDº");
  399. gotoxy(25,22);cprintf("È");gotoxy(50,22);cprintf("¼");
  400. k=26;
  401. for(i=1;i<=24;i++)
  402. { gotoxy(k,22);cprintf("ÿ");
  403. k++;
  404. }
  405. music(1);music(1);
  406. getch();
  407. temp=temp->nextptr;
  408.  
  409. }while(temp!=NULL);
  410.  
  411. }
  412. }
  413.  
  414. void delete_employee()
  415. {
  416. int key,flag;
  417. employee *temp;
  418. temp=head;
  419. if(head==NULL) /* EMPTY LINKED LIST */
  420. { clrscr();
  421. border_margin();
  422. gotoxy(25,10);cprintf("É");
  423. k=26;
  424. for(i=1;i<=24;i++)
  425. { gotoxy(k,10);cprintf("ÿ");
  426. k++;
  427. }
  428. gotoxy(50,10);cprintf("»");
  429. gotoxy(25,11);cprintf("º NO RECORDS AVAILABLE º");
  430. gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");
  431. k=26;
  432. for(i=1;i<=24;i++)
  433. { gotoxy(k,12);cprintf("ÿ");
  434. k++;
  435. }
  436. music(1);music(1);
  437. goto last;
  438. }
  439. else
  440. { clrscr();
  441. border_margin();
  442. gotoxy(10,7);cprintf("ENTER THE EMPLOYEE NUMBER YOU WANT TO DELETE : ");
  443. gotoxy(55,7);scanf("%d",&key);
  444. border_margin();
  445. gotoxy(25,11);cprintf("É");
  446. k=26;
  447. for(i=1;i<=24;i++)
  448. { gotoxy(k,11);cprintf("ÿ");
  449. k++;
  450. }
  451. gotoxy(50,11);cprintf("»");
  452. gotoxy(25,12);cprintf("º º");
  453. gotoxy(25,13);cprintf("È");gotoxy(50,13);cprintf("¼");
  454. k=26;
  455. for(i=1;i<=24;i++)
  456. { gotoxy(k,13);cprintf("ÿ");
  457. k++;
  458. }
  459. gotoxy(25,9);cprintf("SEARCHING FOR RECORDS ...");
  460. k=26;
  461. for(i=1;i<=24;i++)
  462. { gotoxy(k,12);cprintf("ÿ");delay(50);
  463. k++;
  464. }
  465. gotoxy(22,19);textcolor(YELLOW);
  466. cprintf("PRESS A KEY TO RETURN TO CONTINUE ...");
  467. gotoxy(28,17);cprintf("SEARCHING COMPLETE");
  468. getch();
  469.  
  470. /* traverse the entire linked list */
  471. while(temp!=NULL)
  472. { if(temp->employee_no == key)
  473. { flag++;
  474. if(temp==head) /* if node is first */
  475. { head=head->nextptr;
  476. head->previousptr=NULL;
  477. }
  478. else
  479. { if(temp->nextptr==NULL) /* if node is last */
  480. temp->previousptr->nextptr=NULL;
  481. else
  482. { temp->previousptr->nextptr = temp->nextptr;
  483. temp->nextptr->previousptr = temp->previousptr;
  484. }
  485. free(temp);
  486. }
  487. }
  488. temp=temp->nextptr;
  489. }
  490. }
  491. if(flag==0)
  492. { clrscr();
  493. border_margin();
  494. gotoxy(25,10);cprintf("É");
  495. k=26;
  496. for(i=1;i<=24;i++)
  497. { gotoxy(k,10);cprintf("ÿ");
  498. k++;
  499. }
  500. gotoxy(50,10);cprintf("»");
  501. gotoxy(25,11);cprintf("º NO RECORDS FOUND º");
  502. gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");
  503. k=26;
  504. for(i=1;i<=24;i++)
  505. { gotoxy(k,12);cprintf("ÿ");
  506. k++;
  507. }
  508. music(1);music(1);
  509. getch();
  510. }
  511. if(flag==1)
  512. { clrscr();
  513. border_margin();
  514. gotoxy(25,10);cprintf("É");
  515. k=26;
  516. for(i=1;i<=24;i++)
  517. { gotoxy(k,10);cprintf("ÿ");
  518. k++;
  519. }
  520. gotoxy(50,10);cprintf("»");
  521. gotoxy(25,11);cprintf("º RECORD DELETED º");
  522. gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");
  523. k=26;
  524. for(i=1;i<=24;i++)
  525. { gotoxy(k,12);cprintf("ÿ");
  526. k++;
  527. }
  528. music(1);music(1);
  529. getch();
  530. }
  531. last:
  532. getch();
  533. }
  534.  
  535. void update()
  536. { int choice;
  537. char str[30];
  538. char f;
  539. employee *temp;
  540. temp=head;
  541. if(head==NULL) /* EMPTY LINKED LIST */
  542. { clrscr();
  543. border_margin();
  544. gotoxy(25,10);cprintf("É");
  545. k=26;
  546. for(i=1;i<=24;i++)
  547. { gotoxy(k,10);cprintf("ÿ");
  548. k++;
  549. }
  550. gotoxy(50,10);cprintf("»");
  551. gotoxy(25,11);cprintf("º NO RECORDS AVAILABLE º");
  552. gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");
  553. k=26;
  554. for(i=1;i<=24;i++)
  555. { gotoxy(k,12);cprintf("ÿ");
  556. k++;
  557. }
  558. music(1);music(1);
  559.  
  560. }
  561. else
  562. { clrscr();
  563. border_margin();
  564. gotoxy(25,3);cprintf("R E C O R D U P D A T E");
  565. gotoxy(5,5);cprintf("ENTER THE EMPLOYEE NUMBER WHICH IS TO BE UPDATED : ");
  566. gotoxy(57,5);scanf("%d",&choice);
  567. if(choice > count)
  568. { clrscr();
  569. border_margin();
  570. gotoxy(10,10);cprintf("EMPLOYEE NO NOT FOUND");
  571. getch();
  572. goto last;
  573. }
  574. again:
  575. gotoxy(5,10);cprintf("1. NAME ");gotoxy(5,11);cprintf("2. GROSS PAY");
  576. gotoxy(5,12);cprintf("3. DESIGNATION");gotoxy(5,13);cprintf("4. AGE");
  577. gotoxy(5,14);cprintf("5. SEX");
  578. gotoxy(5,16);cprintf("ENTER THE FIELD YOU WANT TO EDIT : ");
  579. gotoxy(41,16);fflush(stdin);f=getch();
  580. switch(f)
  581. { case '1':
  582. fflush(stdin);
  583. gotoxy(5,18);cprintf("ENTER NEW NAME : ");gets(str);
  584. while(choice!=temp->employee_no)
  585. temp=temp->nextptr;
  586. clrscr();
  587. printdetail();
  588. gotoxy(20,7);printf("%d",temp->employee_no);
  589. strcpy(temp->employee_name,str);
  590. gotoxy(20,9);printf("%s",temp->employee_name);
  591. gotoxy(20,11);printf("%f",temp->grosspay);
  592. gotoxy(20,13);puts(temp->designation);
  593. gotoxy(20,15);printf("%d",temp->age);
  594. gotoxy(20,17);puts(temp->sex);
  595. break;
  596. case '2':
  597. float gp;
  598. fflush(stdin);
  599. gotoxy(20,18);cprintf("ENTER NEW GROSS : ");scanf("%f",&gp);
  600. while(choice!=temp->employee_no)
  601. temp=temp->nextptr;
  602. clrscr();
  603. printdetail();
  604. gotoxy(20,7);printf("%d",temp->employee_no);
  605. temp->grosspay = gp;
  606. gotoxy(20,9);printf("%s",temp->employee_name);
  607. gotoxy(20,11);printf("%f",temp->grosspay);
  608. gotoxy(20,13);puts(temp->designation);
  609. gotoxy(20,15);printf("%d",temp->age);
  610. gotoxy(20,17);puts(temp->sex);
  611. break;
  612. case '3':
  613. fflush(stdin);
  614. gotoxy(20,18);cprintf("ENTER NEW DESIGNATION : ");gets(str);
  615. while(choice!=temp->employee_no)
  616. temp=temp->nextptr;
  617. clrscr();
  618. printdetail();
  619. gotoxy(20,7);printf("%d",temp->employee_no);
  620. strcpy(temp->designation,str);
  621. gotoxy(20,9);printf("%s",temp->employee_name);
  622. gotoxy(20,11);printf("%f",temp->grosspay);
  623. gotoxy(20,13);puts(temp->designation);
  624. gotoxy(20,15);printf("%d",temp->age);
  625. gotoxy(20,17);puts(temp->sex);
  626. break;
  627. case '4':
  628. int gp1;
  629. fflush(stdin);
  630. gotoxy(20,18);cprintf("ENTER NEW AGE : ");scanf("%d",&gp1);
  631. while(choice!=temp->employee_no)
  632. temp=temp->nextptr;
  633. clrscr();
  634. printdetail();
  635. gotoxy(20,7);printf("%d",temp->employee_no);
  636. temp->age = gp1;
  637. gotoxy(20,9);printf("%s",temp->employee_name);
  638. gotoxy(20,11);printf("%f",temp->grosspay);
  639. gotoxy(20,13);puts(temp->designation);
  640. gotoxy(20,15);printf("%d",temp->age);
  641. gotoxy(20,17);puts(temp->sex);
  642. break;
  643. case '5':
  644. fflush(stdin);
  645. gotoxy(20,18);cprintf("ENTER NEW SEX : ");gets(str);
  646. while(choice!=temp->employee_no)
  647. temp=temp->nextptr;
  648. clrscr();
  649. printdetail();
  650. gotoxy(20,7);printf("%d",temp->employee_no);
  651. strcpy(temp->sex,str);
  652. gotoxy(20,9);printf("%s",temp->employee_name);
  653. gotoxy(20,11);printf("%f",temp->grosspay);
  654. gotoxy(20,13);puts(temp->designation);
  655. gotoxy(20,15);printf("%d",temp->age);
  656. gotoxy(20,17);puts(temp->sex);
  657. break;
  658. default:
  659. goto again;
  660. }
  661. gotoxy(25,20);cprintf("É");
  662. k=26;
  663. for(i=1;i<=24;i++)
  664. { gotoxy(k,20);cprintf("ÿ");
  665. k++;
  666. }
  667. gotoxy(50,20);cprintf("»");
  668. gotoxy(25,21);cprintf("º RECORD UPDATED º");
  669. gotoxy(25,22);cprintf("È");gotoxy(50,22);cprintf("¼");
  670. k=26;
  671. for(i=1;i<=24;i++)
  672. { gotoxy(k,22);cprintf("ÿ");
  673. k++;
  674. }
  675. music(1);music(1);
  676. }
  677. last:
  678. getch();
  679. }
  680.  
  681. employee *getnode(int count)
  682. { employee *nodeptr;
  683. nodeptr=(employee *)malloc(sizeof(employee));
  684. nodeptr->employee_no=count;
  685. gotoxy(20,7);printf("%d",nodeptr->employee_no);fflush(stdin);
  686. gotoxy(20,9);gets(nodeptr->employee_name);
  687. gotoxy(20,11);scanf("%f",&nodeptr->grosspay);fflush(stdin);
  688. gotoxy(20,13);gets(nodeptr->designation);
  689. gotoxy(20,15);scanf("%d",&nodeptr->age);fflush(stdin);
  690. gotoxy(20,17);gets(nodeptr->sex);
  691. gotoxy(25,20);cprintf("É");
  692. k=26;
  693. for(i=1;i<=24;i++)
  694. { gotoxy(k,20);cprintf("ÿ");
  695. k++;
  696. }
  697. gotoxy(50,20);cprintf("»");
  698. gotoxy(25,21);cprintf("º RECORD ENTRY SUCESSFUL º");
  699. gotoxy(25,22);cprintf("È");gotoxy(50,22);cprintf("¼");
  700. k=26;
  701. for(i=1;i<=24;i++)
  702. { gotoxy(k,22);cprintf("ÿ");
  703. k++;
  704. }
  705. music(1);music(1);
  706. nodeptr->previousptr=NULL;
  707. nodeptr->nextptr=NULL;
  708. return nodeptr;
  709. }
  710.  
  711. void search_employee(int key)
  712. { employee *temp;
  713. clrscr();
  714. border_margin();
  715. gotoxy(25,11);cprintf("É");
  716. k=26;
  717. for(i=1;i<=24;i++)
  718. { gotoxy(k,11);cprintf("ÿ");
  719. k++;
  720. }
  721. gotoxy(50,11);cprintf("»");
  722. gotoxy(25,12);cprintf("º º");
  723. gotoxy(25,13);cprintf("È");gotoxy(50,13);cprintf("¼");
  724. k=26;
  725. for(i=1;i<=24;i++)
  726. { gotoxy(k,13);cprintf("ÿ");
  727. k++;
  728. }
  729. gotoxy(32,9);cprintf("SEARCHING...");
  730. k=26;
  731. for(i=1;i<=24;i++)
  732. { gotoxy(k,12);cprintf("ÿ");delay(50);
  733. k++;
  734. }
  735. gotoxy(22,19);textcolor(YELLOW);
  736. cprintf("PRESS A KEY TO RETURN TO CONTINUE >>");
  737. gotoxy(28,17);cprintf("SEARCHING COMPLETE");
  738. getch();
  739. temp=head;
  740. int flag=0;
  741. if(temp==NULL) /* LINKED LIST IS EMPTY */
  742. { clrscr();
  743. border_margin();
  744. gotoxy(25,10);cprintf("É");
  745. k=26;
  746. for(i=1;i<=24;i++)
  747. { gotoxy(k,10);cprintf("ÿ");
  748. k++;
  749. }
  750. gotoxy(50,10);cprintf("»");
  751. gotoxy(25,11);cprintf("º NO RECORDS AVAILABLE º");
  752. gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");
  753. k=26;
  754. for(i=1;i<=24;i++)
  755. { gotoxy(k,12);cprintf("ÿ");
  756. k++;
  757. }
  758. music(1);music(1);
  759. goto last;
  760. }
  761. while(temp!=NULL)
  762. { if(temp->employee_no==key)
  763. { flag++;
  764. printdetail();
  765. gotoxy(20,7);printf("%d",temp->employee_no);
  766. gotoxy(20,9);puts(temp->employee_name);
  767. gotoxy(20,11);printf("%f",temp->grosspay);
  768. gotoxy(20,13);gets(temp->designation);
  769. gotoxy(20,15);printf("%d",temp->age);
  770. gotoxy(20,17);puts(temp->sex);
  771. gotoxy(25,20);cprintf("É");
  772. k=26;
  773. for(i=1;i<=24;i++)
  774. { gotoxy(k,20);cprintf("ÿ");
  775. k++;
  776. }
  777. gotoxy(50,20);cprintf("»");
  778. gotoxy(25,21);cprintf("º RECORD FOUND º");
  779. gotoxy(25,22);cprintf("È");gotoxy(50,22);cprintf("¼");
  780. k=26;
  781. for(i=1;i<=24;i++)
  782. { gotoxy(k,22);cprintf("ÿ");
  783. k++;
  784. }
  785. music(1);music(1);
  786. }
  787. temp=temp->nextptr;
  788. }
  789. if(flag==0)
  790. { clrscr();
  791. border_margin();
  792. clrscr();
  793. border_margin();
  794. gotoxy(25,10);cprintf("É");
  795. k=26;
  796. for(i=1;i<=24;i++)
  797. { gotoxy(k,10);cprintf("ÿ");
  798. k++;
  799. }
  800. gotoxy(50,10);cprintf("»");
  801. gotoxy(25,11);cprintf("º RECORDS NOT FOUND º");
  802. gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");
  803. k=26;
  804. for(i=1;i<=24;i++)
  805. { gotoxy(k,12);cprintf("ÿ");
  806. k++;
  807. }
  808. music(1);music(1);
  809. }
  810. last:
  811. }
  812.  
  813. void music(int no)
  814. { /* Natural frequncies of 7 notes */
  815. float octave[7]={130.81,146.83,164.81,174.61,196,220,246.94};
  816. int n,i;
  817. switch(no)
  818. { case 1:
  819. for(i=0;i<7;i++)
  820. { sound(octave[i] * 8);
  821. delay(30);
  822. }
  823. nosound();
  824. break;
  825. case 2:
  826. for(i=0;i<15;i++)
  827. { n=random(7);
  828. sound(octave[n] * 4);
  829. delay(100);
  830. }
  831. nosound();
  832. break;
  833. case 3:
  834. while(!kbhit())
  835. { n=random(7);
  836. sound(octave[n] * 4);
  837. delay(100);
  838. }
  839. nosound();
  840. if(getch()==0)
  841. getch();
  842. break;
  843. case 4:
  844. for(i=4;i>=0;i--)
  845. { sound(octave[i] * 4);
  846. delay(15);
  847. }
  848. nosound();
  849. break;
  850. case 5:
  851. sound(octave[6] * 2);
  852. delay(50);
  853.  
  854. nosound();
  855. }
  856. }
  857.  
  858. void border_margin()
  859. { clrscr();
  860. textcolor(YELLOW);
  861. int i,j=3;
  862. gotoxy(2,2);cprintf("É");
  863. for(i=0;i<74;i++)
  864. { gotoxy(j,2);cprintf("ÿ");
  865. j++;
  866. }
  867. gotoxy(77,2);cprintf("»");
  868. j=3;
  869. for(i=0;i<20;i++)
  870. { gotoxy(2,j) ;cprintf("º");
  871. gotoxy(77,j);cprintf("º");
  872. j++;
  873. }
  874. gotoxy(2,23);cprintf("È");
  875. j=3;
  876. for(i=0;i<74;i++)
  877. { gotoxy(j,23);cprintf("ÿ");
  878. j++;
  879. }
  880. gotoxy(77,23);cprintf("¼");
  881. }
  882. void printmain()
  883. { int k,i;
  884. border_margin(); /* user defined function to draw margin */
  885. textbackground(0); /* sets background none */
  886. textcolor(YELLOW);/* set text color */
  887. textbackground(RED);
  888. gotoxy(6,4);cprintf("É");
  889. k=7;
  890. for(i=1;i<=24;i++)
  891. { gotoxy(k,4);cprintf("ÿ");
  892. k++;
  893. }
  894. gotoxy(31,4);cprintf("»");
  895. gotoxy(6,5);cprintf("º 1. ADD RECORDS º");
  896. gotoxy(6,6);cprintf("È");gotoxy(31,6);cprintf("¼");
  897. k=7;
  898. for(i=1;i<=24;i++)
  899. { gotoxy(k,6);cprintf("ÿ");
  900. k++;
  901. }
  902.  
  903. gotoxy(43,4);cprintf("É");
  904. k=44;
  905. for(i=1;i<=24;i++)
  906. { gotoxy(k,4);cprintf("ÿ");
  907. k++;
  908. }
  909. gotoxy(68,4);cprintf("»");
  910. gotoxy(43,5);cprintf("º 2. DISPLAY RECORDS º");
  911. gotoxy(43,6);cprintf("È");gotoxy(68,6);cprintf("¼");
  912. k=44;
  913. for(i=1;i<=24;i++)
  914. { gotoxy(k,6);cprintf("ÿ");
  915. k++;
  916. }
  917.  
  918. gotoxy(6,9);cprintf("É");
  919. k=7;
  920. for(i=1;i<=24;i++)
  921. { gotoxy(k,9);cprintf("ÿ");
  922. k++;
  923. }
  924. gotoxy(31,9);cprintf("»");
  925. gotoxy(6,10);cprintf("º 3. DELETE RECORDS º");
  926. gotoxy(6,11);cprintf("È");gotoxy(31,11);cprintf("¼");
  927. k=7;
  928. for(i=1;i<=24;i++)
  929. { gotoxy(k,11);cprintf("ÿ");
  930. k++;
  931. }
  932.  
  933. gotoxy(43,9);cprintf("É");
  934. k=44;
  935. for(i=1;i<=24;i++)
  936. { gotoxy(k,9);cprintf("ÿ");
  937. k++;
  938. }
  939. gotoxy(68,9);cprintf("»");
  940. gotoxy(43,10);cprintf("º 4. UPDATE RECORDS º");
  941. gotoxy(43,11);cprintf("È");gotoxy(68,11);cprintf("¼");
  942. k=44;
  943. for(i=1;i<=24;i++)
  944. { gotoxy(k,11);cprintf("ÿ");
  945. k++;
  946. }
  947.  
  948. gotoxy(6,14);cprintf("É");
  949. k=7;
  950. for(i=1;i<=24;i++)
  951. { gotoxy(k,14);cprintf("ÿ");
  952. k++;
  953. }
  954. gotoxy(31,14);cprintf("»");
  955. gotoxy(6,15);cprintf("º 5. SEARCH FOR RECORDS º");
  956. gotoxy(6,16);cprintf("È");gotoxy(31,16);cprintf("¼");
  957. k=7;
  958. for(i=1;i<=24;i++)
  959. { gotoxy(k,16);cprintf("ÿ");
  960. k++;
  961. }
  962.  
  963. gotoxy(43,14);cprintf("É");
  964. k=44;
  965. for(i=1;i<=24;i++)
  966. { gotoxy(k,14);cprintf("ÿ");
  967. k++;
  968. }
  969. gotoxy(68,14);cprintf("»");
  970. gotoxy(43,15);cprintf("º 6. QUIT º");
  971. gotoxy(43,16);cprintf("È");gotoxy(68,16);cprintf("¼");
  972. k=44;
  973. for(i=1;i<=24;i++)
  974. { gotoxy(k,16);cprintf("ÿ");
  975. k++;
  976. }
  977. gotoxy(25,21);cprintf("ENTER YOUR CHOICE : ");
  978.  
  979. }
  980. void printdetail()
  981. { border_margin();
  982. gotoxy(5,7);cprintf("EMPLOYEE NO : ");
  983. gotoxy(20,8);cprintf("____________________________________________");
  984. gotoxy(5,9);cprintf("NAME : ");
  985. gotoxy(20,10);cprintf("____________________________________________");
  986. gotoxy(5,11);cprintf("GROSS PAY : ");
  987. gotoxy(20,12);cprintf("____________________________________________");
  988. gotoxy(5,13);cprintf("DESIGNATION : ");
  989. gotoxy(20,14);cprintf("____________________________________________");
  990. gotoxy(5,15);cprintf("AGE : ");
  991. gotoxy(20,16);cprintf("____________________________________________");
  992. gotoxy(5,17);cprintf("SEX : ");
  993. gotoxy(20,18);cprintf("____________________________________________");
  994. }
Comments on this Code Snippet
Feb 12th, 2005
0

Re: Doubly Linked List Implementation

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.
Light Poster
free_eagle is offline Offline
41 posts
since Jan 2005
Jun 20th, 2010
-1

thanks man

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
Newbie Poster
ylnsagar is offline Offline
1 posts
since Jun 2010
Message:
Previous Thread in C Forum Timeline: sending 4 values to client
Next Thread in C Forum Timeline: A Deck of Cards





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC