700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > c语言课设(图书管理系统)

c语言课设(图书管理系统)

时间:2019-02-05 05:33:13

相关推荐

c语言课设(图书管理系统)

任务要求:

建立一个图书馆管理系统,可以处理以下对象:(1)图书馆基本信息。(2)图书馆的书籍。(3)图书馆管理员。(4)读者信息。

程序要完成下列功能:

(1)查询图书馆的总信息。(2)查询图书馆管理员的信息。(3)查询图书馆藏书信息。

(4)存入新书(有管理员加入,需进行身份验证)。5)旧书处理。(6)存入新的管理员的信

息。(7)修改管理员信息(增加工龄,加薪)。(8)两所图书馆的最大藏书量之和。

(9)根据书名检索书信息。(10)查询读者的借阅信息。(11)查询读者信息(包括借书情况、到期时间、罚款情况。)。(12)管理员可以修改用户的欠款和交款的金额。

(13)读者分为学生、研究生和教师。学生的租期为1个月,教师的租期为2个月。

#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>#include <malloc.h>#define LEN sizeof(struct book)struct book {char book_name[20];//书籍名称int number;int count;struct book* next;};int n;struct book* creat(){struct book* head;struct book* p1, * p2;n = 0;p1 = p2 = (struct book*)malloc(LEN);printf("*****书的编号*****书名*****剩余数量*****\n");scanf("%d%s%d", &p1->number, &p1->book_name, &p1->count);head = NULL;while (p1->number != 0){n++;printf("*****书的编号*****书名*****剩余数量*****\n");if (n == 1)head = p1;else p2->next = p1;p2 = p1;p1 = (struct book*)malloc(LEN);scanf("%d%s%d", &p1->number, &p1->book_name, &p1->count);}p2->next = NULL;printf("录入成功!\n");return(head);}void print(struct book* head){struct book* p;p = head;if (head != NULL){printf("*****书的编号*****书名*****剩余数量*****\n");do{printf("%d%s%d\n", p->number, p->book_name, p->count);p = p->next;} while (p != NULL);}else printf("没有这本书!\n");}struct book* del(int num, int count, struct book* head){int flag = 0;struct book* p1, * p2;p2 = NULL;do{p1 = head;if (head == NULL){printf("没有这本书 !\n");goto end;}while (p1->number != num && p1->next != NULL) //当编号不相等(没找到)且下一个链表不是空的时{p2 = p1;p1 = p1->next;//转到下一个链表(p2还在上一个链表)}if (p1->number == num && p1->count > count){printf("借阅编号为N0.%d 本数为:%d\n", num, count); //删除完成p1->count -= count;flag++;break;//标记,如果为0表示不执行删除操作}else if (p1->number == num && p1->count == count) {if (p1 == head)head = p1->next;//如果第一个链表就是要找的将头指针指向下一个链表(删除本链表)elsep2->next = p1->next;//第N个是要找的链表,将p2所指的链表与p1后的链表相连(删除p1的链表)}} while (p1->next != NULL);if (flag != 0)printf("删除完成 !\n");end:return(head);}struct book* add(int num, struct book* head) {int flag = 0;struct book* p;p = head;if (num != 0)printf("*****书的编号*****书名*****剩余数量*****\n");while (p != NULL){if (p->number == num){printf("%d%s%d\n", p->number, p->book_name, p->count);printf("请输入要还书个数:");int new_count = 0;scanf("%d", &new_count);p->count += new_count;flag = 1;goto end;}p = p->next;}if (flag == 0) {printf("没有这本书!\n");}system("cls");end:return(p);}void number(struct book* head){int num, a = 0;struct book* p;printf("*****请输入 \"0\" 结束输入*****\n");do{p = head;printf("请输入要查找的书的编号:");scanf("%d", &num);if (num != 0)printf("*****书的编号*****书名*****作者*****剩余数量*****\n");while (p != NULL){if (p->number == num){printf("%d%s%d\n", p->number, p->book_name, p->count);a++;}p = p->next;}if (a == 0 && num != 0)printf("没有这个书!\n");a = 0;} while (num != 0);system("cls");}void search(struct book* head){int a;struct book* p;p = head;do{printf("1.按书编号查找\n2.退出\n");scanf("%d", &a);system("cls");switch (a) {case 1:number(p); break;case 2:break;}} while (a != 2);}struct book* sort(struct book* head){struct book* p1, * p2;int i, j;char string[20];for (i = 0; i < n - 1; i++){p1 = head;int temp2, temp1;for (j = n - 1; j > 0; j--)while (p1->next != NULL){p2 = p1;p1 = p1->next;if (p2->number > p1->number){temp1 = p1->number;p1->number = p2->number;p2->number = temp1;strcpy(string, p1->book_name);strcpy(p1->book_name, p2->book_name);strcpy(p2->book_name, string);temp2 = p1->count;p1->count = p2->count;p2->count = temp2;}}}return(head);}int main() {struct book* head = NULL;int num;int a;int count;while (1) {printf(" _______________________________________________\n");printf("| 欢迎您使用图书管理系统 |\n");printf("|1.录入图书信息 |\n");printf("|2.删除图书信息 |\n");printf("|3.借书 |\n");printf("|4.还书 |\n");printf("|5.查找图书信息 |\n");printf("|6.排序图书信息 |\n");printf("|7.退出图书管理系统 |\n");printf("|_______________________________________________|\n");printf("********请您选择需要使用的功能********\n");int choice = 0;scanf("%d", &choice);system("cls");//1.录入图书信息if (choice == 1) {printf("*****请输入 \"0 0 0 \" 结束输入*****\n");head = creat();print(head);}//2.删除图书信息else if (choice == 2) {printf("*****请输入 \"0\" 结束输入*****\n");do {printf("请输入要删除书本编号和本数:");scanf("%d%d", &num, &count);head = del(num, count, head);print(head);} while (num != 0);printf("\n\n\n\n\n\n");}//3.借书 else if (choice == 3) {printf("*****请输入 \"0\" 结束输入*****\n");while (number != 0) {printf("请输入要借出书本编号和本数:");scanf("%d%d", &num, &count);head = del(num, count, head);print(head);}printf("\n\n\n\n\n\n");}//4.还书else if (choice == 4) {printf("请输入书编号:");scanf("%d", &num);head = add(num, head);print(head);}//5.查找图书信息else if (choice == 5) {search(head);printf("\n\n\n\n\n\n");}//排序else if (choice == 6) {head = sort(head);print(head);getchar();printf("\n\n\n\n\n\n");}//7.退出系统else if (choice == 7){break;}else {printf(" ********您输入的数据非法请重新输入********\n");}}return 0;}

运行结果

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。