图书馆系统的c++代码
时间: 2023-10-01 18:06:01 浏览: 78
抱歉,由于缺乏详细的需求和功能描述,我们无法提供完整的图书馆系统C代码。但是,以下是一个简单的图书馆系统的C代码示例,以供参考:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_BOOKS 100 // 最大书籍数
struct Book {
char title[50];
char author[50];
int year;
};
struct Library {
struct Book books[MAX_BOOKS];
int num_books;
};
void add_book(struct Library *lib, char *title, char *author, int year) {
// 添加新书
if (lib->num_books < MAX_BOOKS) {
strcpy(lib->books[lib->num_books].title, title);
strcpy(lib->books[lib->num_books].author, author);
lib->books[lib->num_books].year = year;
lib->num_books++;
printf("Added book: %s by %s (%d)\n", title, author, year);
} else {
printf("Library is full!\n");
}
}
void print_books(struct Library *lib) {
// 打印所有书籍
printf("Library contains %d books:\n", lib->num_books);
for (int i = 0; i < lib->num_books; i++) {
printf("%s by %s (%d)\n", lib->books[i].title, lib->books[i].author, lib->books[i].year);
}
}
int main() {
struct Library lib = {0};
add_book(&lib, "The C Programming Language", "Brian W. Kernighan and Dennis M. Ritchie", 1978);
add_book(&lib, "The Hitchhiker's Guide to the Galaxy", "Douglas Adams", 1979);
print_books(&lib);
return 0;
}
```