病床呼叫系统主函数程序
时间: 2024-02-23 07:03:33 浏览: 20
好的,以下是病床呼叫系统主函数程序的示例代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_BEDS 100
struct Bed {
int id;
char patient_name[50];
int call_flag;
};
struct Bed beds[MAX_BEDS];
void init_beds() {
for (int i = 0; i < MAX_BEDS; i++) {
beds[i].id = i + 1;
memset(beds[i].patient_name, 0, sizeof(beds[i].patient_name));
beds[i].call_flag = 0;
}
}
void print_bed(struct Bed bed) {
printf("床号:%d, 患者姓名:%s, 呼叫状态:%s\n", bed.id, bed.patient_name, bed.call_flag ? "已呼叫" : "未呼叫");
}
void print_beds() {
for (int i = 0; i < MAX_BEDS; i++) {
print_bed(beds[i]);
}
}
void call_bed(int bed_id) {
beds[bed_id - 1].call_flag = 1;
}
void assign_patient(int bed_id, char* patient_name) {
strcpy(beds[bed_id - 1].patient_name, patient_name);
}
int main() {
init_beds();
assign_patient(1, "张三");
assign_patient(2, "李四");
assign_patient(3, "王五");
call_bed(2);
call_bed(3);
print_beds();
return 0;
}
```
这个程序演示了一个简单的病床呼叫系统。程序中定义了一个 Bed 结构体,用于存储床位的相关信息,如床号、患者姓名和呼叫状态。程序中还定义了一些函数,如 init_beds() 用于初始化所有床位,print_bed() 和 print_beds() 用于打印单个床位和所有床位的信息,call_bed() 用于将指定床位的呼叫状态设置为已呼叫,assign_patient() 用于将指定床位分配给指定患者。
在主函数中,首先调用 init_beds() 初始化床位,然后将前三个床位分别分配给张三、李四和王五。接着调用 call_bed() 将第二个床位和第三个床位的呼叫状态设置为已呼叫。最后调用 print_beds() 打印所有床位的信息。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://img-home.csdnimg.cn/images/20210720083646.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)