最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C語言鏈表實現(xiàn)簡單圖書管理系統(tǒng)

 更新時間:2022年03月11日 11:03:11   作者:正經(jīng)的民謠書生  
這篇文章主要為大家詳細介紹了C語言鏈表實現(xiàn)簡單圖書管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C語言鏈表實現(xiàn)圖書管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

實現(xiàn)功能:

用C語言制作圖書管理系統(tǒng),實現(xiàn)圖書進行登記書籍,瀏覽書籍,借閱書籍,歸還書籍,書籍排序,刪除書籍信息,查找書籍等功能。

功能展示

1.登記書籍

2.瀏覽書籍

3.借閱書籍

4.歸還書籍

5.書籍排序

6.刪除書籍

7.查找書籍

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("書名\t價格\t數(shù)量\t作者\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("*************圖書管理系統(tǒng)************\n");
?? ?printf("*——————0.退出系統(tǒng)——————*\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("請輸入(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("輸入書籍的信息(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("請輸入借閱的書名:");
?? ??? ?scanf("%s", tempBook.name);
?? ??? ?result = searchByName(list, tempBook.name);
?? ??? ?if (result == NULL)
?? ??? ?{
?? ??? ??? ?printf("沒有相關(guān)書籍無法借閱!\n");
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?if (result->data.num > 0)
?? ??? ??? ?{
?? ??? ??? ??? ?result->data.num--;
?? ??? ??? ??? ?printf("借閱成功!\n");
?? ??? ??? ?}
?? ??? ??? ?else
?? ??? ??? ?{
?? ??? ??? ??? ?printf("當(dāng)前書籍無庫存,借閱失?。n");
?? ??? ??? ?}
?? ??? ?}
?? ??? ?break;
?? ?case 4:
?? ??? ?printf("【歸還】\n"); ? ??
?? ??? ?printf("請輸入歸還的書名:");
?? ??? ?scanf("%s", tempBook.name);
?? ??? ?result = searchByName(list, tempBook.name);
?? ??? ?if (result == NULL)
?? ??? ?{
?? ??? ??? ?printf("該書無借出記錄\n");
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?result->data.num++;
?? ??? ??? ?printf("書籍歸還成功!\n");
?? ??? ?}
?? ??? ?break;
?? ?case 5:
?? ??? ?printf("【排序】\n");
?? ??? ?bubbleSortlist(list);
?? ??? ?break;
?? ?case 6:
?? ??? ?printf("【刪除】\n");
?? ??? ?printf("請輸入刪除書名:");
?? ??? ?scanf("%s", tempBook.name);
?? ??? ?deleteNodeByName(list, tempBook.name);
?? ??? ?saveInfoFile("bookinfo.txt", list);
?? ??? ?break;
?? ?case 7:
?? ??? ?printf("【查找】\n");
?? ??? ?printf("請輸入要查詢的書名:");
?? ??? ?scanf("%s", tempBook.name);
?? ??? ?result = searchByName(list, tempBook.name);
?? ??? ?if (result == NULL)
?? ??? ?{
?? ??? ??? ?printf("未找到相關(guān)信息!\n");
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?printf("書名\t價格\t數(shù)量\t作者\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;
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C語言手寫集合List的示例代碼

    C語言手寫集合List的示例代碼

    數(shù)組長度是固定的,那么在很多時候我們并不知道到底有多少數(shù)據(jù)需要存儲,這時候我么就需要一個可變長度的數(shù)組來進行存儲,在C語言中需要我們自己進行定義,我們稱為集合。本文將用C語言實現(xiàn)手寫集合,需要的可以參考一下
    2022-08-08
  • C語言銀行系統(tǒng)課程設(shè)計

    C語言銀行系統(tǒng)課程設(shè)計

    這篇文章主要為大家詳細介紹了C語言銀行系統(tǒng)課程設(shè)計,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • C語言深入分析函數(shù)與宏的使用

    C語言深入分析函數(shù)與宏的使用

    C語言函數(shù)是一種函數(shù),用來編譯C語言,一般包括字符庫函數(shù),數(shù)學(xué)函數(shù),目錄函數(shù),進程函數(shù),診斷函數(shù),操作函數(shù)等,宏在C語言中是一段有名稱的代碼片段。無論何時使用到這個宏的時候,宏的內(nèi)容都會被這段代碼替換掉
    2022-04-04
  • C語言實現(xiàn)計算器的兩種方法

    C語言實現(xiàn)計算器的兩種方法

    這篇文章主要為大家詳細介紹了C語言實現(xiàn)計算器的兩種方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • 安裝OpenMPI來配合C語言程序進行并行計算

    安裝OpenMPI來配合C語言程序進行并行計算

    這篇文章主要介紹了安裝OpenMPI來配合C語言程序進行并行計算的例子,MPI的全稱是Message Passing Interface即標(biāo)準(zhǔn)消息傳遞界面,可以用于并行計算,需要的朋友可以參考下
    2015-11-11
  • C語言中結(jié)構(gòu)體(struct)的幾種初始化方法

    C語言中結(jié)構(gòu)體(struct)的幾種初始化方法

    相信大家都知道struct結(jié)構(gòu)體是C語言中非常重要的復(fù)合類型,初始化的方法很多,那么小編下面對這些方法進行總結(jié),便于自己和大家以后查閱,有需要的可以參考借鑒。
    2016-08-08
  • Qt5.9畫五角星的方法

    Qt5.9畫五角星的方法

    這篇文章主要為大家詳細介紹了Qt5.9畫五角星的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • C++中虛表是什么意思(概念及示例)

    C++中虛表是什么意思(概念及示例)

    虛函數(shù)表,以及虛函數(shù)指針是實現(xiàn)多態(tài)性(Polymorphism)的關(guān)鍵機制,這篇文章主要介紹了C++中虛表是什么意思(概念及示例),需要的朋友可以參考下
    2024-03-03
  • Qt控件之QToolButton的使用及示例

    Qt控件之QToolButton的使用及示例

    QToolButton類提供了一個快速訪問命令或選項的按鈕,通常在QToolBar內(nèi)部使用,本文主要介紹了Qt控件之QToolButton的使用及示例,感興趣的可以了解一下
    2023-10-10
  • 詳解C語言中二分查找的運用技巧

    詳解C語言中二分查找的運用技巧

    本文主要介紹了二分查找在實際中的應(yīng)用,通過分析幾個應(yīng)用二分查找的實例,總結(jié)下能使用二分查找算法的一些共同點,感興趣的可以了解一下
    2022-03-03

最新評論

甘泉县| 新竹县| 襄樊市| 鄂托克旗| 昭通市| 仲巴县| 舟曲县| 濮阳县| 浦江县| 洮南市| 安庆市| 青阳县| 介休市| 瓮安县| 凌云县| 集贤县| 黄浦区| 长治县| 平塘县| 富民县| 婺源县| 新平| 保靖县| 宜宾县| 独山县| 温宿县| 南昌县| 泾阳县| 绥中县| 桃源县| 尖扎县| 木兰县| 晋宁县| 顺平县| 双峰县| 霸州市| 涡阳县| 信宜市| 易门县| 嘉峪关市| 通化县|