Anda di halaman 1dari 28

Library Program 3

============================================
#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <process.h>
enum status{issued,available,stolen,damage};
int check=1,counter=0,race=0;
template<class T>
class list
{
public:
int maxsize;
int used;
T *a;
public:
list(int s)
{
maxsize=s;
used=0;
a=new T[maxsize];
}
public:
setlist(T p)
{
if(!isFull())
{
a[used]=p;
used++;
return true;
}
else
{
return false;
}

}
bool isFull()
{
return used==maxsize;
}
bool getlist(int index,T &p)
{
if(index<used)
{
p=a[index];
return true;
}
else
{
return false;
}
}
};
class book
{

public:

int isbn;
char title[50];
char author[25];
float price;
status st;

//Simple Constructor
public:
book(int ,char *,char *,float ,status );
book();
int getisbn();
void setisbn(int );
char *gettitle();
char *getauthor();
float getprice();
status getst();
void setstatus(status p);
};

class library
{

private:
int capacity;
book *b;
int totalbooks;
public:
library(int );
~library() ;
bool isfull();
bool addbook(int id,char *,char *,float );
bool searchbook(int ,int *) ;
bool searchtitle(char *,int *);
bool searchauthor(char *,int *) ;
bool adamage(int );
bool astolen(int );
bool issuebook(int is);
bool returnbook(int );
void modifyisbn(int ,int );
void menu(void);
void modify(void);
void pricerange(void);
void entry(void);
void issue(void );
void printrecord(void);
void retubook(void);
void sauthor(void);
void stitle(void);
void pavailablebooks(void);
void pissuedbooks(void);
void adddamage(void);

void addstolen(void);

//list of acessing functions

};

void main()
{
book a;
int size;
cout<<"Enter the size=";
cin>>size;
list<book>ist(size);
for(int i=0;i<size;i++)
{
ist.setlist(a);
}
for(int b=0;b<size;b++)
{
ist.getlist(b,a);
}
library trial(100 );
trial.menu();
//trial.addbook(20,"PHYSICS","THOMAS",100);
//if(trial.issuebook(20))
//cout<<"\nBOOK ISSUED ";
//else
//cout<<"\nBook not available or already issued : ";
}

book::book(int id,char *t,char *a,float p,status s)


//Parametrized
Constructor
{
isbn=id;
strcpy(title,t);
strcpy(author,a);
price=p;
st=s;
}
book::book()
{

int book::getisbn()
{
return isbn;
}

void book::setisbn(int p)
{
isbn=p;
}

char *book::gettitle()
{
return title;
}

char *book::getauthor()
{
return author;
}

float book::getprice()
{

return price;
}

status book::getst()
{
return st;
}

void book::setstatus(status p)
{
st=p;
}
library::library(int size)
{
capacity=size;
b=new book[capacity];
totalbooks=0;
}

library:: ~library()
{

delete[]b;
}

bool library::isfull() //checker full stack


{

if(totalbooks==capacity)
return true;
else
return false;
}

bool library::addbook(int id,char *t,char *a,float p) //adding book


function
{

if(!isfull())
{

book ob(id,t,a,p,available);
b[totalbooks]=ob;
totalbooks++;
return true;
}
else
return false;
}

bool library::searchbook(int key,int *loc) //searching algorithm


{
int i=0;
while(b[i].getisbn()!=key&&(i<totalbooks))
{
i++;

if(i<totalbooks)
{
*loc=i;
return true;

}
else
return false;
}

//search author function is below


bool library::searchauthor(char *authorname,int *location)
//searching algorithm
{
int i=0;
if(strcmpi(b[i].getauthor(),authorname)&&(i<totalbooks))
{
i++;

if(i<totalbooks)
{
*location=i;
return true;

}
else
return false;
}

//title search

bool library::searchtitle(char *booktitle,int *dir) //searching


algorithm
{
int i=0;
if(strcmpi(b[i].gettitle(),booktitle)&&(i<totalbooks))
{
i++;

if(i<totalbooks)
{
*dir=i;
return true;

}
else
return false;
}

//add damage

bool library::adamage(int ps) //adding book function :


{

int loc;
if(searchbook(ps,&loc))
{

if(b[loc].getst()==available)
{
counter++;
b[loc].setstatus(damage);
return true;
}
else
return false;

}
else
return false;
}

//add stolen
bool library::astolen(int ps) //adding book function :
{

int loc;
if(searchbook(ps,&loc))
{

if(b[loc].getst()==available)
{
race++;
b[loc].setstatus(stolen);
return true;
}
else
return false;

}
else
return false;
}

//end of stolen function


bool library::issuebook(int is) //adding book function :
{

int loc;
if(searchbook(is,&loc))
{

if(b[loc].getst()==available)
{
b[loc].setstatus(issued);
return true;
}
else
return false;

}
else
return false;
}

//return book is illustrated below


bool library::returnbook(int is) //adding book function :
{

int loc;
if(searchbook(is,&loc))
{

if(b[loc].getst()==issued)
{
b[loc].setstatus(available);
return true;
}
else
return false;
}
else
return false;
}
void library::menu(void)
{

char op;
system("cls");
cout<<"******************************* MAIN MENU
******************************* \n\n";
cout<<"\n\n1:Add Book ";
cout<<"\n\n2:Issue Book ";
cout<<"\n\n3:Return Book ";
cout<<"\n\n4:Show all ";
cout<<"\n\n5:Search By Author Name ";
cout<<"\n\n6:Search By Title ";
cout<<"\n\n7:Print Issued Books ";
cout<<"\n\n8:Print Available Books ";
cout<<"\n\n9:Add Damage ";
cout<<"\n\nT:Total number of damaged books ";
cout<<"\n\nS:Add Stolen ";
cout<<"\n\nC:Total number of stolen";
cout<<"\n\nP:Price Range Enquiry ";
cout<<"\n\nM:Modify ";
cout<<"\n\nQ:Quit";
cout<<"\n\n\n\n Enter Your Choice To Proceed Forward :
";

cout.flush();
op=getch();
if(op=='q'||op=='Q')
{
exit(0);
}

else if(op=='1')
entry();
else if (op=='2')
issue();
else if(op=='3')
retubook();
else if(op=='4')
printrecord();
else if(op=='5')
sauthor();
else if(op=='6')
stitle();
else if(op=='7')
pissuedbooks();
else if(op=='8')
pavailablebooks();
else if(op=='9')
adddamage();

else if(op=='c'||op=='C')
{
system ("cls ");
cout<<"Total number of stolen books : "<<race;
cout.flush();
getch();
menu();
}

else if(op=='s'||op=='S')
{
addstolen();
}

else if(op=='t'||op=='T')
{

system ("cls ");


cout<<"Total number of damaged books : "<<counter;
cout.flush();
getch();
menu();

else if(op=='p'||op=='P')
{
pricerange();

else if(op=='m'||op=='M')
{modify();}

else
{
cout<<"\n\nPlease select Provided Options (1-10)";
cout.flush();
getch();
system("cls");
menu();

//modify functions
void library::modify(void)
{

char rec;
int psystem,nsystem,loce;
system("cls");
cout<<"\n1:Modify Isbn";
cout<<"\n2:Modify Author Name ";
cout.flush();
rec=getch();
if(rec=='1')
{
cout<<"\n\nEnter Previous Isbn of the book : ";
cin>>psystem;
if(searchbook(psystem,&loce))
cout<<"\n\nOk ,AlRight Proceed Forward :";
else
{
cout<<"\n\n(suspicious acticity )Isbn No not
Matched ";
cout.flush();
getch();
modify();
}

cout<<"\n\nEnter New Isbn of the book : ";


cin>>nsystem;
modifyisbn(psystem,nsystem);
}

else if(rec=='2')
{

cout<<"\n\nunder construction :v";

cout.flush();
getch();
menu();

void library::modifyisbn(int old,int latest)


{

for(int t=0;t<totalbooks;t++)
{

if(b[t].getisbn()==old)
{
b[t].setisbn(latest);
continue;
}

else
continue;
}

void library::pricerange(void)
{
system("cls");
float low,high;
int ch=1;;
cout<<"\n\nEnter Lower Limit : ";
cin>>low;
cout<<"\n\nEnter Upper Limit : ";
cin>>high;

for(int t=0;t<totalbooks;t++)
{

if(b[t].getprice()>=low&&b[t].getprice()<=high)
{
ch=0;

cout<<"\n\n***************************************
*************";
cout<<"\n\n "<<b[t].gettitle();
cout<<"\n\nISBN NO : "<<b[t].getisbn();
cout<<"\n\nAuthor : "<<b[t].getauthor();
cout<<"\n\nPrice : "<<b[t].getprice();
if(b[t].getst()==available)
cout<<"\n\nStatus : Available";
else if(b[t].getst()==issued)
cout<<"\n\nStatus :Issued ";
else if(b[t].getst()==stolen)
cout<<"\n\nStatus :Stolen";
else if(b[t].getst()==damage)
cout<<"\n\nStatus :Damage";

cout<<"\n\n***************************************
**************\n";
continue;
}

else
continue;

if(ch==1)
cout<<"\n\nNo Book In Given Price Range In Our Library
: ";
cout.flush();
getch();
menu();

}
void library::entry(void)
{
int ISBN;
char string1[50];
char author [50];
float price;
system("cls");
cout<<"\n ADDING RECORD
\n ";

cout<<"\n\nEnter ISBN of the book : ";


cin>>ISBN;
check=0;
cout<<"\nEnter Title of the book : ";
cout.flush();
gets(string1);
cout<<"\nEnter Name of Author : ";
cout.flush();
gets(author);
cout<<"\nEnter Price of the book : ";
cin>>price;
if(addbook(ISBN,string1,author,price))
cout<<"\nBOOK ADDED SUCCESSFULY ";
else
{
cout<<"\nBOOK ALREADY EXISTS:";
}

cout.flush();
getch();
system("cls");
menu();

void library::issue(void )
{
system("cls");
int ub;
cout<<"\n\nEnter ISBN no of the book : ";
cin>>ub;
if(issuebook(ub))
cout<<"\n\nBOOK ISSUED ";
else
cout<<"\n\n ! check status ";
cout.flush();
getch();
menu();
}

void library::printrecord(void)
{

int j=0;
cout.flush();
system("cls");

if(check!=0)
cout<<"\n\n No Book Is Added Untill Know ";
else
{

for(int i=0;i<totalbooks;i++)
{

cout<<"\n\n***************************************
*************";
cout<<"\n\n "<<b[i].gettitle();
cout<<"\n\nISBN NO : "<<b[i].getisbn();
cout<<"\n\nAuthor : "<<b[i].getauthor();
cout<<"\n\nPrice : "<<b[i].getprice();
if(b[i].getst()==available)
cout<<"\n\nStatus : Available";
else if(b[i].getst()==issued)
cout<<"\n\nStatus :Issued ";
else if(b[i].getst()==stolen)
cout<<"\n\nStatus :Stolen";
else if(b[i].getst()==damage)
cout<<"\n\nStatus :Damage";
cout<<"\n\n***************************************
**************\n";
continue;
}

cout.flush();
getch();
system("cls");
menu();

void library::retubook(void)
{
system("cls");
int temp;
cout<<"\n-----------------------------------------------------------------
\n";
cout<<"\n\n Return Menu
\n";
cout<<"\n\n---------------------------------------------------------------
\n";
cout<<"\n\nEnter ISBN no of book :";
cin>>temp;

if(returnbook(temp))
{
cout<<"\nBook Returned Successfully :";
}

else
cout<<"\nCheck status ";
cout.flush();
getch();
menu();
}
void library::sauthor(void)
{

char au[50];
int location;
system("cls");

cout<<"\n\n-----------------------------------------------------------
-\n";
cout<<"\n Search Menu
";

cout<<"\n\n-----------------------------------------------------------
-\n";

cout<<"\n\nEnter Name of the Author : ";


cout.flush();
gets(au);
if(searchauthor(au,&location))
{

cout<<"\n\n***************************************
**********************\n";
cout<<"\n ISBN NO : "<<b[location].getisbn();
cout<<"\n\n Book Title : "<<b[location].gettitle();

if(b[location].getst()==available)
cout<<"\n\n Status : Available";
else if(b[location].getst()==issued)
cout<<"\n\n Status :Issued ";
else if(b[location].getst()==stolen)
cout<<"\n\n Status :Stolen";
else if(b[location].getst()==damage)
cout<<"\n\n Status :Damage";

cout<<"\n**********************************************
***************\n";

}
else
{
cout<<"\n\nMatch Not Found ";
}
cout.flush();
getch();
system("cls");
menu();

//title search
void library::stitle(void)
{

char at[50];
int dir;
system("cls");

cout<<"\n\n-----------------------------------------------------------
-\n";
cout<<"\n Search Menu(By Title)
";

cout<<"\n\n-----------------------------------------------------------
-\n\n\n";

cout<<"\n\n\nEnter Title Of The Book : ";


cout.flush();
gets(at);
if(searchtitle(at,&dir))
{

cout<<"\n\n***************************************
*********************\n\n";
cout<<"\n ISBN NO : "<<b[dir].getisbn();
cout<<"\n\n Book Title : "<<b[dir].gettitle();

if(b[dir].getst()==available)
cout<<"\n\n Status : Available";
else if(b[dir].getst()==issued)
cout<<"\n\n Status :Issued ";
else if(b[dir].getst()==stolen)
cout<<"\n\n Status :Stolen";
else if(b[dir].getst()==damage)
cout<<"\n\n Status :Damage";

cout<<"\n**********************************************
***************\n";
}

else
{
cout<<"\n\nMatch Not Found ";
}
cout.flush();
getch();
system("cls");
menu();

//print issued books

void library::pissuedbooks(void)

int k=0;
cout.flush();
system("cls");
for(int i=0;i<totalbooks;i++)
{

if(b[i].getst()==issued)
{

k=1;

cout<<"\n\n***************************************
*************";
cout<<"\n\n "<<b[i].gettitle();
cout<<"\n\nISBN NO : "<<b[i].getisbn();
cout<<"\n\nAuthor : "<<b[i].getauthor();
cout<<"\n\nPrice : "<<b[i].getprice();
if(b[i].getst()==issued)
cout<<"\n\nStatus :Issued ";

cout<<"\n\n********************************************
*********\n";
continue;
}

else
continue;
}

if(k!=1)
cout<<"\n\nNo Book Issued ";

cout.flush();
getch();
system("cls");
menu();

//print available books

void library::pavailablebooks(void)

int k=0;
cout.flush();
system("cls");
for(int i=0;i<totalbooks;i++)
{

if(b[i].getst()==available)
{

k=1;

cout<<"\n\n***************************************
*************";
cout<<"\n\n "<<b[i].gettitle();
cout<<"\n\nISBN NO : "<<b[i].getisbn();
cout<<"\n\nAuthor : "<<b[i].getauthor();
cout<<"\n\nPrice : "<<b[i].getprice();
if(b[i].getst()==issued)
cout<<"\n\nStatus :Issued ";

cout<<"\n\n********************************************
*********\n";
continue;
}

else
continue;
}

if(k!=1)
cout<<"\n\nNo Book Available ";

cout.flush();
getch();
system("cls");
menu();

}
//add damage function

void library::adddamage(void)

{
int we,b=1;;
system("cls");
cout<<" \n\nEnter ISBN of Book To Add To Damage List : ";
cin>>we;
if(adamage(we))
{
cout<<"\n\nBook Added To Damaged List : ";
}

else
cout<<"\n! Check Status ";

cout.flush();
getch();
system("cls");
menu();

//add stolen book

void library::addstolen(void)

{
int we,b=1;;
system("cls");
cout<<" \n\nEnter ISBN of Book To Add To Stolen List : ";
cin>>we;
if(astolen(we))
{
cout<<"\n\nBook Added To Stolen List : ";
}

else
cout<<"\n! Check Status ";

cout.flush();
getch();
system("cls");
menu();

//class ending brace

http://www.ravianeducation.blogspot.com
FARHAN: 03008855006

Anda mungkin juga menyukai