Home > Backend Development > C++ > How to use C++ to write a simple hospital registration system?

How to use C++ to write a simple hospital registration system?

WBOY
Release: 2023-11-03 08:05:10
Original
1364 people have browsed it

How to use C++ to write a simple hospital registration system?

How to use C to write a simple hospital registration system?

With the progress of society and the improvement of people's living standards, the demand for medical services has become more and more urgent. In order to improve the efficiency and convenience of medical services, many hospitals have begun to adopt electronic registration systems. This article will introduce you to how to use C to write a simple hospital registration system.

First, we need to define some basic data structures. In this system, we will use three structures to represent different entities: doctor, patient, and appointment.

#include <iostream>
#include <vector>

struct Doctor {
    int id;
    std::string name;
    std::string specialty;
};

struct Patient {
    int id;
    std::string name;
    int age;
};

struct Appointment {
    int id;
    Doctor doctor;
    Patient patient;
    std::string date;
};
Copy after login

Next, we need to create a database to store doctor, patient and appointment information. In this system, we will use a std::vector to save all reservation information.

std::vector<Appointment> database;
Copy after login

Next, we can implement some functions, such as adding doctors, adding patients and creating appointments.

void addDoctor() {
    Doctor doctor;
    
    // 从用户输入获取医生的信息
    std::cout << "请输入医生的编号:";
    std::cin >> doctor.id;
    std::cout << "请输入医生的姓名:";
    std::cin >> doctor.name;
    std::cout << "请输入医生的专业:";
    std::cin >> doctor.specialty;
    
    // 将医生添加到数据库中
    database.push_back(doctor);
}

void addPatient() {
    Patient patient;
    
    // 从用户输入获取患者的信息
    std::cout << "请输入患者的编号:";
    std::cin >> patient.id;
    std::cout << "请输入患者的姓名:";
    std::cin >> patient.name;
    std::cout << "请输入患者的年龄:";
    std::cin >> patient.age;
    
    // 将患者添加到数据库中
    database.push_back(patient);
}

void createAppointment() {
    Appointment appointment;
    
    // 从用户输入获取预约的信息
    std::cout << "请输入预约的编号:";
    std::cin >> appointment.id;
    
    // 从数据库中选择医生和患者
    std::cout << "医生列表:" << std::endl;
    for (const auto& doctor : database) {
        if (doctor.id >= 0) {
            std::cout << doctor.id << ": " << doctor.name << " - " << doctor.specialty << std::endl;
        }
    }
    std::cout << "请选择医生编号:";
    std::cin >> appointment.doctor.id;
    
    std::cout << "患者列表:" << std::endl;
    for (const auto& patient : database) {
        if (patient.id >= 0) {
            std::cout << patient.id << ": " << patient.name << " - " << patient.age << std::endl;
        }
    }
    std::cout << "请选择患者编号:";
    std::cin >> appointment.patient.id;
    
    std::cout << "请输入预约的日期:";
    std::cin >> appointment.date;
    
    // 将预约添加到数据库中
    database.push_back(appointment);
}
Copy after login

Finally, we can implement a simple user interface to display and operate the system.

int main() {
    while (true) {
        std::cout << "欢迎使用医院挂号系统!" << std::endl;
        std::cout << "[1] 添加医生" << std::endl;
        std::cout << "[2] 添加患者" << std::endl;
        std::cout << "[3] 创建预约" << std::endl;
        std::cout << "[4] 退出系统" << std::endl;
        
        int choice;
        std::cout << "请选择功能:";
        std::cin >> choice;
        
        switch (choice) {
            case 1:
                addDoctor();
                break;
            case 2:
                addPatient();
                break;
            case 3:
                createAppointment();
                break;
            case 4:
                return 0;
        }
        
        std::cout << std::endl;
    }
    
    return 0;
}
Copy after login

In this way, a simple hospital registration system is completed. Users can add doctors, patients and create appointments by entering different options. All information will be stored in the database and can be retrieved and manipulated through queries. The program ends when the user chooses to exit the system.

Of course, this is just a simple example system. The actual hospital registration system may be more complex and more functions and details need to be considered. But through this example, you can have a preliminary understanding of how to use C to write a simple hospital registration system, and can expand and improve it according to actual needs.

The above is the detailed content of How to use C++ to write a simple hospital registration system?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template