1075:药房管理c语言
时间: 2023-10-26 20:03:43 浏览: 216
很高兴听到您对药房管理系统的开发感兴趣。药房管理系统是一种用于帮助药房更好地管理药品库存和销售的软件。以下是一个简单的药房管理系统的C语言代码示例:
```c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct medicine {
char name[50];
int id;
int qty;
float price;
};
int main() {
struct medicine data[100];
int i, n, ch, id, qty;
float amt;
char name[50];
printf("Enter the number of medicines: ");
scanf("%d", &n);
for (i = 0; i < n; i++) {
printf("Enter name of medicine %d: ", i + 1);
scanf("%s", data[i].name);
printf("Enter ID of medicine %d: ", i + 1);
scanf("%d", &data[i].id);
printf("Enter quantity of medicine %d: ", i + 1);
scanf("%d", &data[i].qty);
printf("Enter price of medicine %d: ", i + 1);
scanf("%f", &data[i].price);
}
do {
printf("\n1. Search medicine by ID\n");
printf("2. Search medicine by name\n");
printf("3. Buy medicine\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &ch);
switch (ch) {
case 1:
printf("Enter ID of medicine to search: ");
scanf("%d", &id);
for (i = 0; i < n; i++) {
if (data[i].id == id) {
printf("\nMedicine found!\n");
printf("Name: %s\n", data[i].name);
printf("ID: %d\n", data[i].id);
printf("Quantity: %d\n", data[i].qty);
printf("Price: %.2f\n", data[i].price);
break;
}
if (i == n - 1)
printf("\nMedicine not found!\n");
}
break;
case 2:
printf("Enter name of medicine to search: ");
scanf("%s", name);
for (i = 0; i < n; i++) {
if (strcmp(data[i].name, name) == 0) {
printf("\nMedicine found!\n");
printf("Name: %s\n", data[i].name);
printf("ID: %d\n", data[i].id);
printf("Quantity: %d\n", data[i].qty);
printf("Price: %.2f\n", data[i].price);
break;
}
if (i == n - 1)
printf("\nMedicine not found!\n");
}
break;
case 3:
printf("Enter ID of medicine to buy: ");
scanf("%d", &id);
for (i = 0; i < n; i++) {
if (data[i].id == id) {
printf("Enter quantity of medicine to buy: ");
scanf("%d", &qty);
if (qty > data[i].qty)
printf("\nMedicine not available in the required quantity!\n");
else {
amt = qty * data[i].price;
data[i].qty -= qty;
printf("\nMedicine bought successfully!\n");
printf("Total amount: %.2f\n", amt);
}
break;
}
if (i == n - 1)
printf("\nMedicine not found!\n");
}
break;
case 4:
printf("Exiting...");
exit(0);
default:
printf("Invalid choice!\n");
}
} while (ch != 4);
return 0;
}
```
这个示例演示了一个简单的药房管理系统,其中包括添加、搜索、购买和退出选项。您可以根据需要进行更改和扩展。
阅读全文