Categories
Uncategorised

Classes – Library

/* Copyright © 2007 Ankur Banerjee. Special thanks to Naman Bagga for source code verification. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. http://www.fsf.org/licensing/licenses/lgpl.html /

/ Classes – Program to manage library /

#include <iostream.h>
#include <conio.h>
#include <stdio.h>

int i, flag, n, f;

class library
{
int bookno, copies, issued;
char bookname[20], author[20];
float price;
public:
void accept()
{
cout<<endl<<“Enter data for book “<<i + 1<<endl
<<“Enter book number : “;
cin>>bookno;
cout<<“Enter book name : “;
gets(bookname);
cout<<“Enter author name : “;
gets(author);
cout<<“Enter book price : “;
cin>>price;
cout<<“Enter number of copies in library : “;
cin>>copies;
cout<<“Enter number of copies issued : “;
cin>>issued;
}
int issue(int num)
{
if (num == bookno)
if (copies > issued)
{
issued++;
flag = 1;
}
return flag;
}
int ret(int num)
{
if (num == bookno)
issued–;
return flag;
}
void display(int num)
{
if (num == bookno)
cout<<endl<<“Displaying data for requested book “
<<endl<<“Book number : “<<bookno<<endl
<<“Book name : “<<bookname<<endl
<<“Author : “<<author<<endl
<<“Price : “<<price<<endl
<<“Number of copies in library : “<<copies
<<endl<<“Number of copies issued : “<<issued;
}
} lib[10];

void main()
{
clrscr();
int ch;
char choice;
cout<<endl<<“Library Management Software”<<endl
<<“Enter data for 10 books in the library”<<endl;
for (i = 0; i < 10; i++)
lib[i].accept();
do
{
cout<<endl<<“Program Menu”<<endl
<<“1. Issue a book”<<endl
<<“2. Return a book”<<endl
<<“3. Display book information”<<endl
<<“Enter your choice : “;
cin>>ch;
if (ch == 1)
{
cout<<endl<<“Enter book number for book to be issued : “;
cin>>n;
flag = 0;
for (i = 0; i < 10; i++)
{
f = lib[i].issue(n);
if (flag == 1)
break;
}
if (flag == 1)
cout<<“Book with book number “<<n<<” has been issued”;
else cout<<“Book with book number “<<n
<<” is not available at the moment”;
}
else if (ch == 2)
{
cout<<endl<<“Enter book number for book to be returned : “;
cin>>n;
for (i = 0; i < 10; i++)
{
f = lib[i].ret(n);
if (flag == 1)
break;
}
if (flag == 1)
cout<<“Book with book number “<<n<<” has been returned”;
}
else if (ch == 3)
{
cout<<endl<<“Enter book number for required book : “;
cin>>n;
for (int i = 0; i < 10; i++)
lib[i].display(n);
}
else cout<<endl<<“You entered an incorrect choice”;
cout<<“\n \nDo you wish to continue – y / n : “;
cin>>choice;
} while (choice == ‘y’ || choice == ‘Y’);
cout<<endl;
getch();
}

/ Output */

Library Management Software
Enter data for 10 books in the library

Enter data for book 1
Enter book number : 42
Enter book name : Hitchhiker’s
Enter author name : Douglas Adams
Enter book price : 650
Enter number of copies in library : 42
Enter number of copies issued : 35

Program Menu
1. Issue a book
2. Return a book
3. Display book information
Enter your choice : 1

Enter book number for book to be issued : 42
Book with book number 42 has been issued

Do you wish to continue – y / n : y

Program Menu
1. Issue a book
2. Return a book
3. Display book information
Enter your choice : 2

Enter book number for book to be returned : 42
Book with book number 42 has been returned

Do you wish to continue – y / n : y

Program Menu
1. Issue a book
2. Return a book
3. Display book information
Enter your choice : 3

Enter book number for required book : 42

Displaying data for requested book
Book number : 42
Book name : Hitchhiker’s
Author : Douglas Adams
Price : 650
Number of copies in library : 42
Number of copies issued : 35

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.