C语言I—作业08

这个作业属于哪个课程https://bbs.csdn.net/forums/csuft_swxy_C?typeId=17324
这个作业要求在哪里https://bbs.csdn.net/topics/603607790
这个作业的目标巩固c语言
学号20218471
  1. PTA作业
    1.1.1 贴图展示代码
    1.1.2 数据处理
    1.1.3 PTA提交列表及说明
    没有在规定时间内完成pta
  2. 学习总结
    2.1 学习进度条
周\日这周所花的时间代码行学到的知识简介目前比较迷惑的问题
第十三周8h609循环结构目前有太多疑惑的问题

2.2 累积代码行和博客字数
在这里插入图片描述
2.3 学习感悟
虽然没有做pta但是我有看pta题目发现完全不会下手

以下是一个简单的C语言图书管理系统的示例,它包括添加图书、查询图书、删除图书、借书和还书等功能: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_BOOKS 100 // 最大图书数量 // 图书结构体 typedef struct { char name[50]; // 图书名称 char id[20]; // 图书编号 float price; // 单价 char author[50]; // 作者 int status; // 存在状态,0表示未借出,1表示已借出 char borrower[50]; // 借书人姓名 char gender[10]; // 借书人性别 char student_id[20]; // 借书人学号 } Book; Book books[MAX_BOOKS]; // 图书数组 int num_books = 0; // 当前图书数量 // 添加图书 void add_book() { if (num_books >= MAX_BOOKS) { printf("图书数量已达到上限,无法添加新图书!\n"); return; } Book book; printf("请输入图书名称:"); scanf("%s", book.name); printf("请输入图书编号:"); scanf("%s", book.id); printf("请输入图书单价:"); scanf("%f", &book.price); printf("请输入图书作者:"); scanf("%s", book.author); book.status = 0; // 新添加的图书状态默认为未借出 strcpy(book.borrower, ""); strcpy(book.gender, ""); strcpy(book.student_id, ""); books[num_books++] = book; printf("添加图书成功!\n"); } // 查询图书 void search_book() { char id[20]; printf("请输入要查询的图书编号:"); scanf("%s", id); for (int i = 0; i < num_books; i++) { if (strcmp(books[i].id, id) == 0) { printf("图书名称:%s\n", books[i].name); printf("图书编号:%s\n", books[i].id); printf("图书单价:%.2f\n", books[i].price); printf("图书作者:%s\n", books[i].author); if (books[i].status == 0) { printf("图书状态:未借出\n"); } else { printf("图书状态:已借出\n"); printf("借书人姓名:%s\n", books[i].borrower); printf("借书人性别:%s\n", books[i].gender); printf("借书人学号:%s\n", books[i].student_id); } return; } } printf("未找到该图书!\n"); } // 删除图书 void delete_book() { char id[20]; printf("请输入要删除的图书编号:"); scanf("%s", id); for (int i = 0; i < num_books; i++) { if (strcmp(books[i].id, id) == 0) { for (int j = i; j < num_books - 1; j++) { books[j] = books[j + 1]; } num_books--; printf("删除图书成功!\n"); return; } } printf("未找到该图书!\n"); } // 借书 void borrow_book() { char id[20]; printf("请输入要借阅的图书编号:"); scanf("%s", id); for (int i = 0; i < num_books; i++) { if (strcmp(books[i].id, id) == 0) { if (books[i].status == 1) { printf("该图书已被借出!\n"); return; } printf("请输入借书人姓名:"); scanf("%s", books[i].borrower); printf("请输入借书人性别:"); scanf("%s", books[i].gender); printf("请输入借书人学号:"); scanf("%s", books[i].student_id); books[i].status = 1; printf("借书成功!\n"); return; } } printf("未找到该图书!\n"); } // 还书 void return_book() { char id[20]; printf("请输入要归还的图书编号:"); scanf("%s", id); for (int i = 0; i < num_books; i++) { if (strcmp(books[i].id, id) == 0) { if (books[i].status == 0) { printf("该图书未被借出!\n"); return; } books[i].status = 0; strcpy(books[i].borrower, ""); strcpy(books[i].gender, ""); strcpy(books[i].student_id, ""); printf("还书成功!\n"); return; } } printf("未找到该图书!\n"); } int main() { int choice; while (1) { printf("请选择要执行的操作:\n"); printf("1.添加图书\n"); printf("2.查询图书\n"); printf("3.删除图书\n"); printf("4.借书\n"); printf("5.还书\n"); printf("6.退出\n"); printf("请输入操作编号:"); scanf("%d", &choice); switch (choice) { case 1: add_book(); break; case 2: search_book(); break; case 3: delete_book(); break; case 4: borrow_book(); break; case 5: return_book(); break; case 6: exit(0); default: printf("无效的操作编号,请重新输入!\n"); break; } } return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值