疫苗预约管理系统基础代码c语言
时间: 2023-07-30 08:08:14 浏览: 44
以下是一个简单的疫苗预约管理系统的基础代码示例,可以作为参考:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_VACCINES 10
#define MAX_APPOINTMENTS 100
struct Appointment {
char name[50];
int age;
char date[20];
char time[20];
};
struct Vaccine {
char name[50];
int quantity;
struct Appointment appointments[MAX_APPOINTMENTS];
int num_appointments;
};
struct VaccineBookingSystem {
struct Vaccine vaccines[MAX_VACCINES];
int num_vaccines;
};
void add_vaccine(struct VaccineBookingSystem* system, char* name, int quantity) {
if (system->num_vaccines == MAX_VACCINES) {
printf("Cannot add more vaccines.\n");
return;
}
struct Vaccine vaccine;
strcpy(vaccine.name, name);
vaccine.quantity = quantity;
vaccine.num_appointments = 0;
system->vaccines[system->num_vaccines] = vaccine;
system->num_vaccines++;
}
int make_appointment(struct VaccineBookingSystem* system, char* vaccine_name, struct Appointment appointment) {
for (int i = 0; i < system->num_vaccines; i++) {
if (strcmp(system->vaccines[i].name, vaccine_name) == 0) {
if (system->vaccines[i].quantity > 0) {
system->vaccines[i].quantity--;
system->vaccines[i].appointments[system->vaccines[i].num_appointments] = appointment;
system->vaccines[i].num_appointments++;
return 1;
} else {
return 0;
}
}
}
return -1;
}
int main() {
struct VaccineBookingSystem system;
system.num_vaccines = 0;
add_vaccine(&system, "Pfizer", 100);
add_vaccine(&system, "Moderna", 50);
struct Appointment appointment;
strcpy(appointment.name, "John");
appointment.age = 35;
strcpy(appointment.date, "2022-05-15");
strcpy(appointment.time, "10:00");
int result = make_appointment(&system, "Pfizer", appointment);
if (result == 1) {
printf("Appointment made successfully.\n");
} else if (result == 0) {
printf("Vaccine is out of stock.\n");
} else {
printf("Vaccine not found.\n");
}
return 0;
}
```
上述代码使用结构体表示预约和疫苗,并使用结构体数组表示整个预约系统中的所有疫苗。在此基础上,实现了两个函数:add_vaccine用于添加新的疫苗,make_appointment用于为指定的疫苗进行预约。
在这个系统中,您可以使用add_vaccine函数添加新的疫苗,并使用make_appointment函数为指定的疫苗进行预约。如果预约成功,该预约将被添加到疫苗的预约列表中,并且该疫苗的数量将减少1。如果预约失败(例如因为该疫苗已经用尽),则返回0。如果指定的疫苗不存在,则返回-1。
请注意,这只是一个基础的示例代码,实际的疫苗预约管理系统需要考虑更多的因素,例如安全性、预约时间窗口、用户身份验证等。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)