Sunday, September 14, 2014

create a menu driven library management program using structure and functions


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. Create an array of size 25 of type library. Input record from user and check all the options of the program.

Solution - Code

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>

void add_book();
void disp_book();
void book_auth();
void count_book();

struct lib
{
 int acc_no;
 char book_title[20];
 char author[20];
 int cost;
}b[100];
int count;
main()
{
 int ch;
 while(1)
 {
  printf("\n 1:enter the book info\n");
  printf("\n 2:display book info\n");
  printf("\n 3:book author\n");
  printf("\n 4:count book\n");
  printf("\n 5:exit\n");
  printf("\n enter the choice \n");
  scanf("%d",&ch);
  switch(ch)
  {
   case 1:
    add_book();
    getch();
    break;
   case 2:
    disp_book();
    getch();
    break;
   case 3:
    book_auth();
    getch();
    break;
   case 4:
    count_book();
    getch();
    break;
   case 5:
    exit(0);
  }
 }
}
//-----------------------------------
void add_book()
{
 if(count==9)
 {
  printf("\n no more space\n");
  return;
 }
 printf("\n enter the detail of book \n");
 printf("\n enter accession number of book =");
 scanf("%d",&b[count].acc_no);
 fflush(stdin);
 printf("\n enter the book title=");
 gets(b[count].book_title);
 fflush(stdin);
 printf("\n enter the name of author=");
 gets(b[count].author);
 fflush(stdin);
 printf("\n enter the cost of book=");
 scanf("%d",&b[count].cost);
 count++;
}
//***********************
void disp_book()
{
 int i;
 printf("\n detail of %d booksin library",count);
 for(i=0;i<count;i++)
 {
  printf("\n %d\n%s\n%s\n%d",b[i].acc_no,b[i].book_title,b[i].author,b[i].cost);
 }
}
//*********************
void book_auth()
{
 int i,cnt=0;
 char name[20];
 printf("\n enter the name of author=");
 gets(name);
 for(i=0;i<count;i++)
 {
  if(strcmp(name,b[i].author)==0)
  {
   cnt++;
   printf("\n %d\n%s\n%s\n%d",b[i].acc_no,b[i].book_title,b[i].author,b[i].cost);
  }
 }
 if(cnt==0)
  printf("\n no such book \n");
}
//*******************************
void count_book()
{
 printf("\n total no of book in library =%d",count);
}

Sample Output

add book record c language

display library books

display total library books in c language

No comments :

Post a Comment

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

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