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
|
#include<iostream>
#include<string>
using namespace std;
class BOOK
{
private :
string nameofpublisher ;
char status ;
string nameofbook;
int cost ;
int noofcopies ;
string nameofauthor ;
public:
string get_nameofpublisher() { return nameofpublisher; }
void set_nameofpublisher(const string & name) { nameofpublisher = name;}
char get_status() { return status; }
void set_status( char ch) { status = ch; }
string get_nameofbook() { return nameofbook; }
void set_nameofbook(const string & name) { nameofbook = name; }
int get_cost() { return cost; }
void set_cost( int c) { cost = c; }
int get_noofcopies() { return noofcopies; }
void set_noofcopies( int noof) { noofcopies = noof; }
string get_nameofauthor() { return nameofauthor; }
void set_nameofauthor(const string & name) { nameofauthor = name;}
void readbooks()
{
string tmp;
cout<<"\nEnter The The Name of The Book : " ;
getline(cin, tmp) ;
set_nameofbook(tmp);
cout<<"\nEnter The Cost Of The Book : " ;
getline(cin, tmp) ;
set_cost( stoi(tmp));
cout<<"\nEnter The Name Of The Author :" ;
getline(cin, tmp) ;
set_nameofauthor( tmp);
cout<<"\nEnter The Name Of Publisher : " ;
getline(cin, tmp) ;
set_nameofauthor( tmp);
cout<<"\nEnter The Status Of The Book ( I - Issued / A - Available ) : " ;
getline(cin, tmp);
set_status( tmp[0]);
cout<<"\nEnter The Number Of Copies Available : " ;
getline(cin, tmp);
set_noofcopies(stoi(tmp));
}
void displaybooks()
{
cout<<"\nName Of The Book : " << nameofbook ;
cout<<"\nAuthor Of The Book : " << nameofauthor ;
cout<<"\nPublisher Of The Books " << nameofpublisher ;
cout<<"\nStatus Of The Book : " <<status ;
cout<<"\nCost Of The Book : " <<cost ;
cout<<"\nThe Number Of Copies Available : " << noofcopies ;
}
};
int main()
{
BOOK stock[10] ;
int i ;
for ( i = 0 ; i < 2 ; ++i)
{
cout<<"\n\nEnter The Information For Book " << i + 1 ;
stock[i].readbooks();
}
system("cls");
for (i = 0 ; i < 2; ++i)
{
cout<<"\n\nBook " << i + 1 ;
stock[i].displaybooks();
}
int choice, totalcost, reqcopies;
string searchbookname, searchauthorname;
cout<<"n\n\nSearch Menu\n1.Search Via Book Name\n2.Search Via Author Name " ;
string tmp;
getline(cin, tmp);
choice = stoi(tmp);
switch (choice)
{
case 1 :
cout<<"\nEnter The Name Of The Book You Want To Buy : " ;
getline( cin, searchbookname) ;
cout<<"\nEnter The Number Of Copies You Need : " ;
getline(cin, tmp);
reqcopies = stoi(tmp);
for (i = 0 ; i < 2 ; ++i)
{
if ((stock[i].get_nameofbook() == searchbookname)
&& (stock[i].get_status() == 'A' || stock[i].get_status() == 'a')
&& (stock[i].get_noofcopies() >= reqcopies))
{
cout<<"\nBOOK FOUNDDDD!!!!!" ;
cout<<"\nSTOCK AVAILABLE \t Total Cost = " << stock[i].get_cost() * reqcopies
<<"\nThanks For Visiting COME AGAIN!" ;
}
else ;
}
break ;
case 2 :
cout<<"\nEnter The Name Of The Author Whose Books You Want Search/BUY : " ;
getline( cin, searchauthorname);
cout<<"\nBooks By The Searched Author : " ;
bool book_found = false;
for (i = 0 ; i < 2 ; ++i)
{
if( (stock[i].get_nameofauthor() == searchauthorname) )
{
book_found = true;
cout<<"\n"<<stock[i].get_nameofbook() ;
}
}
if (book_found == false) cout<<"\nNo Books Found By The Author!!!!!!" ;
}
return 0 ;
}
|