An application for a patient visits using queue in C++

Question

Imagine you have been contacted by a local dental care office to develop an application that will manage patient visits. They want the application to place each patient in a queue and call on a first come first served basis to see the dentist Develop the menu-driven Windows Console application with the following menu items

1. Add patient 

2. Next patient

3. Previous patient

4. Delete patient

5. View current

Patient management will be resolved by the implementation of a queue with the following functions:

1. enQueue. Adds the patient in the queue

2. DeQueue: Deletes the patient from the queue

3. Peek Returns the patient that is top in the queue without removing it

4. IsEmpty checks do we have any patient in the queue 5. Size returns the number of patients that are in the queue

While adding a new patient in the queue the program will be cable of collecting the following patient information

1. Patient first and last name

2. Type of insurance

3. SSN number

4. Address

5. Date of visit

You have to write a C++ program that meets the instruction requirements above. Use the assignment template to insert the assignment deliverables outlined above

Summary

In this question, we have to develop an application for patient visits using the queue in C++. For a patient, we have to take some information like his first and last name, address, SSN, insurance type, and date of visit. We have to make an application where we can add new patients, we can know the previous and next patient, we can delete the patient and view the current patient. We will use class objects and queue data structure in order to get this type of application.

Explanation

Here, we will use two classes named “queue” and “patient”. 

In the patient class, we have defined data members first_name, last_name, insurance_type, SSN, address, and, date_of_visit. We have defined the parameter constructor to assign the data members parameter passed to the constructor. The get_data() function takes the information of the patient. The display() function displays the instance of a patient in a proper format.

In the queue class, we have defined an object array patient and rear as data members. There is one default constructor “queue” to initialize rear -1 as in the beginning queue will be empty. The enqueue() function inserts a new patient in the queue. The dequeue() function deletes the front patient from the queue. The peek() function returns the front patient. The isEmpty() function tells if the queue is empty or not. The size() function tells the numbers of patients present in the queue.

In the main function, there are six choices. If the user enters 1, he adds a new patient. When the user enters 2, he gets the next patient’s information. If the user enters 3, he gets the previous patient’s information, and if the user enters 4, he deletes the patient. If the user enters 5, he views the current patient and if the user enters 6 it exits the program.

The program for the patient visits using the queue in C++ is presented below.

Code

#include <iostream>
#include <iomanip>
using namespace std;

/*to implement the patient class*/
class patient
{ 
    public:
    /* data members */
    string first_name, last_name;
    string insurance_type;
    int SSN;
    string address, date_of_visit;
    patient(){}
    /* parametrized constructor*/
    patient(string fN, string lN, string iT, int sN, string add, string doV) 
    { 
        first_name=fN; last_name=lN; insurance_type=iT; 
        SSN=sN; address=add; date_of_visit=doV;
    }
    /* to get the patient data from user */
    void get_data()
    {
        cout<<"Enter the first name of the patient:";
        cin>>first_name;
        cout<<"Enter the last name of the patient:";
        cin>>last_name;
        cout<<"Enter the Insurance type:";
        cin>>insurance_type;
        cout<<"Enter the SSN:";
        cin>>SSN;
        cout<<"Enter the address: ";
        cin>>address;
        cout<<"Enter the date of visit:";
        cin>>date_of_visit;
    }

    /* to display*/
    void display()
    {
        cout<<left; 
        cout<<setw(18)<<(first_name+" "+last_name) <<setw(18);
        cout<<insurance_type<<setw(10)<<SSN<<setw(15)<<address;
        cout<<setw(10)<<date_of_visit<<endl<<endl;
    }
};
/*to implement the desired queue*/
class queue{
    public:
    /* for the last element in the queue*/
    int rear;
    /* to hold the patient instances in the queue*/
    patient p[30];
    /* default constructor*/
    queue () {
        rear=-1;
    }
    /* to insert a new patient into the queue*/
    void enqueue (patient p1)
    { 
        rear++; 
        p[rear] =p1;
    }
    /* to delete the front patient from the queue */
    patient dequeue () 
    {
        patient res = p[0];
        for (int i=0;i<rear;i++)
            p[i]=p[i+1];
            rear--;
            return res;
    }
    /*to return the front patient */
    patient peek() 
    {
        return p[0];
    }
    /* to check if the queue is empty */
    bool isEmpty()
    {
        if(rear==-1)
        return true;
        else
        return false;
    }
    /* to return the size of the queue*/
    int size()
    {
        return rear+1;
    }
};

/*driver code*/
int main()
{
    queue q;
    /* to display the menu*/
    cout<<"Menu\n1. Add patient\n2. Next patient \n3. Previous patient"; cout<<"\n4. Delete patient \n5. View current\n\n"; 
    while (true)
    {
        /* to get the user's choice*/
        cout<<"Enter your choice: ";
        int choice;
        cin>>choice;    
        /* if the user opts for adding a patient */
        if (choice==1) {
            patient p1;
            p1.getData();
            q.enqueue (p1);
        }
        /* for the next patient */
        else if (choice==2){
            cout<<"Enter the current index, to display the next patient: ";
            int curr; cin>>curr;
            cout<<"Next Patient:"<<endl;
            cout<<left;
            cout<<setw(18) <<"Name"<<setw(18);
            cout<<"Insurance Type"<<setw(10) << "SSN"<<setw (15)<<"Address"; 
            cout<<setw(20) <<"Date of Visit"<<endl; 
            q.p[curr+1].display();
        }
        /* for the previous patient */
        else if(choice==3){
            cout<<"Enter the current index, to display the previous patient:";
            int curr; cin>>curr;
            cout<<"Previous Patient: "<<endl;
            cout<<left;
            cout<<setw(18) <<"Name"<<setw(18); 
            cout<<"Insurance Type"<<setw(10) <<"SSN"<<setw(15)<<"Address";
            cout<<setw(20) <<"Date of Visit"<<endl; 
            q.p[curr-1].display();
        }
        /* to delete a patient*/
        else if(choice==4){
            cout<<"Deleted Patient: "<<endl; 
            cout<<left;
            cout<<setw(18) <<"Name"<<setw(18);
            cout<<"Insurance Type"<<setw(10) << "SSN"<<setw(15) <<"Address"; cout<<setw(20) <<"Date of Visit" <<endl;
            q.dequeue ().display();
        }
        /* to view the current patient */
        else if(choice==5){
            cout<<"Enter the current index: ";
            int curr; cin>>curr;
            cout<<"Next Patient:"<<endl;
            cout<<left;
            cout<<setw(18)<<"Name"<<setw(18);
            cout<<"Insurance Type"<<setw(10) <<"SSN"<<setw(15)<<"Address";
            cout<<setw(20) <<"Date of Visit"<<endl;
            q.p[curr].display();
        }
        else
        break;
        cout<<"Enter 6 to exit\n";
    }
}

Output

an application for patient visit using the queue in C++ output

 

Also read,  ARRAY OF STRUCTURE IN C

 

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *