C语言图书管理系统:借阅、归还、展示等功能实现

这篇文章展示了一个使用 C 语言实现的简单图书管理系统,包含借阅图书 (borrowBook)、归还图书 (returnBook)、展示图书信息 (displayBook) 等核心功能。

代码实现cvoid borrowBook() { char bookCode[20]; printf('请输入要借阅的图书编号:'); scanf('%s', bookCode);

if (head == NULL) {        printf('没有找到相关图书!

'); return; }

BookNode *current = head;    while (current != NULL) {        if (strcmp(current->bookCode, bookCode) == 0) {            if (current->borrowed) {                printf('该图书已借出!

'); } else { current->borrowed = 1; printf('借阅成功! '); } return; } current = current->next; }

printf('没有找到相关图书!

');}

void returnBook() { char bookCode[20]; printf('请输入要归还的图书编号:'); scanf('%s', bookCode);

if (head == NULL) {        printf('没有找到相关图书!

'); return; }

BookNode *current = head;    while (current != NULL) {        if (strcmp(current->bookCode, bookCode) == 0) {            if (current->borrowed) {                current->borrowed = 0;                printf('归还成功!

'); } else { printf('该图书未借出! '); } return; } current = current->next; }

printf('没有找到相关图书!

');}

void displayBook() { if (head == NULL) { printf('图书列表为空! '); return; }

BookNode *current = head;    while (current != NULL) {        printf('图书编号:%s

', current->bookCode); printf('书名:%s ', current->bookName); printf('作者:%s ', current->author); printf('出版社:%s ', current->publisher); printf('图书种类:%s ', current->bookkind); printf('图书种类编号:%s ', current->bookkinds); printf('价格:%d ', current->quantity); printf('借阅状态:%s ', current->borrowed ? '已借出' : '未借出'); printf(' ');

    if (current->next != NULL) {            printf('

'); }

    current = current->next;    }}

// ... 其他函数实现 ...

int main() { loadBookData();

while (1) {        // ... 菜单和用户交互 ...    }}

函数功能说明

  • borrowBook() 函数: - 接收用户输入的图书编号。 - 在图书列表中查找该编号的图书。 - 如果找到且未被借阅,则将该图书标记为已借出。- returnBook() 函数: - 接收用户输入的图书编号。 - 在图书列表中查找该编号的图书。 - 如果找到且已被借阅,则将该图书标记为未借出。- displayBook() 函数: - 遍历图书列表,打印每本书的详细信息,包括编号、书名、作者、借阅状态等。

总结

这个 C 语言实现的图书管理系统提供了一个简单的图书借阅和归还功能示例。你可以根据自己的需求扩展功能,例如添加用户管理、搜索图书、数据持久化等。

C语言图书管理系统:借阅、归还、展示等功能实现

原文地址: https://www.cveoy.top/t/topic/fx8N 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录