图书销售系统 C语言 C++ 数据结构 链表 课程设计.docx
《图书销售系统 C语言 C++ 数据结构 链表 课程设计.docx》由会员分享,可在线阅读,更多相关《图书销售系统 C语言 C++ 数据结构 链表 课程设计.docx(23页珍藏版)》请在三一办公上搜索。
1、图书销售系统 C语言 C+ 数据结构 链表 课程设计#include<stdio.h>#include<stdlib.h>#include<memory.h>#include<string.h>#include<conio.h>/* 销售信息结构定义 */typedef struct Bookchar id32;char sn32;char name32;char author32;char type32;char press32;char publish_time32;char price32;char sale_time32;char salesma
2、n32;char number32;struct Book* next;/* 指向链表的下一个节点 */Book;/* 链表头 */Book* head = NULL;/* 记录条数 */int size = 0;/* 从键盘得到一项数据 */void get_item(char* name, char* value)printf(%s:, name);scanf(%s, value);/* 输入一条新纪录 */Book* new_recordBook* book = malloc(sizeof(Book);memset(book, 0, sizeof(Book);fflush(stdin);
3、get_item(id, book->id);get_item(sn, book->sn);get_item(name, book->name);get_item(author, book->author);get_item(type, book->type);get_item(press, book->press);get_item(publish time, book->publish_time);get_item(price, book->price);get_item(sale time, book->sale_time);get_item(sale
4、sman, book->salesman);get_item(number, book->number);return book;/* 保存一项数据 */void save_item(FILE* fp, char* value)fwrite(value, 32, 1, fp);/* 从文件读取一项数据 */void load_item(FILE* fp, char* value)fread(value, 32, 1, fp);/* 保存到文件 */void saveBook* book = head;FILE* fp = fopen(BookSale.txt, wb);fwrite(&
5、size, sizeof(size), 1, fp);while(book)save_item(fp, book->id);save_item(fp, book->sn);save_item(fp, book->name);save_item(fp, book->author);save_item(fp, book->type);save_item(fp, book->press);save_item(fp, book->publish_time);save_item(fp, book->price);save_item(fp, book->sale_tim
6、e);save_item(fp, book->salesman);save_item(fp, book->number);book = book->next;fclose(fp);/* 向链表中添加新纪录 */void add_record(Book* book)if(head=NULL)head = book;elseBook* temp = head;while(temp->next)temp = temp->next;temp->next = book;/* 从文件中读取所有记录 */void loadint i;FILE* fp = fopen(BookSale
7、.txt, rb);fread(&size, sizeof(size), 1, fp);if(feof(fp)size = 0;return;for(i=0; i<size; i+)Book* book = malloc(sizeof(Book);memset(book, 0, sizeof(Book);load_item(fp, book->id);load_item(fp, book->sn);load_item(fp, book->name);load_item(fp, book->author);load_item(fp, book->type);load_it
8、em(fp, book->press);load_item(fp, book->publish_time);load_item(fp, book->price);load_item(fp, book->sale_time);load_item(fp, book->salesman);load_item(fp, book->number);add_record(book);fclose(fp);/* 从链表中删除一条记录 */void remove_record(Book* book)Book* temp = head; if(book=head)head = book-
9、>next;while(temp)if(temp->next=book)temp->next = book->next;break;temp = temp->next;free(book);size-;save;/* 根据name查询 */Book* get_by_nameint i = 0;char name32;Book* temp = head;Book* books = malloc(sizeof(Book*)*size);memset(books, 0, sizeof(Book*)*size);printf(Please input the book name:)
10、;scanf(%s, name);while(temp)if(strcmp(temp->name, name)=0) booksi+ = temp;temp = temp->next;return books;/* 根据name排序 */Book* sort_by_nameBook* books = malloc(sizeof(Book*)*size);int i = 0, j;Book* temp = head;while(temp)booksi+ = temp;temp = temp->next;for(i=0; i<size-1; i+)for(j=1; j<size
11、-i; j+)if(strcmp(booksj->name, booksj-1->name)<0)Book* t = booksj;booksj = booksj-1;booksj-1 = t;return books;Book* get_by_authorint i = 0;char author32;Book* temp = head;Book* books = malloc(sizeof(Book*)*size);memset(books, 0, sizeof(Book*)*size);printf(Please input the author:);scanf(%s, au
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 图书销售系统 C语言 C+ 数据结构 链表 课程设计 图书 销售 系统 语言
链接地址:https://www.31ppt.com/p-3377718.html