Tuesday, September 9, 2014

Library management using structure


Problem

Write a menu driven program that depicts the working of a library. The menu options should be:
  1. Add book information
  2. Display book information
  3. List all books of given author
  4. List the title of specified book
  5. List the count of books in the library
  6. List the books in the order of accession number
  7. Exit
Create a structure called library to hold accession number, title of the book, author name, price of the book, and flag indicating whether book is issued or not.

Solution - Code

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct library
{
 char bk_name[30];
 char arthur[30];
 int pages;
 float price;
};

int main()
{
 struct library l[3];
 char ar_nm,bk_nm;
 int i,j;

 printf ("1. Add book information\n2. Display book information\n3. List all books of given author\n4. List the title of specified book\n5. List the count of books in the library\n6. Exit");

 printf ("\n\nEnter one of the above : ");
 scanf("%d",&j);

 switch (j)
 {
  case 1:
   for (i=0;i<3;i++)
   {

    printf ("Enter book name = ");
    scanf ("%s",&l[i].bk_name);

    printf ("Enter arthur name = ");
    scanf ("%s",&l[i].arthur);

    printf ("Enter pages = ");
    scanf ("%d",&l[i].pages);

    printf ("Enter price = ");
    scanf ("%f",&l[i].price);
   }
   break;
  case 2:
   printf("you have entered the following information\n");
   for(i=0;i<3;i++)
   {
    printf ("book name = %s",l[i].bk_name);

    printf ("arthur name = %s",l[i].arthur);

    printf ("pages = %d",l[i].pages);

    printf ("price = %f",l[i].price);
   }
   break;

  case 3:
   printf ("Enter arthur name : ");
   scanf ("%s",&ar_nm);
   for (i=0;i<3;i++)
   {
    if (ar_nm == l[i].arthur)
     printf ("%s %s %d %f",l[i].bk_name,l[i].arthur,l[i].pages,l[i].price);
   }
   break;

  case 4:
   printf ("Enter book name : ");
   scanf ("%s",&bk_nm);
   for (i=0;i<3;i++)
   {
    if (bk_nm == l[i].bk_name)
     printf ("%s %s %d %f",l[i].bk_name,l[i].arthur,l[i].pages,l[i].price);
   }
   break;

  case 5:
   for (i=0;i<3;i++)
   {

   }
   break;
  case 6:
   exit (0);


 }
 return 0;
}

Sample Output

library working using struct

8 comments :

  1. Not working.. Please do something.. output isn't coming..

    ReplyDelete
    Replies
    1. which compiler/editor you are using?

      Delete
    2. Turbo C.. The output isn't even coming.. I need it very urgent.. Help me out !

      Delete
    3. try using bloodshed dev c++ compiler/editor. Hopefully it will work fine on it. to donwload the compiler follow the below link:
      http://www.bloodshed.net/

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. In this code cases of 2,3,4,5 are not working

      Delete

Note: Only a member of this blog may post a comment.

Copyright 2017. All Rights Reserved. Privacy Policy / Terms And Conditions / Sitemap / Contact