Advertisement
Guest User

ailo

a guest
Dec 13th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.75 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. typedef struct node
  5. {
  6. char bookid[50];
  7. char bookname[100];
  8. char author[50];
  9. char category[50];
  10. char name[50];
  11. int quantity;
  12. struct node *next;
  13. } node;
  14.  
  15. node *head_book=NULL,*ihead=NULL;
  16.  
  17.  
  18. node *search_id(node *list , char s[])
  19. {
  20.  
  21. while(list!=NULL)
  22. {
  23. if(strcmp(list->bookid,s)==0)
  24. {
  25. return list;
  26. break;
  27. }
  28. list=list->next;
  29. }
  30. if(list==NULL)
  31. {
  32. return NULL;
  33. }
  34. }
  35.  
  36.  
  37. node *search_nm(char s[])
  38. {
  39. node *list=head_book;
  40. while(list!=NULL)
  41. {
  42. if(strcmp(list->bookname,s)==0)
  43. {
  44. return list;
  45. break;
  46. }
  47. list=list->next;
  48. }
  49. if(list==NULL)
  50. {
  51. return NULL;
  52. }
  53. }
  54.  
  55. void search()
  56. {
  57. printf("1.Search by Id\n");
  58. printf("2.Search By Name\n");
  59. int x;
  60. printf("Select one:");
  61. scanf("%d",&x);
  62. if(x==1)
  63. {
  64. char temp[50];
  65. printf("Enter Book ID:");
  66. scanf(" %[^\n]",temp);
  67. node *n=search_id(head_book,temp);
  68. if(n==NULL)
  69. {
  70. printf("No Book Available\n");
  71.  
  72. }
  73. else
  74. {
  75. printf("\nBook Is Available!!!!\n\n");
  76. printf("Book ID: %s\n",n->bookid);
  77. printf("Book Name: %s\n",n->bookname);
  78.  
  79. printf("Author: %s\n",n->author);
  80. printf("Quantity: %d\n",n->quantity);
  81.  
  82. }
  83. printf("\n1.back\n");
  84. printf("2.menu\n");
  85. printf("Choose One:");
  86. int y;
  87. scanf("%d",&y);
  88. if(y==1)
  89. {
  90. search();
  91. }
  92. else
  93. {
  94. menu();
  95. }
  96.  
  97.  
  98. }
  99. else if(x==2)
  100. { char temp[50];
  101. printf("Enter Book Name:");
  102. scanf(" %[^\n]",temp);
  103. node *n=search_nm(temp);
  104. if(n==NULL)
  105. {
  106. printf("\nNo Book Available!!\n\n");
  107.  
  108. }
  109. else
  110. {
  111. printf("\nBook Is Available\n\n");
  112. printf("Book ID: %s\n",n->bookid);
  113. printf("Book Name: %s\n",n->bookname);
  114.  
  115. printf("Author: %s\n",n->author);
  116. printf("Quantity: %d\n\n",n->quantity);
  117.  
  118. }
  119. printf("\n1.back\n");
  120. printf("2.menu\n");
  121. printf("Choose One:");
  122. int y;
  123. scanf("%d",&y);
  124. if(y==1)
  125. {
  126. search();
  127. }
  128. else
  129. {
  130. menu();
  131. }
  132.  
  133. }
  134. }
  135.  
  136.  
  137. void view()
  138. {
  139. node *list = head_book;
  140. int cm=0,e=0,c=0,m=0,a=0,tbook=0;
  141. while(list!=NULL)
  142. {
  143. if(strcmp(list->category,"Computer")==0)
  144. {
  145. printf("\nBook Id: %s\n",list->bookid);
  146. printf("book Name: %s\n",list->bookname);
  147. printf("Author: %s\n",list->author);
  148. printf("Category: %s\n",list->category);
  149. printf("Quantity: %d\n",list->quantity);
  150. cm++;
  151. }
  152. printf("\nTotal Computer Book:%d\n",cm);
  153.  
  154. list=list->next;
  155. }
  156.  
  157. list = head_book;
  158. while(list!=NULL)
  159. {
  160. if(strcmp(list->category,"Electronics")==0)
  161. {
  162. printf("\nBook Id: %s\n",list->bookid);
  163. printf("book Name: %s\n",list->bookname);
  164. printf("Author: %s\n",list->author);
  165. printf("Category: %s\n",list->category);
  166. printf("Quantity: %d\n",list->quantity);
  167. e++;
  168. }
  169. printf("\nTotal Electronics Book:%d\n",e);
  170.  
  171. list=list->next;
  172. }
  173.  
  174.  
  175. list = head_book;
  176. while(list!=NULL)
  177. {
  178. if(strcmp(list->category,"Civil")==0)
  179. {
  180. printf("\nBook Id: %s\n",list->bookid);
  181. printf("book Name: %s\n",list->bookname);
  182. printf("Author: %s\n",list->author);
  183. printf("Category: %s\n",list->category);
  184. printf("Quantity: %d\n",list->quantity);
  185. c++;
  186. }
  187.  
  188. list=list->next;
  189. }
  190.  
  191. printf("\nTotal Civil Book:%d\n",c);
  192.  
  193. list = head_book;
  194. while(list!=NULL)
  195. {
  196. if(strcmp(list->category,"Mechanical")==0)
  197. {
  198. printf("\nBook Id: %s\n",list->bookid);
  199. printf("book Name: %s\n",list->bookname);
  200. printf("Author: %s\n",list->author);
  201. printf("Category: %s\n",list->category);
  202. printf("Quantity: %d\n",list->quantity);
  203. m++;
  204. }
  205.  
  206. list=list->next;
  207. }
  208.  
  209. printf("\nTotal Mechanical Book:%d\n",m);
  210. list = head_book;
  211. while(list!=NULL)
  212. {
  213. if(strcmp(list->category,"Architecture")==0)
  214. {
  215. printf("\nBook Id: %s\n",list->bookid);
  216. printf("book Name: %s\n",list->bookname);
  217. printf("Author: %s\n",list->author);
  218. printf("Category: %s\n",list->category);
  219. printf("Quantity: %d\n",list->quantity);
  220. a++;
  221. }
  222.  
  223. list=list->next;
  224. }
  225. printf("\nTotal Architecture Book:%d\n\n",a);
  226.  
  227. printf("Total Book's = %d\n\n",a+cm+c+m+e);
  228. printf("\n1.menu\n");
  229. int x;
  230. printf("press 1\n");
  231. scanf("%d",&x);
  232. if(x==1)
  233. {
  234. menu();
  235. }
  236. else
  237. {
  238. menu();
  239. }
  240.  
  241.  
  242. }
  243.  
  244. void addbook()
  245. {
  246.  
  247. char temp[50];
  248. printf("\n1.Computer\n");
  249. printf("2.Electronics\n");
  250. printf("3.Civil\n");
  251. printf("4.Mechanical\n");
  252. printf("5.Architecture\n");
  253. printf("Select category:");
  254. int x;
  255. scanf("%d",&x);
  256. switch(x)
  257. {
  258. case 1:
  259. {
  260. strcpy(temp,"Computer");
  261. break;
  262. }
  263. case 2:
  264. {
  265. strcpy(temp,"Electronics");
  266. break;
  267. }
  268. case 3:
  269. {
  270. strcpy(temp,"Civil");
  271. break;
  272. }
  273. case 4:
  274. {
  275. strcpy(temp,"Mechanical");
  276. break;
  277. }
  278. case 5:
  279. {
  280. strcpy( temp,"Architecture");
  281. break;
  282. }
  283. default:
  284. {
  285. printf("Choose Correct option!!\n");
  286. addbook();
  287. break;
  288. }
  289. }
  290. char id[50];
  291. printf("\nEnter Book Id:");
  292. scanf(" %s",id);
  293.  
  294. node *list=head_book;
  295. while(list!=NULL)
  296. {
  297. if(strcmp(list->bookid,id)==0)
  298. {
  299. printf("\nThis Book Id Already Exist!!\n\n");
  300. break;
  301. }
  302. list=list->next;
  303.  
  304. }
  305. if(list==NULL)
  306. {
  307. node *n=(node*)malloc(sizeof(node));
  308. n->next=NULL;
  309. printf("Book Name:");
  310. scanf(" %[^\n]",n->bookname);
  311.  
  312. printf("Author:");
  313. scanf(" %[^\n]",n->author);
  314. printf("Quantity:");
  315. scanf("%d",&n->quantity);
  316. strcpy(n->bookid,id);
  317. strcpy(n->category,temp);
  318. if(head_book==NULL)
  319. {
  320. head_book=n;
  321. }
  322. else
  323. {
  324. node *list=head_book;
  325. while(list->next!=NULL)
  326. {
  327. list=list->next;
  328. }
  329. list->next=n;
  330. }
  331.  
  332. }
  333.  
  334.  
  335.  
  336.  
  337.  
  338. printf("\n1.Add More information\n");
  339. printf("2.Menu\n");
  340. printf("Choose one:");
  341. int y;
  342. scanf("%d",&y);
  343. if(y==1)
  344. {
  345.  
  346. addbook();
  347.  
  348.  
  349.  
  350. }
  351. else
  352. {
  353. menu();
  354. }
  355. }
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362. void Delete()
  363. { char ch[50];
  364. node *temp=NULL;
  365. printf("\nEnter Book Id:");
  366. scanf("%s",ch);
  367. node *list=head_book;
  368. if(head_book==NULL)
  369. {
  370. printf("\nThis Book Does not Exist!!\n\n");
  371. }
  372. else if(strcmp(head_book->bookid,ch)==0)
  373. {
  374. temp=head_book;
  375. head_book=head_book->next;
  376. free(temp);
  377. }
  378. else
  379. {
  380. while(strcmp(list->next->bookid,ch)!=0&&list->next!=NULL)
  381. {
  382. list=list->next;
  383. }
  384. if(list->next==NULL)
  385. {
  386. printf("\nThis Book Does not Exist!!\n\n");
  387. }
  388. else
  389. {
  390. temp=list->next;
  391. list->next=temp->next;
  392. free(temp);
  393. }
  394. }
  395.  
  396. printf("1.delete Another\n");
  397. printf("2.Menu\n");
  398. int x;
  399. if(x==1)
  400. {
  401. Delete();
  402. }
  403. else
  404. {
  405. menu();
  406. }
  407.  
  408. }
  409. ibook()
  410. { char ch[50];
  411. printf("Enter Book id:");
  412. scanf("%s",ch);
  413. node *n=search_id(head_book,ch);
  414. if(n==NULL)
  415. {
  416. printf("\nNo Record Found!!\n\n");
  417. }
  418. else
  419. {
  420. node *m=(node*)malloc(sizeof(node));
  421. m->next=NULL;
  422. printf("This Book Is available!");
  423. printf("There are %d unissued book in the library\n",n->quantity);
  424. printf("The book name is: %s\n",n->bookname);
  425. printf("Enter Student Name:");
  426. scanf(" %[^\n]",m->name);
  427. strcpy(m->bookid,n->bookid);
  428. strcpy(m->bookname,n->bookname);
  429. strcpy(m->category,n->category);
  430. printf("The Book of Id %s is Issued for 7 days\n",n->bookid);
  431. if(ihead==NULL)
  432. {
  433. ihead=m;
  434. }
  435. else
  436. {
  437. node *list=ihead;
  438. while(list->next!=NULL)
  439. {
  440. list=list->next;
  441. }
  442. list->next=m;
  443. }
  444.  
  445. }
  446.  
  447. printf("\n1.issue another book\n");
  448. printf("2.menu\n");
  449. int y;
  450. printf("choose one:");
  451. scanf("%d",&y);
  452. if(y==1)
  453. {
  454. ibook();
  455. }
  456. else
  457. {
  458. menu();
  459. }
  460. }
  461.  
  462. void vbook()
  463. {
  464. node *list=ihead;
  465. if(ihead==NULL)
  466. {
  467. printf("\nNo record found\n\n");
  468. }
  469. else
  470. {
  471. while(list!=NULL)
  472. {
  473. printf("Student Name: %s\n",list->name);
  474. printf("Book Name: %s\n",list->bookname);
  475. printf("Book Id: %s\n",list->bookid);
  476. printf("Category: %s\n\n",list->category);
  477. list=list->next;
  478. }
  479. }
  480. printf("\n1.back\n");
  481. printf("2.menu\n");
  482. int y;
  483. printf("Choose One:");
  484. scanf("%d",&y);
  485. if(y==1)
  486. {
  487. issu();
  488. }
  489. else
  490. {
  491. menu();
  492. }
  493. }
  494.  
  495.  
  496. void sissu()
  497. {
  498. printf("Enter Book id:");
  499. char ch[50];
  500. scanf("%s",ch);
  501. node *list=ihead;
  502. int count=0;
  503. if(ihead==NULL)
  504. {
  505. printf("\nNo record found!!\n");
  506. }
  507. else
  508. {
  509. while(list!=NULL)
  510. {
  511. if(strcmp(list->bookid,ch)==0)
  512. {
  513. printf("This book has taken by %s\n",list->name);
  514. count=1;
  515. }
  516. }
  517. printf("\n");
  518. if(count==0)
  519. {
  520. printf("\nNo record found!\n\n");
  521. }
  522. }
  523. printf("\n1.Another search\n");
  524. printf("2.Menu\n");
  525. int y;
  526. printf("choose one:");
  527. scanf("%d",&y);
  528. if(y==1)
  529. {
  530. sissu();
  531. }
  532. else
  533. {
  534. menu();
  535. }
  536.  
  537. }
  538. void rissu()
  539. {
  540. printf("Enter book Id:");
  541. char ch[50];
  542. scanf("%s",ch);
  543. node *temp=NULL;
  544. if(ihead==NULL)
  545. {
  546. printf("no record found\n");
  547. }
  548. else if(strcmp(ihead->bookid,ch)==0)
  549. {
  550. temp=ihead;
  551. ihead=ihead->next;
  552. free(temp);
  553. }
  554. else
  555. {
  556. node *list=ihead;
  557. while(strcmp(list->next->bookid,ch)!=0&&list->next!=NULL)
  558. {
  559. list=list->next;
  560. }
  561. if(list->next==NULL)
  562. {
  563. printf("No record Found!!\n");
  564. }
  565. else
  566. {
  567. temp=list->next;
  568. list->next=temp->next;
  569. free(temp);
  570. }
  571. }
  572. printf("\n1.Remove another Issue\n");
  573. printf("2.Menu\n");
  574. int y;
  575. printf("Choose One:");
  576. scanf("%d",&y);
  577. if(y==1)
  578. {
  579. rissu();
  580. }
  581. else
  582. {
  583. menu();
  584. }
  585. }
  586.  
  587. void issu()
  588. { printf("\n1.issue a book\n");
  589. printf("2.View Issue Book\n");
  590. printf("3.search Issue Book\n");
  591. printf("4.remove Issue Book\n ");
  592. printf("Choose one:");
  593. int x;
  594. scanf("%d",&x);
  595. switch(x)
  596. {
  597. case 1:
  598. {
  599. ibook();
  600. break;
  601.  
  602. }
  603. case 2:
  604. {
  605. vbook();
  606. break;
  607. }
  608. case 3:
  609. {
  610. sissu();
  611. break;
  612. }
  613. case 4:
  614. {
  615. rissu();
  616. }
  617. default:
  618. {
  619. printf("\nYou Choose Wrong otion!!!\n");
  620. menu();
  621. break;
  622. }
  623. }
  624. }
  625. void edit()
  626. {
  627. char temp[50];
  628. printf("Enter Book id:");
  629. scanf("%s",temp);
  630. node *n=search_id(head_book,temp);
  631. if(n==NULL)
  632. {
  633. printf("\nNo record Found!!\n");
  634. }
  635. else
  636. {
  637. printf("\nNew book Name:");
  638. scanf(" %[^\n]",n->bookname);
  639. printf("Author Name:");
  640. scanf(" %[^\n]",n->author);
  641. printf("Quantity:");
  642. scanf("%d",&n->quantity);
  643. }
  644.  
  645. printf("\n1.Edit Another Book\n");
  646. printf("2.menu\n");
  647. printf("Choose One:");
  648. int x;
  649. scanf("%d",&x);
  650. if(x==1)
  651. {
  652. edit();
  653. }
  654. else
  655. {
  656. menu();
  657. }
  658. }
  659.  
  660. void menu()
  661. {
  662. printf("\n1.Add Book's\n");
  663. printf("2.Search Book's\n");
  664. printf("3.Delete Book's\n");
  665. printf("4.Issue Book's\n");
  666. printf("5.view book list\n");
  667. printf("6.Edit Book's\n");
  668. printf("7.Exit\n");
  669. int x;
  670. printf("Choose any One:");
  671. scanf("%d",&x);
  672. switch(x)
  673. {
  674. case 1:
  675. {
  676.  
  677. addbook();
  678.  
  679.  
  680.  
  681. break;
  682. }
  683. case 2:
  684. {
  685. search();
  686. break;
  687. }
  688. case 3:
  689. {
  690. Delete();
  691. break;
  692. }
  693. case 4:
  694. {
  695. issu();
  696. break;
  697. }
  698. case 5:
  699. {
  700. view();
  701. break;
  702. }
  703. case 6:
  704. {
  705. edit();
  706. break;
  707. }
  708. case 7:
  709. {
  710. exit(0);
  711. break;
  712. }
  713.  
  714. default :
  715. {
  716. printf("Choose Correct Option!!\n");
  717. menu();
  718. break;
  719. }
  720. }
  721.  
  722. }
  723.  
  724. int main()
  725. {
  726. printf(" LIBRARY MANAGEMENT\n");
  727. printf(" ____________________\n");
  728. menu();
  729. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement