0% found this document useful (0 votes)
11 views3 pages

Library Management System

This C++ program implements a library management system that allows a user to issue and return books to students. It stores book and student details in arrays, including book IBAN, name, author, edition, price, quantity, and issue status. The program displays a menu allowing the user to issue or return a book using the student roll number and book IBAN. It also sorts and displays all book details by price or all student details by age. The main function contains a switch statement to process the user's menu choice until they choose to exit.

Uploaded by

ammarwaheed2244
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Library Management System

This C++ program implements a library management system that allows a user to issue and return books to students. It stores book and student details in arrays, including book IBAN, name, author, edition, price, quantity, and issue status. The program displays a menu allowing the user to issue or return a book using the student roll number and book IBAN. It also sorts and displays all book details by price or all student details by age. The main function contains a switch statement to process the user's menu choice until they choose to exit.

Uploaded by

ammarwaheed2244
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

MUHAMMAD NABEEL ARSHAD L1F23BSDS0074

Project : library management system

#include<iostream>
using namespace std;

const int BOOK_COUNT = 4;


const int STUDENT_COUNT = 4;
const string LIBRARY_IDENTIFIER = "LibraryXYZ"; // Replace with your library identifier

// Arrays to store book details


int book_iban_arr[BOOK_COUNT] = { 1, 2, 3, 4 };
string book_names[BOOK_COUNT] = { "History", "Computer Science", "Chemistry", "Literature" };
string book_authors[BOOK_COUNT] = { "John Doe", "Jane Smith", "Alice Johnson", "Bob Brown" };
string book_editions[BOOK_COUNT] = { "1st Edition", "2nd Edition", "3rd Edition", "4th Edition" };
double book_prices[BOOK_COUNT] = { 800.0, 1200.0, 600.0, 150.0 };
int book_quantities[BOOK_COUNT] = { 3, 2, 5, 2 };
bool book_issued[BOOK_COUNT] = { false, false, false, false };

// Arrays to store student details


int student_roll_numbers[STUDENT_COUNT] = { 101, 102, 103, 104 };
int student_ages[STUDENT_COUNT] = { 20, 21, 22, 23 };

// Function to get a valid numeric input


int getNumericInput() {
int input;
while (!(cin >> input) || cin.peek() != '\n') {
cout << "Invalid input. Please enter a valid number: ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
return input;
}

int main() {
int choice, index;
bool is_found;
int iban, student_roll_number;

do {
cout << "1. Issue a book to a student" << endl;
cout << "2. Student returns a book" << endl;
cout << "3. Display details of all books sorted by price" << endl;
cout << "4. Display details of all students sorted by age" << endl;
cout << "5. Exit" << endl;
cout << "Enter your choice: ";
choice = getNumericInput();

switch (choice) {
case 1:
cout << "Enter student roll number: ";
student_roll_number = getNumericInput();

cout << "Enter book IBAN: ";


iban = getNumericInput();
is_found = false;
for (int i = 0; i < BOOK_COUNT; i++) {
if (iban == book_iban_arr[i] && book_quantities[i] > 1 && book_issued[i] == false) {
is_found = true;
index = i;
break;
}
}

if (is_found) {
cout << "Book \"" << book_names[index] << "\" by " << book_authors[index] << " (Edition: " <<
book_editions[index] << ") has been issued to student with roll number " << student_roll_number << endl;
book_quantities[index]--;
book_issued[index] = true;
}
else {
cout << "Book not available, invalid IBAN, or already issued by this library." << endl;
}
break;

case 2:
cout << "Enter student roll number: ";
student_roll_number = getNumericInput();

cout << "Enter book IBAN: ";


iban = getNumericInput();

is_found = false;
for (int i = 0; i < BOOK_COUNT; i++) {
if (iban == book_iban_arr[i] && book_quantities[i] < 5 && book_issued[i] == true) {
is_found = true;
index = i;
break;
}
}

if (is_found) {
cout << "Book \"" << book_names[index] << "\" by " << book_authors[index] << " (Edition: " <<
book_editions[index] << ") has been returned by student with roll number " << student_roll_number << endl;
book_quantities[index]++;
book_issued[index] = false;
}
else {
cout << "Invalid IBAN, the book was not issued by this library, or the book was not issued at all." << endl;
}
break;

case 3:
// Bubble sort for displaying details of all books sorted by price
for (int i = 0; i < BOOK_COUNT; i++) {
for (int j = 0; j < BOOK_COUNT - i - 1; j++) {
if (book_prices[j] > book_prices[j + 1]) {
swap(book_iban_arr[j], book_iban_arr[j + 1]);
swap(book_names[j], book_names[j + 1]);
swap(book_authors[j], book_authors[j + 1]);
swap(book_editions[j], book_editions[j + 1]);
swap(book_prices[j], book_prices[j + 1]);
swap(book_quantities[j], book_quantities[j + 1]);
swap(book_issued[j], book_issued[j + 1]);
}
}
}
cout << "Sorted book details by price:" << endl;
for (int i = 0; i < BOOK_COUNT; i++) {
cout << "IBAN: " << book_iban_arr[i] << " | Name: " << book_names[i] << " | Author: " << book_authors[i] <<
" | Edition: " << book_editions[i] << " | Price: " << book_prices[i] << " | Quantity: " << book_quantities[i] << " | Issued: "
<< (book_issued[i] ? "Yes" : "No") << endl;
}
break;

case 4:
// Bubble sort for displaying details of all students sorted by age
for (int i = 0; i < STUDENT_COUNT; i++) {
for (int j = 0; j < STUDENT_COUNT - i - 1; j++) {
if (student_ages[j] > student_ages[j + 1]) {
swap(student_roll_numbers[j], student_roll_numbers[j + 1]);
swap(student_ages[j], student_ages[j + 1]);
}
}
}
cout << "Sorted student details by age:" << endl;
for (int i = 0; i < STUDENT_COUNT; i++) {
cout << "Roll Number: " << student_roll_numbers[i] << " | Age: " << student_ages[i] << endl;
}
break;

case 5:
cout << "Exiting program." << endl;
break;

default:
cout << "Invalid choice" << endl;
break;
}

} while (choice != 5);

return 0;
}

You might also like