+ All Categories
Home > Documents > Hospital Manage

Hospital Manage

Date post: 29-May-2018
Category:
Upload: gurjit20
View: 216 times
Download: 0 times
Share this document with a friend

of 19

Transcript
  • 8/9/2019 Hospital Manage

    1/19

    Code :

    //Project Program for Hospital Database Queue array.

    #include

    #include

    #include

    #include

    // define maximum number of patients in a queue

    #define MAXPATIENTS 100

    // define structure for patient data

    struct patient

    {

    char FirstName[50];

    char LastName[50];

    char ID[20];

    };

    // define class for queue

    class queue

  • 8/9/2019 Hospital Manage

    2/19

    {

    public:

    queue (void);

    int AddPatientAtEnd (patient p);

    int AddPatientAtBeginning (patient p);

    patient GetNextPatient (void);

    int RemoveDeadPatient (patient * p);

    void OutputList (void);

    char DepartmentName[50];

    private:

    int NumberOfPatients;

    patient List[MAXPATIENTS];

    };

    // declare member functions for queue

    queue::queue ()

    {

    // constructor

    NumberOfPatients = 0;

    }

  • 8/9/2019 Hospital Manage

    3/19

    int queue::AddPatientAtEnd (patient p)

    {

    // adds a normal patient to the end of the queue.

    // returns 1 if successful, 0 if queue is full.

    if (NumberOfPatients >= MAXPATIENTS)

    {

    // queue is full

    return 0;

    }

    // put in new patient

    else

    List[NumberOfPatients] = p; NumberOfPatients++;

    return 1;

    }

    int queue::AddPatientAtBeginning (patient p)

    {

    // adds a critically ill patient to the beginning of the queue.

    // returns 1 if successful, 0 if queue is full.

    int i;

    if (NumberOfPatients >= MAXPATIENTS)

  • 8/9/2019 Hospital Manage

    4/19

    {

    // queue is full

    return 0;

    }

    // move all patients one position back in queue

    for (i = NumberOfPatients-1; i >= 0; i--)

    {

    List[i+1] = List[i];

    }

    // put in new patient

    List[0] = p; NumberOfPatients++;

    return 1;

    }

    patient queue::GetNextPatient (void)

    {

    // gets the patient that is first in the queue.

    // returns patient with no ID if queue is empty

    int i; patient p;

    if (NumberOfPatients == 0) {

  • 8/9/2019 Hospital Manage

    5/19

    // queue is empty

    strcpy(p.ID,"");

    return p;}

    // get first patient

    p = List[0];

    // move all remaining patients one position forward in queue

    NumberOfPatients--;

    for (i=0; i

  • 8/9/2019 Hospital Manage

    6/19

    {

    if (stricmp(List[i].ID, p->ID) == 0)

    {

    // patient found in queue

    *p = List[i]; found = 1;

    // move all following patients one position forward in queue

    NumberOfPatients--;

    for (j=i; j

  • 8/9/2019 Hospital Manage

    7/19

    cout

  • 8/9/2019 Hospital Manage

    8/19

    cout

  • 8/9/2019 Hospital Manage

    9/19

    void OutputPatient (patient * p)

    {

    // this function outputs patient data to the screen

    if (p == NULL || p->ID[0]==0)

    {

    cout

  • 8/9/2019 Hospital Manage

    10/19

    Social security number: " ID;

    }

    int ReadNumber()

    {

    // this function reads an integer number from the keyboard.

    // it is used because input with cin >> doesn't work properly!

    char buffer[20];

    cin.getline(buffer, sizeof(buffer));

    return atoi(buffer);

    }

    void DepartmentMenu (queue * q)

    {

    // this function defines the user interface with menu for one

    department

    int choice = 0, success; patient p;

    while (choice != 6)

    {

    // clear screen

    clrscr();

  • 8/9/2019 Hospital Manage

    11/19

    // print menu

    cout

  • 8/9/2019 Hospital Manage

    12/19

    choice = ReadNumber();

    // do indicated action

    switch (choice)

    {

    case 1: // Add normal patient

    p = InputPatient();

    if (p.ID[0])

    {

    success = q->AddPatientAtEnd(p);

    clrscr();

    if (success)

    {

    cout

  • 8/9/2019 Hospital Manage

    13/19

    Error: The queue is full. Cannot add patient:";

    }

    OutputPatient(&p);

    cout AddPatientAtBeginning(p);

    clrscr();

    if (success)

    {

    cout

  • 8/9/2019 Hospital Manage

    14/19

    else

    {

    // error

    cout GetNextPatient();

    clrscr();

    if (p.ID[0])

    {

    cout

  • 8/9/2019 Hospital Manage

    15/19

    Patient to operate:

    ";

    OutputPatient(&p);}

    else

    {

    cout RemoveDeadPatient(&p);

    clrscr();

    if (success)

    {

  • 8/9/2019 Hospital Manage

    16/19

    cout

  • 8/9/2019 Hospital Manage

    17/19

    clrscr();

    q->OutputList();

    cout

  • 8/9/2019 Hospital Manage

    18/19

    {

    // clear screen

    clrscr();

    // print menu

    cout

  • 8/9/2019 Hospital Manage

    19/19

    // is it a department name?

    if (MenuChoice >= 1 && MenuChoice


Recommended