以下是一个简单的图书管理系统的C语言代码示例:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Book {
    char title[100];
    char author[100];
    int year;
};

void addBook(struct Book books[], int *count) {
    struct Book book;
    printf("请输入书名:");
    scanf("%s", book.title);
    printf("请输入作者:");
    scanf("%s", book.author);
    printf("请输入出版年份:");
    scanf("%d", &book.year);
    books[*count] = book;
    (*count)++;
    printf("添加成功!\n");
}

void displayBooks(struct Book books[], int count) {
    printf("图书列表:\n");
    for (int i = 0; i < count; i++) {
        printf("书名:%s,作者:%s,出版年份:%d\n", books[i].title, books[i].author, books[i].year);
    }
}

int main() {
    struct Book books[100];
    int count = 0;
    int choice;

    do {
        printf("图书管理系统\n");
        printf("1. 添加图书\n");
        printf("2. 显示图书列表\n");
        printf("0. 退出\n");
        printf("请选择操作:");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                addBook(books, &count);
                break;
            case 2:
                displayBooks(books, count);
                break;
            case 0:
                printf("感谢使用图书管理系统!\n");
                break;
            default:
                printf("请选择正确的操作!\n");
                break;
        }
    } while (choice != 0);

    return 0;
}

这个示例中,图书的信息包括书名、作者和出版年份,使用结构体 struct Book 来存储每本书的信息。图书管理系统提供了添加图书和显示图书列表的功能。用户可以选择要执行的操作,根据选择调用相应的函数进行处理。用户可以通过输入操作编号来选择不同的功能


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

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