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.
#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;
void main()
{
int ch;
while(1)
{
clrscr();
{
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);
printf("\n enter the book title=");
scanf("%s",b[count].book_title);
printf("\n enter the name of author=");
scanf("%s",b[count].author);
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=");
scanf("%s",nam7Â Â Â `e);
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);
}
Comments
Leave a comment