Example 2: Write a menu driven program in 'C' which shows the working of library. The menu option should be: i) Add book details. ii) Display book details. iii) List all books of given author. iv) Show the count of books in the library. v) Exit. Create a structure called library to hold Book ID, title of the book, author name, price of the book. Code: #include #include struct library{ int id; char title[40]; char author[20]; float price; } b[100] ; int num=0; void Add(){ printf("How many books' info do you want to enter? "); scanf(" %d",&num); for(int i=0;i

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Example 2: Write a menu driven program in 'C' which shows the working of library. The
menu option should be:


i) Add book details.
ii) Display book details.
iii) List all books of given author.
iv) Show the count of books in the library.
v) Exit.


Create a structure called library to hold Book ID, title of the book, author name, price of
the book.

Code:


#include<stdio.h>
#include<string.h>
struct library{
int id;
char title[40];
char author[20];
float price;
} b[100] ;
int num=0;
void Add(){
printf("How many books' info do you want to enter? ");
scanf(" %d",&num);
for(int i=0;i<num;i++){
printf("Enter the following information about the book:\n");
printf("ID, title, author's name, price(in Tk)\n");
scanf(" %d %s %s %f",&b[i].id,&b[i].title,&b[i].author,&b[i].price);
}
}
void Disp(){
printf("\tID\tName\tAuthor\tPrice(Tk)\n");
for(int i=0;i<num;i++){
printf("\t%d\t%s\t%s\t%f\n",b[i].id,b[i].title,b[i].author,b[i].price);
}
}
void Count(){
printf("\nNo of books avalable in the library = %d\n",num);
}
void List(){
char str[20];
printf("Enter the author's name: ");
scanf("%s",str);
for(int i=0;i<num;i++){
if(strcmp(str,b[i].author)==0)
printf("\n\t%d\t%s\t%s\t%f\n",b[i].id,b[i].title,b[i].author,b[i].price);
}
}

int main(){
int option=0;
do {
printf("\nWelcome to the library\nPlease Select an Option: \n");
printf("-----------------------------------------------------------
\n");
printf("1.Add book details\n2.Display book details\n3.List all books
of a given author\n4.Show total no. of books in the library.\n5.Exit\n");
printf("-----------------------------------------------------------
\n");
scanf("%d",&option);
switch(option){
case 1: Add();
break;
case 2: Disp();
break;
case 3: List();
break;
case 4: Count();
break;
}
}while(option != 5);
return 0;
}

 

 


Report:
Make the following modifications to the system in Example-2
- Add a password-protected authorization system so that option-1 can be used by
the librarian only
- Enable the use of multi-word strings in book titles and author names
- Make the system dynamic: make sure that the newly input book info does not
overwrite the previous ones.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Please explain the code step by step. 

Solution
Bartleby Expert
SEE SOLUTION
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY