1
+ #include < iostream.h>
2
+ #include < conio.h>
3
+ #include < stdio.h>
4
+ #include < string.h>
5
+ #include < stdlib.h>
6
+ class book {
7
+ char publisher[20 ];
8
+ float price;
9
+ int stock;
10
+ char title[20 ];
11
+ char author[20 ];
12
+ public: int find (char [],char []);
13
+ void show_book ();
14
+ void stock_check (int );
15
+ void add_book ();
16
+ book ();
17
+
18
+
19
+
20
+ };
21
+ book::book (){
22
+ char *author=new char [50 ];
23
+ char *title=new char [50 ];
24
+ char *publisher=new char [50 ];
25
+ price=0 ;
26
+ stock=0 ;
27
+
28
+
29
+ }
30
+ void book::add_book (){
31
+ cout<<endl<<" ADD BOOK DETAILS : " <<endl;
32
+ cout<<" Enter the title : " ;
33
+ gets (title);
34
+ cout<<endl<<" Enter the author : " ;
35
+ gets (author);
36
+ cout<<endl<<" Enter the publisher : " ;
37
+ gets (publisher);
38
+ cout<<endl<<" Enter the price : " ;
39
+ cin>>price;
40
+ cout<<endl<<" Enter the stock : " ;
41
+ cin>>stock;
42
+ cout<<endl;
43
+ }
44
+
45
+ int book::find (char bt[],char ba[]){
46
+ if (strcmp (title,bt)&&strcmp (author,ba))
47
+ {
48
+ return 0 ;
49
+
50
+ }
51
+ else
52
+ {
53
+ return 1 ;
54
+
55
+ }
56
+
57
+ }
58
+ void book::show_book (){
59
+
60
+ cout<<endl<<" BOOK DETAILS " <<endl<<endl<<" Book Title : " <<title;
61
+ cout<<endl<<" Author : " <<author<<endl<<" Publisher : " <<publisher;
62
+ cout<<endl<<" Price : " <<price<<endl<<" Books available : " <<stock<<endl;
63
+ cout<<endl;
64
+
65
+ }
66
+ void book::stock_check (int copy){
67
+ if (stock>=copy)
68
+ {
69
+ cout<<endl<<" Books are ready " <<endl;
70
+ cout<<" Cost of " <<copy<<" books are " <<(price*copy)<<endl;
71
+ }
72
+ else
73
+ {
74
+ cout<<endl<<" The copies are not available" <<endl;
75
+ }
76
+ }
77
+
78
+ void main ()
79
+ {
80
+ int ch,n=0 ,i,flag=0 ,b_id=0 ,num,opt;
81
+ book b[100 ];
82
+ char b_name[50 ],b_title[50 ],b_author[50 ];
83
+ clrscr ();
84
+ do
85
+ {
86
+ cout<<" \n\n\t\t ********BOOK SHOP*********" ;
87
+ cout<<" \n 1.Add book\n 2.Find book\n 3.Buy Book" ;
88
+ cout<<" \n 4.Exit\n Select option : " ;
89
+ cin>>ch;
90
+ switch (ch)
91
+ {
92
+ case 1 :cout<<" \n How many books to add : " ;
93
+ cin>>n;
94
+ for (i=0 ;i<n;i++)
95
+ b[i].add_book ();
96
+ break ;
97
+ /* case 87:for(i=0;i<n;i++)
98
+ {
99
+ b[i].show_book();
100
+ cout<<"\n************\n";
101
+
102
+ }
103
+ break; */
104
+ case 2 :cout<<" \n Enter the book title : " ;
105
+ gets (b_title);
106
+ cout<<" \n Enter the author : " ;
107
+ gets (b_author);
108
+ for (i=0 ;i<n;i++)
109
+ {
110
+ if (b[i].find (b_title,b_author))
111
+ {
112
+ flag=1 ;
113
+ b[i].show_book ();
114
+ b_id=i;
115
+ cout<<" The book is found ...... Book id is : " <<b_id<<" .Use this to buy book \n " ;
116
+
117
+ }
118
+
119
+ }
120
+ break ;
121
+ case 3 :cout<<" \n Buy Book " ;
122
+ cout<<" \n Enter Book id : " ;
123
+ cin>>opt;
124
+ if (b_id<=n)
125
+ {
126
+ if (flag==1 )
127
+ {
128
+ cout<<" \n Book is available \n Enter the no of copies : " ;
129
+ cin>>num;
130
+ b[b_id].stock_check (num);
131
+ flag=0 ;
132
+ }
133
+ else
134
+ {
135
+ cout<<" \n Entered copies not available " ;
136
+ }
137
+ }
138
+ break ;
139
+ case 4 :cout<<" \n Thanks for using " ;
140
+ break ;
141
+ default :cout<<" \Invalid option " ;
142
+ }
143
+ }while (ch!=4 );
144
+ getch ();
145
+
146
+ }
0 commit comments