//数据结构关于课程设计--------图书馆管理系统的设计 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> #define _OJ_ typedef struct Book { char title[30]; //ISBN编号书籍的标准编号 char ISBN[30]; char author[30]; //作者 char publisher[30]; //出版社 char pub_time[30]; //出版时间 char price[10]; //书的价格 int count; //书的数量 struct Book *next; } Book, *Linkbook; typedef struct Student { int amount; //学生已借书的数量 char stu_num[8]; //学生的学号 char name[20]; //学生的姓名 char card_num[8]; //借书证的编号 Linkbook stu_book[6]; //学生所借图书信息 struct Student *next; } Stu, *Linkstu; //判断输入的字符是否正确 void input_str(const char *str, char *str1, int number) { char tmp[200]; printf("%s", str); do { scanf("%s", tmp); if(strlen(tmp) > number) { printf("您输入的信息错误请重新输入:\n"); } } while(strlen(tmp) > number); strcpy(str1, tmp); } // 判断输入的整型数字是否正确 int input_float(const char *str, char *str1, int number) { int i, len, flag; char num[200]; printf("%s", str); for ( ; ;) { flag = 0; scanf("%s", num); len = strlen(num); if(len > number) { printf("\n您输入的信息错误请重新输入:"); continue; } for (i = 0; i < len; i++) { if((num[i] < ‘0‘ || num[i] > ‘9‘) && num[i] != ‘.‘) { printf("\n您输入的不是浮点数字请重新输入:"); flag = 1; break; } } if(flag == 1) continue; else break; } strcpy(str1, num); return 1; } //------------------------------------- 判断输入的浮点型是否正确 int input_int(const char *str, int number) { int i, len, flag; char num[200]; printf("%s", str); for ( ; ;) { flag = 0; scanf("%s", num); len = strlen(num); if(len > number) { printf("\n您输入的数字超限请重新输入:"); continue; } for (i = 0; i < len; i++) { if((num[i] < ‘0‘ || num[i] > ‘9‘)) { printf("\n您输入的非数字或不是整型数字请重新输入:"); flag = 1; break; } } if(flag == 1) continue; else break; } int n = atoi(num); return n; } //-----------------------------------------------判断输入的ISBN是否正确 void input_ISBN(const char *str, char *str1) //International Standard Book Number { int i, flag; char tmp[200]; //x-xxx-xxxxx-x printf("%s", str); for(;;) { flag = 0; scanf("%s", tmp); if(strlen(tmp) != 13 || tmp[1] != ‘-‘ || tmp[5] != ‘-‘ || tmp[11] != ‘-‘) { printf("您输入的格式错误请重新输入格式为:x-xxx-xxxxx-x\n"); continue; } for( i = 0; i < strlen(tmp); i++) { if((tmp[i] < ‘0‘ || tmp[i] > ‘9‘) && tmp[i] != ‘-‘){ printf("您输入的含非数字请重新输入格式为:x-xxx-xxxxx-x"); flag = 1; continue; } } if(flag == 1) continue; else break; } strcpy(str1, tmp); } //----------------------------------------------------------------------------- //书籍收编入库 Linkbook Creat_book(void) { char ch; Linkbook L, head, P; head = (Linkbook) malloc (sizeof(Book)); if(!head) { printf("申请空间失败!!!\n"); exit(0); } L = head; printf("创建图书:\n"); for (;;) { P = (Linkbook) malloc (sizeof(Book)); P->next = NULL; input_str("请输图书名称:", P->title, 30); input_str("请输入图书的作者:", P->author, 30); input_str("请输入图书的出版社:", P->publisher, 30); input_str("请输入图书的出版时间:", P->pub_time, 30); input_float("请输入图书的价格:", P->price, 10); P->count = input_int("请输入图书的数量:",5); input_ISBN("请输入图书的ISBN格式为:x-xxx-xxxxx-x:\n", P->ISBN); L->next = P; L = P; printf("请按任意键继续添加图书 或者输入q返回:"); ch = getche(); if (ch == ‘q‘ || ch == ‘Q‘) break; } printf("\n"); return head; } void print_book(Linkbook head) { Linkbook L; L = head->next; printf("打印所有图书信息:"); while (L != NULL) { printf("图书名称:%s\n", L->title); printf("图书作者:%s\n", L->author); printf("图书出版社:%s\n", L->publisher); printf("图书出版时间:%s\n", L->pub_time); printf("图书价格:%s\n", L->price); printf("图书的ISBN:%s\n", L->ISBN); printf("图书数量:%d\n\n\n", L->count); L = L->next; } printf("打印完成!!\n"); } //-------------------------------------------------------------- int main(int argc, char const *argv[]) { #ifndef _OJ_ //ONLINE JUDGE freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif Linkbook Book = NULL; Linkstu Stu = NULL; Book = Creat_book(); printf("booknext%s", Book->next->title); print_book(Book); return 0; }
时间: 2024-10-12 04:35:21