0% found this document useful (0 votes)
18 views

#Include Using Namespace Int

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)
18 views

#Include Using Namespace Int

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
You are on page 1/ 2

#include <bits/stdc++.

h>
using namespace std;

int main() {
string x;
cout<<"Enter name : ";
cin>>x;
cout<<"\n";
map<int , string > mp;
mp.insert({10,"BOOK1"});
mp.insert({20,"BOOK2"});
mp.insert({30,"BOOK3"});
mp.insert({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(mp.count(bn) > 0)
{
cout<<mp[bn]<<" taken!\n";
mp.erase(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 ( mp.count(bn)>0 ) {
cout<<"Book with same book number already exists!\n";
}
else {
mp.insert({ bn, name });
cout<<"Book Added!\n\n";
}
}
break;
case 3:
{
cout<<"Here are the books:\n";
map<int, string>::iterator it;
for ( it = mp.begin(); it != mp.end(); 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