Write a menu driven program in 'C' that shows the working of a library.The menu option should be - Add book information. - Display book information. - List all books of given author. - List the count of books in the library. - Exit. (Using Structure Array)
#includestruct book { int b_no; char b_name[40]; char b_author[40]; int no_pages; }; void main() { struct book b[20]; int ch,n,i,count = 0; char temp[40]; clrscr(); do { printf("\nPRESS 1.TO ADD BOOK INFORMATION."); printf("\nPRESS 2.TO DISPALY BOOK INFORMATION."); printf("\nPRESS 3.TO DISPLAY BOOK OF GIVEN AUTHOR."); printf("\nPRESS 4.TO COUNT NUMBER OF BOOK."); printf("\nPRESS 5.TO EXIT."); printf("\nENTER YOUR CHOICE::"); scanf("%d",&ch); switch(ch) { case 1: printf("\nHOW MANY RECORDS U WANT :: "); scanf("%d",&n); for(i = 0 ; i < n ; i++) { printf("ENTER BOOK NO. ::> "); scanf("%d",&b[i].b_no); printf("ENTER BOOK NAME ::> "); scanf("%s",b[i].b_name); printf("ENTER AUTHOR NAME ::> "); scanf("%s",b[i].b_author); printf("ENTER NO. OF PAGES ::> "); scanf("%d",&b[i].no_pages); } break; case 2: printf("\nALL BOOK INFORMATION::>"); for( i = 0 ; i < n ; i++) { printf("\n%d\t%s\t%s\t%d",b[i].b_no,b[i].b_name,b[i].b_author, b[i].no_pages); } break; case 3: printf("\nENTER THE AUTHOR NAME :: >\n"); scanf("%s",temp); for( i = 0 ; i < n ; i++) { if(strcmp(b[i].b_author,temp) == 0) { printf("\n%s",b[i].b_name); } } break; case 4 : for( i = 0 ; i < n ; i++) { count++; } printf("\nTOTAL NUMBER OF BOOKS IN LIBRARY :: > %d",count); break; case 5 : exit(0); } }while(ch != 5); getch(); }
Write a menu driven program in 'C' that shows the working of a library.The menu option should be - Add book information. - Display book information. - List all books of given author. - List the count of books in the library. - Exit. (Using Structure Array)
Reviewed by
on
April 24, 2015
Rating: