-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram.cpp
290 lines (264 loc) · 4.83 KB
/
program.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
const int SIZE=100;
int count=0;
struct book
{
int bno;
char bname[20];
char author[20];
float price;
int ncopy;
int nissue;
};
book b[SIZE];
void addbook(); //add one book detail
void display(); //display all book detail
void searchno(); //search book with bookno
void searchname(); //search book with bookname
void display(book); //display detail of one book
void modifybook(); //modify book detail
void deletebook(); //delete book detail
void main()
{
int choice;
do{
clrscr();
cout<<"\n\n\t\tMain Menu";
cout<<"\n1.Add book details";
cout<<"\n2.Display all books";
cout<<"\n3.Search book by bookno";
cout<<"\n4.Search book by bookname";
cout<<"\n5.Modify book details";
cout<<"\n6.Delete book details";
cout<<"\n7.Exit";
cout<<"\n\nEnter your choice:";
cin>>choice;
switch(choice)
{
case 1:
clrscr();
addbook();
break;
case 2:
clrscr();
if(count==0)
{
cout<<"\nNo book exists";
cout<<"\nPlease run option one first";
break;
}
display();
break;
case 3:
clrscr();
if(count==0)
{
cout<<"\nNo book exists";
cout<<"\nPlease run option one first";
break;
}
searchno();
break;
case 4:
clrscr();
if(count==0)
{
cout<<"\nNo book exists";
cout<<"\nPlease run option one first";
break;
}
searchname();
break;
case 5:
clrscr();
if(count==0)
{
cout<<"\nNo book exists";
cout<<"\nPlease run option one first";
break;
}
modifybook();
break;
case 6:
clrscr();
if(count==0)
{
cout<<"\nNo book exists";
cout<<"\nPlease run option one first";
break;
}
deletebook();
break;
case 7:
cout<<"\nExit from program...Bye";
break;
default:
cout<<"\n\nInvalid choice";
}
cout<<"\n\nPress any key to continue...";
getch();
}while(choice!=7);
}
void addbook()
{
cout<<"Enter book details\n";
cout<<"Bookno:";
cin>>b[count].bno;
cout<<"Bookname:";
cin>>b[count].bname;
cout<<"Author";
gets(b[count].author);
cout<<"Price:";
cin>>b[count].price;
cout<<"No. of copies:";
cin>>b[count].ncopy;
bcount.nissue=0;
count++;
}
void display()
{
int i;
for(i=0;i<count;i++)
{
cout<<"\nBookno :"<<b[i].bno;
cout<<"\nBookname :"<<b[i].bname;
cout<<"\nAuthor :"<<b[i].author;
cout<<"\nPrice :"<<b[i].price;
cout<<"\nNo of copy :"<<b[i].ncopy;
cout<<"\nNo of issue :"<<b[i].nissue;
}cout<<"\n----------------------------------------------";
}
void searchno()
{
int no,i,flag=0;
cout<<"Enter book number to search:";
cin>>no;
for(i=0;i<count;i++)
{
if(b[i].bno==no)
{
cout<<"\nBook found";
display(b[i]);
flag=1;
break;
}
}
if(flag==0)
{
cout<<"\n\nInvalid bookno";
}
}
void searchname()
{
char name[20];
int i,flag=0;
cout<<"Enter book name to search:";
gets(name);
for(i=0;i<count;i++)
{
if(strcmp(b[i].bname,name)==0)
{
cout<<"\nBook found";
display(b[i]);
flag=1;
break;
}
}
if(!flag)
{
cout<<"\n\nInvalid bookno";
}
}
void display(book b1)
{
cout<<"-----------------------------\n";
cout<<"Bookno:";
cout<<b[count].bno;
cout<<"\nBookname:";
cout<<b[count].bname;
cout<<"\nAuthor";
cout<<b[count].author;
cout<<"\nPrice:";
cout<<b[count].price;
cout<<"No. of copies:";
cout<<b[count].ncopy;
cout<<"\n-----------------------------\n";
}
void modifybook()
{
int no,i,flag=0;
char ch;
cout<<"Enter bookno to modify:";
cin>>no;
for(i=0;i<count;i++)
{
if(b[i].bno==no)
{
cout<<"\nBook found";
flag=1;
cout<<"\nCurrent Details of book:\n";
display(b[i]);
cout<<"\nDo you want to modify(y/n):";
cin>>ch;
if(ch=="y"||ch=="Y")
{
cout<<"Enter book details\n";
cout<<"Bookno:";
cin>>b[count].bno;
cout<<"Bookname:";
cin>>b[count].bname;
cout<<"Author";
gets(b[count].author);
cout<<"Price:";
cin>>b[count].price;
cout<<"No. of copies:";
cin>>b[count].ncopy;
cout<<"\nRecord is modified";
cout<<"\n\nModified Record";
display(b[i]);
}
break;
}
}
if(flag==0)
{
cout<<"\nInvalid book no";
}
}
void deletebook()
{
int no,i,flag=0;
char ch;
cout<<"Enter book no to delete";
cin>>no;
for(i=0;i<count;i++)
{
if(b[i].bno==no)
{
cout<<"\nBook found";
cout<<"\nBook details\n";
display(b[i]);
flag=1;
cout<<"\nAre you sure to delete(y/n)";
cin>>ch;
if(ch=="y"||ch=="Y")
{
for(int j=i;j<count;j++)
{
b[j]=b[j+1];
}
count--;
cout<<"\n\nRecord Deleted Sucessfully";
}
break;
}
}
if(!flag)
{
cout<<"\nInvalid book no";
}
}
e