[ create a new paste ] login | about

Project: example
Link: http://example.codepad.org/c9Dz9oed    [ raw code | output | fork ]

Python, pasted on Jan 7:
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
#include <stdio.h> 
#include <malloc.h> 
#include <string.h> 
#define MaxSize 100 
typedef struct
{
char isbn[30];//书号
char name[30];//书名
char writer[30];//作者
char producter[30];//出版社
int num;//馆存数量
char price[30];//价格
}ElemType;
typedef struct
{
    ElemType data[MaxSize],data1[MaxSize];
    int length;
}SqList;
void InitList(SqList*&L)//初始化线性表
{
    L=(SqList*)malloc(sizeof(SqList));
    L->length=0;
}
int ListEmpty(SqList *L)
{ 
   return(L->length==0);
}
void AddBook(SqList *&L)//添加图书
{
   int bz=0;
    printf("请输入图书信息!\n");
    printf("书号\t书名\t作者\t出版社\t馆存数量(整型)\t价格\n");
    scanf("%s %s %s %s %d %s",L->data[L->length].isbn,L->data[L->length].name,L->data[L->length].writer,L->data[L->length].producter,&L->data[L->length].num,L->data[L->length].price);
    printf("\n");
for(int i=0;i<L->length;i++)
{
	if(strcmp(L->data[i].isbn,L->data[L->length].isbn)==0)
	{
		L->data[i].num++;
        bz=1;
	    break;
	}
}


if(bz==0)
{
     L->length++;
     printf("添加图书成功!\n");
}
}
void Search_i(SqList*&L)//按书号查询
{
	printf("请输入你想要查找图书的书号:");
	char isbn[50];
	scanf("%s",&isbn);
	int i=0;
	while(i<L->length&&strcmp(L->data[i].isbn,isbn)!=0)
	{
		i++;
	}
	if(i>=L->length)
	{
		printf("图书馆没有此图书!\n");
	}
	else
	{
		printf("书号\t书名\t作者\t出版社\t馆存数量\t价格\n");
		printf("%s\t%s\t%s\t%s\t%d\t%s  元",L->data[i].isbn,L->data[i].name,L->data[i].writer,L->data[i].producter,L->data[i].num,L->data[i].price);
		printf("\n");
	}
}
void Search_n(SqList*&L)//按书名查询
{
	printf("请输入你想查找图书的书名:");
	char name[50];
	scanf("%s",&name);
	int i=0,b=0;
	for(i;i!=L->length;i++)
	{
		if(strcmp(L->data[i].name,name)==0)
			b++;
	}
	if(b==0)
	{
		printf("图书馆没有此图书!\n");
	}
	else
	{
		printf("书号\t书名\t作者\t出版社\t馆存数量\t价格\n");
		for(i=0;i!=L->length;i++)
		{
			if(strcmp(L->data[i].name,name)==0)
			{
				printf("%s\t%s\t%s\t%s\t%d\t%s元",L->data[i].isbn,L->data[i].name,L->data[i].writer,L->data[i].producter,L->data[i].num,L->data[i].price);
		        printf("\n");
			}
		}
	}
}
void Search_w(SqList*&L)//按作者查询
{
	printf("请输入你想要查找图书的作者:");
	char writer[50];
	scanf("%s",&writer);
	int i=0,b=0;
	for(i;i!=L->length;i++)
	{
		if(strcmp(L->data[i].writer,writer)==0)
			b++;
	}
	if(b==0)
		{
			printf("图书馆没有此图书!\n");
	}
	else
	{
		printf("%s的作品共有%d本,信息如下:\n",writer,b);
        printf("书号\t书名\t作者\t出版社\t馆存数量\t价格\n");
        for(i=0;i<L->length;i++)
		{
			if(strcmp(L->data[i].writer,writer)==0)
			{
		         printf("%s\t%s\t%s\t%s\t%d\t%s  元",L->data[i].isbn,L->data[i].name,L->data[i].writer,L->data[i].producter,L->data[i].num,L->data[i].price);
		         printf("\n");
			}
		}
	}
}
void Search_p(SqList*&L)//按出版社查询
{
	printf("请输入你想要查找图书的出版社:");
	char producter[50];
	scanf("%s",&producter);
	int i=0,c=0;
	for(i;i!=L->length;i++)
	{
		if(strcmp(L->data[i].producter,producter)==0)
			c++;
	}
	if(c==0)
	{
		printf("图书馆没有此图书!\n");
	}
	else
	{
		printf("%s的作品共有%d本,信息如下:\n",producter,c);
        printf("书号\t书名\t作者\t出版社\t馆存数量\t价格\n");
        for(i=0;i<L->length;i++)
		{
			if(strcmp(L->data[i].producter,producter)==0)
			{
		         printf("%s\t%s\t%s\t%s\t%d\t%s  元",L->data[i].isbn,L->data[i].name,L->data[i].writer,L->data[i].producter,L->data[i].num,L->data[i].price);
		         printf("\n");
			}
		}
	}
}
void Revise_i(SqList*&L)//按书号修改图书
{
	printf("请输入你要修改图书的书号:");
	char isbn[30];
	scanf("%s",&isbn);
	printf("你要修改的图书信息如下:\n");
	int i=0,v=0;
	while(i<L->length&&strcmp(L->data[i].isbn,isbn)!=0)
		i++;
	if(i>=L->length)
		printf("图书馆没有此图书!\n");
else
	{

        printf("书号\t书名\t作者\t出版社\t馆存数量\t价格\n");
        printf("%s\t%s\t%s\t%s\t%d\t%s  元",L->data[i].isbn,L->data[i].name,L->data[i].writer,L->data[i].producter,L->data[i].num,L->data[i].price);
		 printf("\n");
		 printf("请输入图书信息!\n");
         printf("书号\t书名\t作者\t出版社\t馆存数量\t价格\n");
         scanf("%s %s %s %s %d %s",L->data[i].isbn,L->data[i].name,L->data[i].writer,L->data[i].producter,L->data[i].num,L->data[i].price);
		 printf("修改图书信息成功!\n");
}
}
void Revise_n(SqList*&L)//按书名修改图书
{
	printf("请输入你要修改图书的书名:");
	char name[30];
	scanf("%s",&name);
	printf("你要修改的图书信息如下:\n");
	int i=0,a=0;
	for(i;i<L->length;i++)
	{
		if(strcmp(L->data[i].name,name)==0)
			a++;
	}
	if(a==0)
	{
		printf("图书馆没有此图书!:\n");
	}
	else
	{
		char isbn2[30];
		printf("符合条件的图书共有%d本,信息如下:\n",a);
		printf("书号\t书名\t作者\t出版社\t馆存数量\t价格\n");
		for(int o=0;o<L->length;o++)
		{
			if(strcmp(L->data[o].name,name)==0)//书名相同时按书号删除
				printf("%s\t%s\t%s\t%s\t%d\t%s元",L->data[o].isbn,L->data[o].name,L->data[o].writer,L->data[o].producter,L->data[o].num,L->data[o].price);
                printf("\n");
		}
		printf("请输入你想要修改的书籍的书号:");
		scanf("%d",&isbn2);
		int t=0,e=0;
		for(t;t<L->length;t++)
		{
			if(strcmp(L->data[t].isbn,isbn2)==0)
			{
				e=t;
			}
		}
		printf("书号\t书名\t作者\t出版社\t馆存数量\t价格\n");
        printf("%s\t%s\t%s\t%s\t%d\t%s元",L->data[e].isbn,L->data[e].name,L->data[e].writer,L->data[e].producter,L->data[e].num,L->data[e].price);
        for(t=0;t<L->length;t++)//判断修改后的书籍,是否有相同书籍已存在于图书馆内
		{
			if(strcmp(L->data[t].isbn,L->data[i].isbn)==0)
			{
				L->data[t].num++;
				L->length--;
			}
		}
		printf("\n");
		printf("修改图书信息成功!\n");
	}
}
void Delete_i(SqList*&L)//按书号删除图书
{
    printf("请输入你要删除图书的序号:\n");
	char isbn[30];
	scanf("%s",&isbn);
    int i =0;
	while(i<L->length&&strcmp(L->data[i].isbn,isbn)!=0)
	i++;
	if(i>=L->length)
	printf("图书馆没有此图书!\n");
	else{
		int j;
		printf("isbn: %s的图书%s已成功删除!\n",L->data[i].isbn,L->data[i].name);
        for(j=i;j<L->length-1;j++)
			L->data[j]=L->data[j+1];
		L->length--;
	}
}
void Delete_n(SqList*&L)//按书名删除图书
{
	printf("请输入你要删除图书的书名:\n");
	char name[30];
	scanf("%s",&name);
	int i =0,a=0,e=0;
	for(i;i<L->length;i++)
	{
		if(strcmp(L->data[i].name,name)==0)
			a++;
	}
	if(a==0)
		printf("图书馆没有此图书!\n");
	else
	{
		char isbn2[30];//书名相同时按书号删除
		printf("符合条件的图书共有%d本,信息如下:\n",a);
		printf("书号\t书名\t作者\t出版社\t馆存数量\t价格\n");
	    for(int o=0;o<L->length;o++)
		{
			if(strcmp(L->data[o].name,name)==0)
                printf("%s\t%s\t%s\t%s\t%d\t%s  元",L->data[o].isbn,L->data[o].name,L->data[o].writer,L->data[o].producter,L->data[o].num,L->data[o].price);             
			    printf("\n");
		}
		printf("请输入你想要删除书籍的书号:");
		scanf("%d",&isbn2);
		int t=0;
		for(t;t<L->length;t++)
		{
			if(strcmp(L->data[t].isbn,isbn2)==0)
				e=t;
		}
		int j;
		printf("isbn:%s的图书%s已成功删除!\n",L->data[e].isbn,L->data[e].name);
		for(j=e;j<L->length-1;j++)
			L->data[j]=L->data[j+1];
		L->length--;
	}
}
void BorrowBook(SqList*&L)//图书借阅
{
	printf("请输入你想要借的图书的书号:");
	char isbn[30];
	scanf("%s",&isbn);
	int i=0;
	while(i<L->length&&strcmp(L->data[i].isbn,isbn)!=0)
	{
		i++;
	}
	if(i>=L->length)
	{
		printf("图书馆内没有此图书!\n");
	}
	else
	{
		if(L->data[i].num==0)
		{
			printf("该图书已经全部借出!\n");
		}
		else
		{
			printf("图书%s借阅成功!\n",L->data[i].name);
			L->data[i].num--;
		}
	}
}
void BackBook(SqList*&L)//图书归还
{
	printf("请输入你想要归还的图书的书号:");
	char isbn[30];
	scanf("%s",&isbn);
	int i=0;
	while(i<L->length&&strcmp(L->data[i].isbn,isbn)!=0)
	{
		i++;
	}
	if(i>=L->length)
	{
		printf("这本图书不是我们图书馆所藏!\n");
	}
	else
	{
		printf("图书%s归还成功!\n",L->data[i].name);
		L->data[i].num++;
	}
}
void Sort_i(SqList*&L)//按书号排序
{
	for(int i=0;i<L->length-1;i++)
	{
	    for(int j=0;j<L->length-1-i;j++)
	   {
		    if(strcmp(L->data[j].isbn,L->data[j+1].isbn)>0)
			{

                strcpy(L->data1[j].isbn,L->data[j].isbn);
			    strcpy(L->data[j].isbn,L->data[j+1].isbn);
                strcpy(L->data[j+1].isbn,L->data1[j].isbn);
		        strcpy(L->data1[j].name,L->data[j].name);
			    strcpy(L->data[j].name,L->data[j+1].name);
			    strcpy(L->data[j+1].name,L->data1[j].name);
			    strcpy(L->data1[j].writer,L->data[j].writer);
                strcpy(L->data[j].writer,L->data[j+1].writer); 
                strcpy(L->data[j+1].writer,L->data1[j].writer); 
                strcpy(L->data1[j].producter,L->data[j].producter); 
                strcpy(L->data[j].producter,L->data[j+1].producter); 
                strcpy(L->data[j+1].producter,L->data1[j].producter); 
                L->data1[j].num=L->data[j].num; 
                L->data[j].num=L->data[j+1].num; 
                L->data[j+1].num=L->data1[j].num; 
                strcpy(L->data1[j].price,L->data[j].price); 
                strcpy(L->data[j].price,L->data[j+1].price); 
                strcpy(L->data[j+1].price,L->data1[j].price);
			}
		}
	}
	printf("书号\t书名\t作者\t出版社\t馆存数量\t价格\n");
    for(int i=0;i<L->length;i++)
	{
        printf("%s\t%s\t%s\t%s\t%d\t%s  元",L->data[i].isbn,L->data[i].name,L->data[i].writer,L->data[i].producter,L->data[i].num,L->data[i].price);
        printf("\n");
	}
}

void Sort_n(SqList*&L)//按书名排序
{
	for(int i=0;i<L->length-1;i++)
	{
		for(int j=0;j<L->length-1-i;j++)
		{
			if(strcmp(L->data[j].writer,L->data[j+1].writer)>0)
			{
                strcpy(L->data1[j].isbn,L->data[j].isbn);
		    	strcpy(L->data[j].isbn,L->data[j+1].isbn);
                strcpy(L->data[j+1].isbn,L->data1[j].isbn);
		        strcpy(L->data1[j].name,L->data[j].name);
		    	strcpy(L->data[j].name,L->data[j+1].name);
		    	strcpy(L->data[j+1].name,L->data1[j].name);
		    	strcpy(L->data1[j].writer,L->data[j].writer);
                strcpy(L->data[j].writer,L->data[j+1].writer); 
                strcpy(L->data[j+1].writer,L->data1[j].writer); 
                strcpy(L->data1[j].producter,L->data[j].producter); 
                strcpy(L->data[j].producter,L->data[j+1].producter); 
                strcpy(L->data[j+1].producter,L->data1[j].producter); 
                L->data1[j].num=L->data[j].num; 
                L->data[j].num=L->data[j+1].num; 
                L->data[j+1].num=L->data1[j].num; 
                strcpy(L->data1[j].price,L->data[j].price); 
                strcpy(L->data[j].price,L->data[j+1].price); 
                strcpy(L->data[j+1].price,L->data1[j].price);
			}
			for(int t=0;t<L->length-1;t++)
			{
				if(strcmp(L->data[t].writer,L->data[t+1].writer)==0)
				{
					if(strcmp(L->data[t].isbn,L->data[t+1].isbn)>0)
					{
						strcpy(L->data1[t].isbn,L->data[t].isbn);
		    	strcpy(L->data[t].isbn,L->data[t+1].isbn);
                strcpy(L->data[t+1].isbn,L->data1[t].isbn);
		        strcpy(L->data1[t].name,L->data[t].name);
		    	strcpy(L->data[t].name,L->data[t+1].name);
		    	strcpy(L->data[t+1].name,L->data1[t].name);
		    	strcpy(L->data1[t].writer,L->data[t].writer);
                strcpy(L->data[t].writer,L->data[t+1].writer); 
                strcpy(L->data[t+1].writer,L->data1[t].writer); 
                strcpy(L->data1[t].producter,L->data[t].producter); 
                strcpy(L->data[t].producter,L->data[t+1].producter); 
                strcpy(L->data[t+1].producter,L->data1[t].producter); 
                L->data1[t].num=L->data[t].num; 
                L->data[t].num=L->data[t+1].num; 
                L->data[t+1].num=L->data1[t].num; 
                strcpy(L->data1[t].price,L->data[t].price); 
                strcpy(L->data[t].price,L->data[t+1].price); 
                strcpy(L->data[t+1].price,L->data1[t].price);
					}
				}
			}
		}
	}
printf("书号\t书名\t作者\t出版社\t馆存数量\t价格\n");
for(int i=0;i<L->length;i++)
{
    printf("%s\t%s\t%s\t%s\t%d\t%s  元",L->data[i].isbn,L->data[i].name,L->data[i].writer,L->data[i].producter,L->data[i].num,L->data[i].price);
    printf("\n");
}
}
int menu(SqList*&L);
void menu1(SqList*&L)
{
	printf("\n\t--------------------------\n");
	printf("\t         1.按书名进行查询           \n\n"); 
    printf("\t         2.按作者名进行查询         \n\n");
	printf("\t         3.按出版社进行查询         \n\n");
	printf("\t         0.返回主菜单               \n");
	printf("\n\t--------------------------\n");
	printf("请选择功能(0~3):");
	int choice;
	scanf("%d",&choice);
	switch(choice)
	{
case 1:Search_n(L);system("pause");system("cls");break;
case 2:Search_w(L);system("pause");system("cls");break;
case 3:Search_p(L);system("pause");system("cls");break;
case 0:system("cls");menu(L);break;
default:printf("输入有误,请重新输入!");system("pause");system("cls");
	}
	menu1(L);
}
void menu2(SqList*&L)
{
	printf("\n\t--------------------------\n");
	printf("\t         1.按书号进行图书的修改           \n\n"); 
    printf("\t         2.按书名进行图书的修改        \n\n");
	printf("\t         0.返回主菜单               \n");
	printf("\n\t--------------------------\n");
	printf("请选择功能(0~2):");
	int choice;
	scanf("%d",&choice);
	switch(choice)
	{
case 1:Revise_i(L);system("pause");system("cls");break;
case 2:Revise_n(L);system("pause");system("cls");break;
case 0:system("cls");menu(L);break;
default:printf("输入有误,请重新输入!");system("pause");system("cls");
	}
	menu2(L);
}
void menu3(SqList*&L)
{
	printf("\n\t--------------------------\n");
	printf("\t         1.按书号进行图书的删除           \n\n"); 
    printf("\t         2.按书名进行图书的删除         \n\n");
    printf("\t         0.返回主菜单               \n");
	printf("\n\t--------------------------\n");
	printf("请选择功能(0~2):");
	int choice;
	scanf("%d",&choice);
	switch(choice)
	{
case 1:Delete_i(L);system("pause");system("cls");break;
case 2:Delete_n(L);system("pause");system("cls");break;
case 0:system("cls");menu(L);break;
default:printf("输入有误,请重新输入!");system("pause");system("cls");
	}
	menu3(L);
}
void menu4(SqList*&L)
{
	printf("\n\t--------------------------\n");
	printf("\t         1.按书号进行图书的排序          \n\n"); 
    printf("\t         2.按书名进行图书的排序         \n\n");
    printf("\t         0.返回主菜单               \n");
	printf("\n\t--------------------------\n");
	printf("请选择功能(0~2):");
	int choice;
	scanf("%d",&choice);
	switch(choice)
	{
case 1:Sort_i(L);system("pause");system("cls");break;
case 2:Sort_n(L);system("pause");system("cls");break;
case 0:system("cls");menu(L);break;
default:printf("输入有误,请重新输入!");system("pause");system("cls");
	}
	menu4(L);
}
void menu5(SqList*&L)
{
	printf("\n\t--------------------------\n");
	printf("\t         1.图书借阅           \n\n"); 
    printf("\t         2.图书归还         \n\n");
    printf("\t         0.返回主菜单               \n");
	printf("\n\t--------------------------\n");
	printf("请选择功能(0~2):");
	int choice;
	scanf("%d",&choice);
	switch(choice)
	{
case 1:Delete_i(L);system("pause");system("cls");break;
case 2:Delete_n(L);system("pause");system("cls");break;
case 0:system("cls");menu(L);break;
default:printf("输入有误,请重新输入!");system("pause");system("cls");
	}
	menu5(L);
}
int menu(SqList*&L)
{system("cls");
	printf("\n\t\t       **简易图书管理系统**       ");
	printf("\n\t--------------------------\n");
	printf("\t|         1.图书信息录入           |\n\n"); 
    printf("\t|         2.图书信息查询           |\n\n");
    printf("\t|         3.图书信息排序           |\n\n");
	printf("\t|         4.图书信息修改           |\n\n"); 
    printf("\t|         5.图书信息删除           |\n\n");
    printf("\t|         6.图书借阅归还           |\n\n");
	printf("\t|         0.退出                   |\n\n");
	printf("\n\t--------------------------\n");
	printf("请选择功能(0~6):");
	int choice;
	scanf("%d",&choice);
	switch(choice)
	{
case 1:AddBook(L);system("pause");break;
case 2:system("cls");menu1(L);break;
case 3:system("cls");menu4(L);break;
case 4:system("cls");menu2(L);break;
case 5:system("cls");menu3(L);break;
case 6:system("cls");menu5(L);break;
case 0:printf("您已成功退出!");return 0;break;
default:printf("输入有误,请重新输入!");system("pause");system("cls");
	}
	return 1;
}
void main()
{
	SqList*L;
	InitList(L);
	while(menu(L));
}


Output:
1
2
3
4
  Line 5
    typedef struct
                 ^
SyntaxError: invalid syntax


Create a new paste based on this one


Comments: