0% found this document useful (0 votes)
30 views2 pages

Library Management Program

This C++ program manages a library using a map data structure. It prompts the user to enter their name and provides a menu with options to take or donate a book, check available books, or exit. Depending on the option selected, it will either remove or add key-value pairs to the map, or print out all key-value pairs to check the available books. The program runs in a loop until the user selects the exit option.

Uploaded by

Ashish Pathak
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)
30 views2 pages

Library Management Program

This C++ program manages a library using a map data structure. It prompts the user to enter their name and provides a menu with options to take or donate a book, check available books, or exit. Depending on the option selected, it will either remove or add key-value pairs to the map, or print out all key-value pairs to check the available books. The program runs in a loop until the user selects the exit option.

Uploaded by

Ashish Pathak
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

#include <bits/stdc++.

h>
using namespace std;

int main() {
string x;
cout<<"Enter name : ";
cin>>x;
cout<<"\n";
map<int , string > mp;
[Link]({10,"BOOK1"});
[Link]({20,"BOOK2"});
[Link]({30,"BOOK3"});
[Link]({40,"BOOK4"});

int flag=0;
int input;
while(flag==0){
cout<<"Hello "<<x<<",\nWelcome to Libraby Manager\n";
cout<<"Select a task to perform:\n";
cout<<"1. Take a book\n";
cout<<"2. Donate a book\n";
cout<<"3. Check books\n";
cout<<"4. EXIT\n";
cin>>input;
cout<<"-------------------\n";
switch(input)
{
case 1:
{
int bn;
cout<<"Enter book number: ";
cin>>bn;
if([Link](bn) > 0)
{
cout<<mp[bn]<<" taken!\n";
[Link](bn);
}
else
{
cout<<"Book not found...\n";
}
}
break;
case 2:
{
int bn;
string name;
cout<<"Enter book number: ";
cin>>bn;
cout<<endl;
cout<<"Enter book name: ";
cin>>name;
cout<<endl;
if ( [Link](bn)>0 ) {
cout<<"Book with same book number already exists!\n";
}
else {
[Link]({ bn, name });
cout<<"Book Added!\n\n";
}
}
break;
case 3:
{
cout<<"Here are the books:\n";
map<int, string>::iterator it;
for ( it = [Link](); it != [Link](); it++ )
{
cout << it->first
<< " : "
<< it->second // string's value
<<endl ;
}
cout<<endl;
cout<<"-------------------\n";
}
break;
case 4: {cout<<"Bye "<<x;flag=1;}
break;
default:cout<<"Enter proper values -_- \n\n";
}
}
return 0;
}

You might also like