C語(yǔ)言鏈表實(shí)現(xiàn)簡(jiǎn)單圖書(shū)管理系統(tǒng)
本文實(shí)例為大家分享了C語(yǔ)言鏈表實(shí)現(xiàn)圖書(shū)管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)功能:
用C語(yǔ)言制作圖書(shū)管理系統(tǒng),實(shí)現(xiàn)圖書(shū)進(jìn)行登記書(shū)籍,瀏覽書(shū)籍,借閱書(shū)籍,歸還書(shū)籍,書(shū)籍排序,刪除書(shū)籍信息,查找書(shū)籍等功能。
功能展示
1.登記書(shū)籍
2.瀏覽書(shū)籍
3.借閱書(shū)籍
4.歸還書(shū)籍
5.書(shū)籍排序
6.刪除書(shū)籍
7.查找書(shū)籍
8.退出程序
代碼如下
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<string.h> ? struct bookInfo { ?? ?char name[20]; ?? ?float price; ?? ?int num; }; ? struct Node ? { ?? ?struct bookInfo data; ?? ?struct Node* next; }; struct Node* list = NULL; ? struct Node* createHead() { ?? ?struct Node* headNode = (struct Node*)malloc(sizeof(struct Node)); ?? ?headNode->next = NULL; ?? ?return headNode; } ? ? struct Node* createNode(struct bookInfo data) { ?? ?struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)); ?? ?newNode->data = data; ?? ?newNode->next = NULL; ?? ?return newNode; } ? ? void insertNodeByhead(struct Node* headNode, struct bookInfo data) { ?? ?struct Node* newNode = createNode(data); ?? ?newNode->next = headNode->next; ?? ?headNode->next = newNode; } ? void deleteNodeByName(struct Node* headNode, char *bookName) { ?? ?struct Node* posLeftNode = headNode; ?? ?struct Node* posNode = headNode->next; ?? ?while (posNode != NULL && strcmp(posNode->data.name, bookName)) ?? ?{ ?? ??? ?posLeftNode = posNode; ?? ??? ?posNode = posLeftNode->next; ?? ?} ?? ?if (posNode == NULL) ?? ??? ?return; ?? ?else ?? ?{ ?? ??? ?printf("刪除成功!\n"); ?? ??? ?posLeftNode->next = posNode->next; ?? ??? ?free(posNode); ?? ??? ?posNode = NULL; ?? ?} } struct Node* searchByName(struct Node* headNode, char* bookName) { ?? ?struct Node* posNode = headNode->next; ?? ?while (posNode != NULL && strcmp(posNode->data.name, bookName)) ?? ?{ ?? ??? ?posNode = posNode->next; ?? ?} ?? ?return posNode; } ? void printlist(struct Node* headNode) { ?? ?struct Node* pMove = headNode->next; ?? ?printf("書(shū)名\t價(jià)格\t數(shù)量\t作者\(yùn)t出版社\n"); ?? ?while (pMove!=NULL) ?? ?{ ?? ??? ?printf("%s\t%.1f\t%d\n", pMove->data.name, pMove->data.price, pMove->data.num); ?? ??? ?pMove = pMove->next; ?? ?} } ? void makeMenu() { ?? ?printf("*************************************\n"); ?? ?printf("*************圖書(shū)管理系統(tǒng)************\n"); ?? ?printf("*——————0.退出系統(tǒng)——————*\n"); ?? ?printf("*——————1.登記書(shū)籍——————*\n"); ?? ?printf("*——————2.瀏覽書(shū)籍——————*\n"); ?? ?printf("*——————3.借閱書(shū)籍——————*\n"); ?? ?printf("*——————4.歸還書(shū)籍——————*\n"); ?? ?printf("*——————5.書(shū)籍排序——————*\n"); ?? ?printf("*——————6.刪除書(shū)籍——————*\n"); ? ? printf("*——————7.查找書(shū)籍——————*\n"); ? ? printf("**************************************\n"); ? ? printf("請(qǐng)輸入(0 ~ 7):"); } ? void saveInfoFile(const char* fileName, struct Node* headNode) { ?? ?FILE* fp = fopen(fileName, "w");?? ? ?? ?struct Node* pMove = headNode->next; ?? ?while (pMove != NULL) ?? ?{ ?? ??? ?fprintf(fp, "%s\t%.1f\t%d\n", pMove->data.name, pMove->data.price, pMove->data.num); ?? ??? ?pMove = pMove->next; ?? ?} ?? ?fclose(fp); } ? void readInfoFromFile(const char* fileName, struct Node* headNode) { ?? ?FILE* fp = fopen(fileName, "r"); ?? ?if (fp == NULL) ?? ?{ ?? ??? ?fp = fopen(fileName, "w+"); ?? ?} ?? ?struct bookInfo tempData; ?? ?while (fscanf(fp, "%s\t%f\t%d\n", tempData.name, &tempData.price, &tempData.num) != EOF) ?? ?{ ?? ??? ?insertNodeByhead(list, tempData); ?? ?} ?? ?fclose(fp); } ? void bubbleSortlist(struct Node* headNode) { ?? ?for (struct Node* p = headNode->next; p != NULL; p = p->next) ?? ?{ ?? ??? ?for (struct Node* q = headNode->next; q->next != NULL; q = q->next) ?? ??? ?{ ?? ??? ??? ?if (q->data.price > q->next->data.price) ?? ??? ??? ?{ ?? ??? ??? ??? ?struct bookInfo tempData = q->data; ?? ??? ??? ??? ?q->data = q->next->data; ?? ??? ??? ??? ?q->next->data = tempData; ?? ??? ??? ?} ?? ??? ?} ?? ?} ?? ?printlist(headNode); } ? void keyDown() { ?? ?int userKey = 0; ?? ?struct bookInfo tempBook; ?? ?struct Node* result = NULL; ?? ?scanf("%d",&userKey); ?? ?switch (userKey) ?? ?{ ?? ?case 0: ?? ??? ?printf("【退出】\n"); ?? ??? ?printf("退出成功\n"); ?? ??? ?system("pause"); ?? ??? ?exit(0); ? ? ? ? ? ? ? ? ? ?? ??? ?break; ?? ?case 1: ?? ??? ?printf("【登記】\n"); ?? ??? ?printf("輸入書(shū)籍的信息(name,price,num):"); ?? ??? ?scanf("%s%f%d", tempBook.name, &tempBook.price, &tempBook.num); ?? ??? ?insertNodeByhead(list, tempBook); ?? ??? ?saveInfoFile("bookinfo.txt", list ); ?? ??? ?break; ?? ?case 2: ?? ??? ?printf("【瀏覽】\n"); ?? ??? ?printlist(list); ?? ??? ?break; ?? ?case 3: ?? ??? ?printf("【借閱】\n"); ? ? ?? ??? ?printf("請(qǐng)輸入借閱的書(shū)名:"); ?? ??? ?scanf("%s", tempBook.name); ?? ??? ?result = searchByName(list, tempBook.name); ?? ??? ?if (result == NULL) ?? ??? ?{ ?? ??? ??? ?printf("沒(méi)有相關(guān)書(shū)籍無(wú)法借閱!\n"); ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?if (result->data.num > 0) ?? ??? ??? ?{ ?? ??? ??? ??? ?result->data.num--; ?? ??? ??? ??? ?printf("借閱成功!\n"); ?? ??? ??? ?} ?? ??? ??? ?else ?? ??? ??? ?{ ?? ??? ??? ??? ?printf("當(dāng)前書(shū)籍無(wú)庫(kù)存,借閱失??!\n"); ?? ??? ??? ?} ?? ??? ?} ?? ??? ?break; ?? ?case 4: ?? ??? ?printf("【歸還】\n"); ? ?? ?? ??? ?printf("請(qǐng)輸入歸還的書(shū)名:"); ?? ??? ?scanf("%s", tempBook.name); ?? ??? ?result = searchByName(list, tempBook.name); ?? ??? ?if (result == NULL) ?? ??? ?{ ?? ??? ??? ?printf("該書(shū)無(wú)借出記錄\n"); ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?result->data.num++; ?? ??? ??? ?printf("書(shū)籍歸還成功!\n"); ?? ??? ?} ?? ??? ?break; ?? ?case 5: ?? ??? ?printf("【排序】\n"); ?? ??? ?bubbleSortlist(list); ?? ??? ?break; ?? ?case 6: ?? ??? ?printf("【刪除】\n"); ?? ??? ?printf("請(qǐng)輸入刪除書(shū)名:"); ?? ??? ?scanf("%s", tempBook.name); ?? ??? ?deleteNodeByName(list, tempBook.name); ?? ??? ?saveInfoFile("bookinfo.txt", list); ?? ??? ?break; ?? ?case 7: ?? ??? ?printf("【查找】\n"); ?? ??? ?printf("請(qǐng)輸入要查詢(xún)的書(shū)名:"); ?? ??? ?scanf("%s", tempBook.name); ?? ??? ?result = searchByName(list, tempBook.name); ?? ??? ?if (result == NULL) ?? ??? ?{ ?? ??? ??? ?printf("未找到相關(guān)信息!\n"); ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?printf("書(shū)名\t價(jià)格\t數(shù)量\t作者\(yùn)t出版社\n"); ?? ??? ??? ?printf("%s\t%.1f\t%d\n", result->data.name, result->data.price, result->data.num); ?? ??? ?} ?? ??? ?break; ?? ?default: ?? ??? ?printf("【error】\n"); ?? ??? ?break; ?? ?} } ? int main() { ?? ?list= createHead(); ?? ?readInfoFromFile("bookinfo.txt", list); ?? ?while (1) ?? ?{ ?? ??? ?makeMenu(); ?? ??? ?keyDown(); ?? ??? ?system("pause"); ?? ??? ?system("cls"); ?? ?} ?? ?system("pause"); ?? ?return 0; }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C語(yǔ)言實(shí)現(xiàn)圖書(shū)管理系統(tǒng)
- C語(yǔ)言圖書(shū)管理系統(tǒng)簡(jiǎn)潔版
- C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單圖書(shū)管理系統(tǒng)
- C語(yǔ)言圖書(shū)管理系統(tǒng)課程設(shè)計(jì)
- C語(yǔ)言鏈表實(shí)現(xiàn)圖書(shū)管理系統(tǒng)
- C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單的圖書(shū)管理系統(tǒng)
- C語(yǔ)言實(shí)現(xiàn)圖書(shū)館管理系統(tǒng)
- C語(yǔ)言實(shí)現(xiàn)圖書(shū)管理系統(tǒng)(文件數(shù)據(jù)庫(kù))
- C語(yǔ)言圖書(shū)管理系統(tǒng)實(shí)驗(yàn)
- C語(yǔ)言單鏈表實(shí)現(xiàn)圖書(shū)管理系統(tǒng)
相關(guān)文章
C語(yǔ)言數(shù)據(jù)結(jié)構(gòu)系列篇二叉樹(shù)的概念及滿(mǎn)二叉樹(shù)與完全二叉樹(shù)
在上一章中我們正式開(kāi)啟了對(duì)數(shù)據(jù)結(jié)構(gòu)中樹(shù)的講解,介紹了樹(shù)的基礎(chǔ)。本章我們將學(xué)習(xí)二叉樹(shù)的概念,介紹滿(mǎn)二叉樹(shù)和完全二叉樹(shù)的定義,并對(duì)二叉樹(shù)的基本性質(zhì)進(jìn)行一個(gè)簡(jiǎn)單的介紹。本章附帶課后練習(xí)2022-02-02C++ inline內(nèi)聯(lián)函數(shù)詳解
這篇文章主要介紹了C++ inline內(nèi)聯(lián)函數(shù)詳解,有感興趣的同學(xué)可以借鑒參考下2021-02-02C++11中bind綁定器和function函數(shù)對(duì)象介紹
這篇文章主要介紹了C++11中bind綁定器和function函數(shù)對(duì)象介紹,綁定器,函數(shù)對(duì)象和lambda表達(dá)式只能使用在一條語(yǔ)句中,更多相關(guān)內(nèi)容需要的小伙伴可以參考一下2022-07-07notepad介紹及插件cmake編譯過(guò)程(替代notepad++)
這篇文章主要介紹了notepad介紹及插件cmake編譯過(guò)程(替代notepad++),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-03-03基于C語(yǔ)言實(shí)現(xiàn)三子棋游戲的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何利用C語(yǔ)言數(shù)組實(shí)現(xiàn)簡(jiǎn)單的三子棋游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07