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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
#include <iostream>
#include <string>
using namespace std;
int size = 0;
class Book
{
private:
string ISBN;
string title;
string author;
int quantity;
public:
Book(string serial, string tit, string auth, int qu)
{
ISBN = serial;
title = tit;
author = auth;
quantity = qu;
}
Book()
{}
void set_ISBN(string serial)
{
ISBN = serial;
}
void set_title(string tit)
{
title = tit;
}
void set_author(string auth)
{
author = auth;
}
void set_quanitiy(int qu)
{
quantity = qu;
}
string get_ISBN()
{
return ISBN;
}
string get_title()
{
return title;
}
string get_author()
{
return author;
}
int get_quantity()
{
return quantity;
}
void print_book_info()
{
cout << "ISBN : " << ISBN << endl;
cout << "Title : " << title << endl;
cout << "Author : " << author << endl;
cout << "Quantity : " << quantity << endl;
}
~Book()
{}
};
void add_anew_book(Book *b, string IS, string title, string author, int qua)
{
int i = 0;
int q1;
q1 = (b+i)->get_quantity();
if (IS == b->get_ISBN())
{
cout << "The book is already in stock, we're gonna add one to it's quantity ! " << endl;
q1++;
}
else
size++;
(b+i)->set_ISBN(IS);
(b+i)->set_author(author);
(b+i)->set_title(title);
(b+i)->set_quanitiy(qua);
i++;
}
bool borrow_abook(Book *b, string IS)
{
int x;
if (b->get_ISBN() == IS)
{
x = b->get_quantity();
x--;
return true;
}
else return false;
}
bool return_abook(Book *b, string IS)
{
int x;
if (b->get_ISBN() == IS)
{
x = b->get_quantity();
x++;
return true;
}
else return false;
}
bool search_for_abook(Book *b, string IS)
{
if (b->get_ISBN() == IS)
{
return true;
}
else return false;
}
void print_all_books(Book *b)
{
for (int i = 0; i < size; i++)
{
(b + i)->print_book_info();
}
}
void main()
{
Book *b;
b = new Book [size];
char c;
cout << "Welcome to our BookStore, please choose one of the following : " << endl;
cout << "1. To add a new book, please enter 'A': " << endl;
cout << "2. To borrow a book, please enter 'B': " << endl;
cout << "3. To return a borrowed book, please enter 'R': " << endl;
cout << "4. To search for a book, please enter 'S': " << endl;
cout << "5. to print a book's info, please enter 'P' :" << endl;
cout << "6. to print the info of all the book avialable in stock, please enter 'T' :" << endl;
cout << "7. To exit, please enter 'E' : " << endl;
cin >> c;
string IS , title , author;
int qua;
bool bor;
bool ret;
bool ser;
while (c != 'E')
{
switch (c)
{
case 'A': cout << "Enter the book ISBN to check if the book is already in stock or not to add it : " << endl;
cin >> IS;
b->set_ISBN(IS);
cout << "Enter the book's title , author , quantity : " << endl;
cin >> title >> author >> qua;
b->set_title(title);
b->set_author(author);
b->set_quanitiy(qua);
add_anew_book(b, IS, title , author, qua);break;
case'B': cout << "Please enter the book's ISBN : " << endl;
cin >> IS;
bor = borrow_abook(b, IS);
if (bor)
{
cout << "Enjoy reading the book, and please return the given book in a week." << endl;
}
else cout << "Sorry there is no avialabe copy right now, please check later ." << endl; break;
case'R':cout << "Please enter the book's ISBN : " << endl;
cin >> IS;
ret = return_abook(b, IS);
if (ret)
{
cout << "Thanks for returning the book in time, hope you enjoyed it." << endl;
}
else cout << "Sorry, this book doesn't belong to our BookStore." << endl; break;
case'S':cout << "Please enter the book's ISBN : " << endl;
cin >> IS;
ser = search_for_abook(b, IS);
if (ser)
{
cout << "Book was found ." << endl;
}
else cout << "Book was not found" << endl;
break;
case'P':cout << "Please enter the book's position to print it's info :" << endl;
int i;
cin >> i;
(b+i)->print_book_info();
break;
case'T':print_all_books(b);
break;
}
cout << "1. To add a new book, please enter 'A': " << endl;
cout << "2. To borrow a book, please enter 'B': " << endl;
cout << "3. To return a borrowed book, please enter 'R': " << endl;
cout << "4. To search for a book, please enter 'S': " << endl;
cout << "5. to print a book's info, please enter 'P' :" << endl;
cout << "6. to print the info of all the book available in stock, please enter 'T' :" << endl;
cout << "7. To exit, please enter 'E' : " << endl;
cin >> c;
}
system("pause");
}
|