Exp 2
Exp 2
Problem Statement
Design and implement a Library Management System that allows the following operations:
Design
We'll use a structure to represent a book and an array to store multiple books. The system will
have a menu-driven interface to perform the operations.
#include <stdio.h>
#include <string.h>
typedef struct {
int id;
char title[50];
char author[50];
} Book;
Book library[MAX_BOOKS];
int book_count = 0;
// Function prototypes
void addBook();
void displayBooks();
void borrowBook();
int main() {
int choice;
while (1) {
printf("4. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
addBook();
break;
case 2:
displayBooks();
break;
case 3:
borrowBook();
break;
case 4:
return 0;
default:
return 0;
void addBook() {
return;
Book new_book;
new_book.id = book_count + 1;
new_book.available = 1;
library[book_count] = new_book;
book_count++;
}
void displayBooks() {
if (book_count == 0) {
return;
printf("----------------------\n");
void borrowBook() {
int book_id;
scanf("%d", &book_id);
return;
if (library[book_id - 1].available == 0) {
} else {
library[book_id - 1].available = 0;