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.
#define NO_OF_BOOKS 100
struct Library
{
int AccessionNo;
char Title[50];
char Author[50];
float Price;
int Flag;
};
main(void)
{
int n=0,Flag=1,r,k;
struct Library B[NO_OF_BOOKS];
char Auth[50];
n=0;
while(Flag)
{
printf("\n\nPress-1 to Add book information");
printf("\nPress-2 to display book information");
printf("\nPress-3 to display list of all books of given author");
printf("\nPress-4 to display title of specidfied book");
printf("\nPress-5 to display the count of books in the library");
printf("\nPress-6 to list the books in Accession Number");
printf("\nPress-7 to EXIT");
Flag=0;
while(Flag<1 || Flag>7)
{
printf("Enter Choice (1 to 7): "); scanf("%d",&Flag);
}
if(Flag==1)
{
printf("\nEnter Accession No.: "); scanf("%d",&B[n].AccessionNo);
printf("\nEnter Title : "); scanf("%s",B[n].Title);
printf("\nEnter Author : "); scanf("%s",B[n].Author);
printf("\nEnter Price : "); scanf("%f",&B[n].Price);
printf("\nEnter Flag : "); scanf("%d",&B[n].Flag);
printf("\nBook added successfully.");
n=n+1;
}
if(Flag==2)
{
for(r=0;r<n;r++)
{
printf("\n%10d%10s%10s%10.2f",B[r].AccessionNo,B[r].Title,B[r].Author,B[r].Price);
if(B[r].Flag) printf("\tNot Issued");
else printf("\tIssued");
}
}
if(Flag==3)
{
printf("\nEnter Accession Name: "); scanf("%s",&Auth);
for(r=0;r<n;r++)
{
if(strcmpi(Auth,B[r].Author))
{
printf("\n%10d%10s%10s%10.2f",B[r].AccessionNo,B[r].Title,B[r].Author,B[r].Price);
if(B[r].Flag) printf("\tNot Issued");
else printf("\tIssued");
}
}
}
if(Flag==4)
{
printf("\nEnter Accession No.: "); scanf("%d",&k);
for(r=0;r<n;r++)
{
if(k==B[r].AccessionNo)
{
printf("\n%10d%10s%10s%10.2f",B[r].AccessionNo,B[r].Title,B[r].Author,B[r].Price);
if(B[r].Flag) printf("\tNot Issued");
else printf("\tIssued");
}
}
}
if(Flag==5)
{
printf("\nTotal No. of books in library = %d",n);
}
if(Flag==6)
{
for(r=0;r<n;r++)
{
printf("\n%10d%10s%10s%10.2f",B[r].AccessionNo,B[r].Title,B[r].Author,B[r].Price);
if(B[r].Flag) printf("\tNot Issued");
else printf("\tIssued");
}
}
if(Flag==7) exit(0);
}
}
Comments
Leave a comment