-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBookInventry.cpp
103 lines (98 loc) · 2.6 KB
/
BookInventry.cpp
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
#include <iostream>
#include <string>
using namespace std;
class books
{
private:
string title, author, publisher;
int quantity, price;
public:
books()
{
cout << "\nEnter Book Title : ";
cin >> title;
cout << "Enter Book Author : ";
cin >> author;
cout << "Enter Book Publisher : ";
cin >> publisher;
cout << "Enter Book Quantity : ";
cin >> quantity;
cout << "Enter the price of the book : ";
cin >> price;
}
bool chktitauth(string tit, string auth)
{
if (tit == title && auth == author)
{
return true;
}
return false;
}
void setquantity(int a)
{
quantity = quantity - a;
}
int getquantity()
{
return quantity;
}
int getprice()
{
return price;
}
};
int main()
{
int n;
cout << "Enter number of Entries : ";
cin >> n;
books ob[n];
string tit, auth;
while (1)
{
cout << "\n\nEnter title of the book : ";
cin >> tit;
cout << "Enter title of the Author : ";
cin >> auth;
for (int i = 0; i < n; i++)
{
if (ob[i].chktitauth(tit, auth))
{
int qnty;
cout << "Book is available " << endl;
cout << "Enter the quantity you want to buy: ";
cin >> qnty;
if (qnty > ob[i].getquantity())
{
int remain = qnty - ob[i].getquantity();
cout << "Sorry! The required quantity is not available." << endl;
cout << "Only " << remain << " is available " << endl;
cout << "Do you want to buy " << remain << " item ?Y/N : ";
char c;
cin >> c;
if (c == 'Y' || c == 'y')
{
cout << "Price of " << remain << " Book is : " << remain * ob[i].getprice() << endl;
ob[i].setquantity(qnty);
break;
}
else
{
break;
}
}
else
{
cout << "Required number of books is available ," << endl
<< "Price of Books : " << qnty * ob[i].getprice() << endl;
ob[i].setquantity(qnty);
}
}
else
{
cout << "Book is unavailable ." << endl;
}
}
}
return 0;
}