定义一个结构体描述病患病历信息:病历号,姓名,年龄,性别,症状,初诊情况,就诊时间 (用一个结构体,存储时间:年月日)设计程序按病患姓名实现病患的查找。如果找到该病患信息,就在屏幕上显示出该人的所有信息,如果没有找到,则显示“查无此人“
时间: 2023-07-30 11:09:33 浏览: 138
以下是一个基本的C++代码实现:
```cpp
#include <iostream>
#include <string>
using namespace std;
struct Date {
int year;
int month;
int day;
};
struct MedicalRecord {
int id;
string name;
int age;
string gender;
string symptoms;
string diagnosis;
Date visitDate;
};
const int MAX_RECORDS = 100; // 最大病历数
int main() {
MedicalRecord records[MAX_RECORDS]; // 定义病历数组
int count = 0; // 记录当前的病历数
// 示例数据,实际应用中可通过读写文件、数据库等方式获取
records[count++] = { 1001, "张三", 30, "男", "头痛、发烧、咳嗽", "感冒", { 2021, 10, 1 } };
records[count++] = { 1002, "李四", 45, "女", "腰痛", "腰椎间盘突出", { 2021, 9, 15 } };
records[count++] = { 1003, "王五", 60, "男", "胸痛、气短", "冠心病", { 2021, 10, 5 } };
string searchName;
cout << "请输入要查找的病患姓名:";
cin >> searchName;
bool found = false; // 标记是否找到匹配的病患信息
for (int i = 0; i < count; i++) {
if (records[i].name == searchName) {
found = true;
// 显示病患信息
cout << "病历号:" << records[i].id << endl;
cout << "姓名:" << records[i].name << endl;
cout << "年龄:" << records[i].age << endl;
cout << "性别:" << records[i].gender << endl;
cout << "症状:" << records[i].symptoms << endl;
cout << "初诊情况:" << records[i].diagnosis << endl;
cout << "就诊时间:" << records[i].visitDate.year << "年"
<< records[i].visitDate.month << "月"
<< records[i].visitDate.day << "日" << endl;
break; // 找到一个匹配的病患信息即可退出循环
}
}
if (!found) {
cout << "查无此人" << endl;
}
return 0;
}
```
注:本代码仅作为示例,实际应用中需要针对具体需求进行修改和完善。
阅读全文