C语言实现药品排序模块:按条形码、库存、生产日期排序并输出信息
以下是一个使用C语言编写的药品排序模块,包括根据药品条形码、库存数量和生产日期进行排序的功能。 ```c #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct { char barcode[20]; int quantity; char productionDate[10]; } Medicine; void sortMedicinesByBarcode(Medicine *medicines, int n) { for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (strcmp(medicines[j].barcode, medicines[j + 1].barcode) > 0) { Medicine temp = medicines[j]; medicines[j] = medicines[j + 1]; medicines[j + 1] = temp; } } } } void sortMedicinesByQuantity(Medicine *medicines, int n) { for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (medicines[j].quantity > medicines[j + 1].quantity) { Medicine temp = medicines[j]; medicines[j] = medicines[j + 1]; medicines[j + 1] = temp; } } } } void sortMedicinesByProductionDate(Medicine *medicines, int n) { for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (strcmp(medicines[j].productionDate, medicines[j + 1].productionDate) > 0) { Medicine temp = medicines[j]; medicines[j] = medicines[j + 1]; medicines[j + 1] = temp; } } } } void printMedicines(Medicine *medicines, int n) { printf("Barcode\tQuantity\tProduction Date\n"); for (int i = 0; i < n; i++) { printf("%s\t%d\t%s\n", medicines[i].barcode, medicines[i].quantity, medicines[i].productionDate); } } int main() { int n; printf("Enter the number of medicines: "); scanf("%d", &n); Medicine *medicines = (Medicine *)malloc(n * sizeof(Medicine)); printf("Enter the details of each medicine:\n"); for (int i = 0; i < n; i++) { printf("Medicine %d:\n", i + 1); printf("Barcode: "); scanf("%s", medicines[i].barcode); printf("Quantity: "); scanf("%d", &medicines[i].quantity); printf("Production Date: "); scanf("%s", medicines[i].productionDate); } printf("\nSorting by Barcode:\n"); sortMedicinesByBarcode(medicines, n); printMedicines(medicines, n); printf("\nSorting by Quantity:\n"); sortMedicinesByQuantity(medicines, n); printMedicines(medicines, n); printf("\nSorting by Production Date:\n"); sortMedicinesByProductionDate(medicines, n); printMedicines(medicines, n); free(medicines); return 0; } ``` 这个程序首先定义了一个`Medicine`结构体,包含药品的条形码、库存数量和生产日期信息。然后实现了三个排序函数,分别按照条形码、库存数量和生产日期对药品数组进行排序。最后在`main`函数中获取用户输入的药品信息,并调用相应的排序函数进行排序,然后输出排序后的药品信息。 ######[AI写代码神器 | 1025点数解答 | 2024-06-01 19:17:20]
- Java:抽象类 Vehicle 及子类 Car、MotorBike 实战演示(讯飞星火 | 440点数解答 | 2024-06-06 23:18:54)324
- 用 Pandas 深度剖析数据:从读取到统计分析全流程实战(GPT | 642点数解答 | 2024-06-30 15:39:49)374
- 用 Pandas 深入分析招聘数据:从数据读取到可视化全流程解析(GPT | 1539点数解答 | 2024-06-30 15:56:50)387
- Python 实现球类:精准计算半径、表面积与体积,附输入验证与异常处理!(阿里通义 | 261点数解答 | 2024-11-28 21:19:39)369
- PHP实训:从0到1搭建电商平台,收获技能与成长!(讯飞星火 | 674点数解答 | 2024-06-17 08:58:32)365
- bookmanage 数据库表创建、测试数据添加及多需求 SQL 操作全解析(GPT | 909点数解答 | 2024-06-22 22:25:19)418
- WinForm实现图书管理系统:数据库操作、界面设计与功能全解析(GPT | 1163点数解答 | 2024-06-22 22:26:42)377
- 单机版保质期管理系统 HTML 实现及开发要点(字节豆包 | 2458点数解答 | 2026-04-01 06:49:18)32
- 基于商品效期规则的本地网页管理系统,无需服务器和网络,单HTML文件本地浏览器运行。 商品效期规则: 保质期≥12个月:临期提醒提前45天,下架提前5天(含过期提醒) 6个月≤保质期<12个月:临期提醒提前20天,下架提前3天(含过期提醒) 3个月≤保质期<6个月:临期提醒提前15天,下架提前3天(含过期提醒) 30天≤保质期<3个月:临期提醒提前10天,下架提前3天(含过期提醒) 15天≤保质期<30天:临期提醒提前5天,下架提前3天(含过期提醒) 保质期≤15天:临期提醒提前3天,下架提前2天(含过期提醒) 一定要遵守上门这个规则,状态以上位置,需要一一对应。 严格遵循 6 级保质期规则 → 自动计算「临期/下架/过期」状态(绿/黄/红) 产品管理模块: 商品列表展示:序号、名称、类别、生产日期、保质期、到期日、剩余天数(带单位)、状态(正常/临期/下架(一定要注意,选择类型要根据选择显示),对应绿/黄/红颜色)、操作(编辑、删除、备注),默认按照后添加先排,还需要根据一些条件,比如剩余天数可以筛选排序。 功能:添加商品(弹窗形式,保质期仅支持"XX天"或"XX月"格式)(讯飞星火 | 2053点数解答 | 2026-04-01 23:04:48)27
- 51 单片机:定时器 0 实现 8 个 LED 循环点亮,附代码及优化建议(字节豆包 | 1193点数解答 | 2024-12-27 15:10:29)341
- Java 递归爬取国家统计局地区 <tr><td> 信息:附完整代码与实现解析( | 1006点数解答 | 2024-05-20 14:15:53)278
- Python实现数组创建、操作及元素查找的多功能程序(阿里通义 | 903点数解答 | 2024-10-21 23:43:14)249