Write a program library management system menu driven program that depicts the working of a library
Write a Program Library Management System
Object: Write a menu driven program that depicts the working of a library. The menu options should be:
a) Add book information b) Display book information c) List all books of given author d) List the title of specified book e) List the count of books in the library f) List the books in the order of accession number g) Exit.
Create a structure called library to hold accession number, title of the book, author name, price of the book, and flag indicating whether book is issued or not. C++ projects for beginners with source code
Code:
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
void addbok();
void dipbok();
void bokaut();
void count();
void listacc();
void assacc();
struct lib
{
int acno;
float no_p;
char booknam[30];
char auther[20],flag[5];
}c[100];
int cont;
void main()
{
int a;
cout<<“\n\t———————————————————————-\n”;
cout<<“\t L i b r a r y M a n a g e m e n t S y s t e m\n”;
cout<<“\t———————————————————————-\n”;
while(1)
{
cout<<“\n============================================================\n”;
cout<<“Press 1 for Add book information:\n”;
cout<<“Press 2 for Display book information:\n”;
cout<<“Press 3 for List all books of given author:\n”;
cout<<“Press 4 for List the count of books in the library:\n”;
cout<<“Press 5 for List the title of specified book:\n”;
cout<<“Press 6 for List the books in the order of accession number:\n”;
cout<<“Press 7 for Exit:\n”;
cin>>a;
switch(a)
{
case 1:
addbok();
getch();
break;
case 2:
dipbok();
getch();
break;
case 3:
bokaut();
getch();
break;
case 4:
count();
getch();
break;
case 5:
listacc();
getch();
break;
case 6:
assacc();
getch();
break;
case 7:
exit(0);
break;
default:
cout<<“Invalid Entry.”;
break;
}
}
getch();
}
void addbok()
{
if(cont==9)
{
cout<<“\n No space\n”;
return;
}
cout<<“Add book information\n”;
cout<<“Enter Accession Number of book: “;
cin>>c[cont].acno;
cin.ignore();
cout<<“Enter the book title: “;
gets(c[cont].booknam);
cout<<“Enter the Name of author: “;
gets(c[cont].auther);
cout<<“Enter Price of the Book: “;
cin>>c[cont].no_p;
cout<<“Book Issued (yes or not): “;
cin>>c[cont].flag;
cont++;
}
void dipbok()
{
cout<<“\nDisplay book information\n”;
for(int i=0;i<cont;i++)
{
cout<<“\n=========================================”;
cout<<“\nAccession Number of book is: “<<c[i].acno;
cout<<“\nTitle of book is: “<<c[i].booknam;
cout<<“\nName of Author is: “<<c[i].auther;
cout<<“\nPrice of book is: “<<c[i].no_p;
cout<<“\nBook Issued (yes or not): “<<c[i].flag;
}
}
void bokaut()
{
int cnt=0,i;
char nam[20];
cin.ignore();
cout<<“Enter the Author Name: “;
gets(nam);
for(i=0;i<cont;i++)
{
if(strcmp(nam,c[i].auther)==0)
{
cnt++;
cout<<“\n=========================================”;
cout<<“\nAccession Number of book is: “<<c[i].acno;
cout<<“\nTitle of book is: “<<c[i].booknam;
cout<<“\nName of Author is: “<<c[i].auther;
cout<<“\nPrice of book is: “<<c[i].no_p;
cout<<“\nBook Issued (yes or not): “<<c[i].flag;
}
}
if(cnt==0)
{
cout<<“\n Author Not found.\n”;
}
}
void count()
{
cout<<“Total no of book in library: “<<cont;
}
void listacc()
{
int cnt=0,i;
char nam[20];
cin.ignore();
cout<<“Enter the Book Name: “;
gets(nam);
for(i=0;i<cont;i++)
{
if(strcmp(nam,c[i].booknam)==0)
{
cnt++;
cout<<“\n=========================================”;
cout<<“\nAccession Number of book is: “<<c[i].acno;
cout<<“\nTitle of book is: “<<c[i].booknam;
cout<<“\nName of Author is: “<<c[i].auther;
cout<<“\nPrice of book is: “<<c[i].no_p;
cout<<“\nBook Issued (yes or not): “<<c[i].flag;
}
}
if(cnt==0)
{
cout<<“\n Book Not found.\n”;
}
}
void assacc()
{
int i,j,temp;
for(i=0;i<cont;i++)
{
for(j=0;j<cont-1;j++)
{
if(c[i].acno>c[j+1].acno)
{
temp=c[i].acno;
c[i].acno=c[j+1].acno;
c[j+1].acno=temp;
}
}
}
for(j=0;j<cont;j++)
{
cout<<“\nAccession Number is: “<<c[j].acno;
cout<<“\nTitle of book is: “<<c[j].booknam;
cout<<“\nName of Author is: “<<c[j].auther;
cout<<“\nPrice of book is: “<<c[j].no_p;
cout<<“\nBook Issued (yes or not): “<<c[j].flag;
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | #include<iostream> #include<conio.h> #include<string> using namespace std; void addbok(); void dipbok(); void bokaut(); void count(); void listacc(); void assacc(); struct lib { int acno; float no_p; char booknam[30]; char auther[20],flag[5]; }c[100]; int cont; void main() { int a; cout<<"\n\t----------------------------------------------------------------------\n"; cout<<"\t L i b r a r y M a n a g e m e n t S y s t e m\n"; cout<<"\t----------------------------------------------------------------------\n"; while(1) { cout<<"\n============================================================\n"; cout<<"Press 1 for Add book information:\n"; cout<<"Press 2 for Display book information:\n"; cout<<"Press 3 for List all books of given author:\n"; cout<<"Press 4 for List the count of books in the library:\n"; cout<<"Press 5 for List the title of specified book:\n"; cout<<"Press 6 for List the books in the order of accession number:\n"; cout<<"Press 7 for Exit:\n"; cin>>a; switch(a) { case 1: addbok(); getch(); break; case 2: dipbok(); getch(); break; case 3: bokaut(); getch(); break; case 4: count(); getch(); break; case 5: listacc(); getch(); break; case 6: assacc(); getch(); break; case 7: exit(0); break; default: cout<<"Invalid Entry."; break; } } getch(); } void addbok() { if(cont==9) { cout<<"\n No space\n"; return; } cout<<"Add book information\n"; cout<<"Enter Accession Number of book: "; cin>>c[cont].acno; cin.ignore(); cout<<"Enter the book title: "; gets(c[cont].booknam); cout<<"Enter the Name of author: "; gets(c[cont].auther); cout<<"Enter Price of the Book: "; cin>>c[cont].no_p; cout<<"Book Issued (yes or not): "; cin>>c[cont].flag; cont++; } void dipbok() { cout<<"\nDisplay book information\n"; for(int i=0;i<cont;i++) { cout<<"\n========================================="; cout<<"\nAccession Number of book is: "<<c[i].acno; cout<<"\nTitle of book is: "<<c[i].booknam; cout<<"\nName of Author is: "<<c[i].auther; cout<<"\nPrice of book is: "<<c[i].no_p; cout<<"\nBook Issued (yes or not): "<<c[i].flag; } } void bokaut() { int cnt=0,i; char nam[20]; cin.ignore(); cout<<"Enter the Author Name: "; gets(nam); for(i=0;i<cont;i++) { if(strcmp(nam,c[i].auther)==0) { cnt++; cout<<"\n========================================="; cout<<"\nAccession Number of book is: "<<c[i].acno; cout<<"\nTitle of book is: "<<c[i].booknam; cout<<"\nName of Author is: "<<c[i].auther; cout<<"\nPrice of book is: "<<c[i].no_p; cout<<"\nBook Issued (yes or not): "<<c[i].flag; } } if(cnt==0) { cout<<"\n Author Not found.\n"; } } void count() { cout<<"Total no of book in library: "<<cont; } void listacc() { int cnt=0,i; char nam[20]; cin.ignore(); cout<<"Enter the Book Name: "; gets(nam); for(i=0;i<cont;i++) { if(strcmp(nam,c[i].booknam)==0) { cnt++; cout<<"\n========================================="; cout<<"\nAccession Number of book is: "<<c[i].acno; cout<<"\nTitle of book is: "<<c[i].booknam; cout<<"\nName of Author is: "<<c[i].auther; cout<<"\nPrice of book is: "<<c[i].no_p; cout<<"\nBook Issued (yes or not): "<<c[i].flag; } } if(cnt==0) { cout<<"\n Book Not found.\n"; } } void assacc() { int i,j,temp; for(i=0;i<cont;i++) { for(j=0;j<cont-1;j++) { if(c[i].acno>c[j+1].acno) { temp=c[i].acno; c[i].acno=c[j+1].acno; c[j+1].acno=temp; } } } for(j=0;j<cont;j++) { cout<<"\nAccession Number is: "<<c[j].acno; cout<<"\nTitle of book is: "<<c[j].booknam; cout<<"\nName of Author is: "<<c[j].auther; cout<<"\nPrice of book is: "<<c[j].no_p; cout<<"\nBook Issued (yes or not): "<<c[j].flag; } } |
1 Response
[…] Write a program library management system menu driven program that depicts the working of a library […]