Ask Experts Questions for FREE Help !
Ask
    zaratk90's Avatar
    zaratk90 Posts: 1, Reputation: 1
    New Member
     
    #1

    Oct 24, 2011, 03:02 AM
    Please any one remove errors from this c programme,its hospital database project
    #include<iostream.h>
    #include<conio.h>
    #include<string.h>
    #include<stdlib.h>
    #define MAXPATIENTS 100
    Struct patient
    {
    Char FirstName[50];
    Char LastName[50];
    Char ID[20];
    };
    Class queue
    {
    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];
    };
    Queue::queue ()
    {
    NumberOfPatients = 0;
    }
    Int queue::AddPatientAtEnd (patient p)
    {
    If (NumberOfPatients >= MAXPATIENTS)
    {
    Return 0;
    }
    Else
    List[NumberOfPatients] = p; NumberOfPatients ;
    Return 1;
    }
    Int queue::AddPatientAtBeginning (patient p)
    {
    Int I;
    If (NumberOfPatients >= MAXPATIENTS)
    {
    Return 0;
    }
    For (I = NumberOfPatients-1; I >= 0; I--)
    {
    List[i 1] = List[i];
    }
    List[0] = p; NumberOfPatients ;
    Return 1;
    }
    Patient queue::GetNextPatient (void)
    { int I; patient p;
    If (NumberOfPatients == 0) {
    Strcpy(p.ID," ");
    Return p;}
    P = List[0];
    NumberOfPatients--;
    For (I=0; I<NumberOfPatients; I )
    {
    List[i] = List[i 1];
    }
    Return p;
    }
    Int queue::RemoveDeadPatient (patient * p)
    {
    Int I, j, found = 0;
    For (I=0; I<NumberOfPatients; I )
    {
    If (stricmp(List[i].ID, p->ID) == 0)
    {
    *p = List[i]; found = 1;
    NumberOfPatients--;
    For (j=i; j<NumberOfPatients; j )
    {
    List[j] = List[j 1];
    }
    }
    Return (found);
    }
    Void queue::OutputList(void)
    {
    Int I;
    If(NumberOfPatients == 0)
    {
    Cout<<"Queue is empty";
    }
    Else
    {
    For (I=0; I<NumberOfPatients; I )
    {
    Cout << " " << List[i].FirstName;
    Cout << " " << List[i].LastName;
    Cout << " " << List[i].ID;
    }
    }
    }
    Patient InputPatient (void)
    {
    Patient p;
    Cout << "Please enter data for new patient First name: ";
    Cin.getline(p.FirstName, sizeof(p.FirstName));
    Cout << "Last name: ";
    Cin.getline(p.LastName, sizeof(p.LastName));
    Cout << "Social security number: ";
    Cin.getline(p.ID, sizeof(p.ID));
    If (p.FirstName[0]==0 || p.LastName[0]==0 || p.ID[0]==0)
    {
    Strcpy(p.ID,"");
    Cout << "Error: Data not valid. Operation cancelled.";
    Getch();
    }
    Return p;
    }
    Void OutputPatient (patient * p)
    {
    If(p==NULL||p->ID[0]==0)
    {
    Cout << "No patient";
    Return;
    }
    Else
    Cout << "Patient data:";
    Cout << "First name: " << p->FirstName;
    Cout << "Last name: " << p->LastName;
    Cout << "Social security number: " << p->ID;
    }
    Int ReadNumber()
    {
    Char buffer[20];
    Cin.getline(buffer, sizeof(buffer));
    Return atoi(buffer);
    }
    Void DepartmentMenu (queue * q)
    {
    Int choice = 0, success; patient p;
    While (choice != 6)
    {
    Clrscr();
    Cout << "Welcome to department: " << q->DepartmentName;
    Cout << "Please enter your choice:";
    Cout << "1: Add normal patient";
    Cout << "2: Add critically ill patient";
    Cout << "3: Take out patient for operation";
    Cout << "4: Remove dead patient from queue";
    Cout << "5: List queue";
    Cout << "6: Change department or exit";
    Choice = ReadNumber();
    Switch (choice)
    {
    Case 1: // Add normal patient
    P = InputPatient();
    If (p.ID[0])
    {
    Success = q->AddPatientAtEnd(p);
    Clrscr();
    If (success)
    {
    Cout << "Patient added:";
    }
    Else
    {
    Cout << "Error: The queue is full. Cannot add patient:";
    }
    OutputPatient(&p);
    Cout << "Press any key";
    Getch();
    }
    Break;
    Case 2:
    P = InputPatient();
    If (p.ID[0])
    {
    Success = q->AddPatientAtBeginning(p);
    Clrscr();
    If (success)
    {
    Cout << "Patient added:";
    }
    Else
    {
    Cout << "Error: The queue is full. Cannot add patient:";
    }
    OutputPatient(&p);
    Cout << "Press any key";
    getch();
    }
    Break;
    Case 3:
    P = q->GetNextPatient();
    Clrscr();
    If (p.ID[0])
    {
    Cout << "Patient to operate:";
    OutputPatient(&p);}
    Else
    {
    Cout << "There is no patient to operate.";
    }
    Cout << "Press any key";
    Getch();
    Break;
    Case 4:
    P = InputPatient();
    If (p.ID[0])
    {
    Success = q->RemoveDeadPatient(&p);
    Clrscr();
    If (success)
    {
    Cout << "Patient removed:";
    }
    Else
    {
    Cout << "Error: Cannot find patient:";
    }
    OutputPatient(&p);
    Cout << "Press any key";
    Getch();
    }
    Break;
    Case 5: // List queue
    Clrscr();
    Q->OutputList();
    Cout << "Press any key";
    Getch();
    Break;
    }
    }
    }
    Void main ()
    {
    Int I,MenuChoice = 0;
    Queue departments[3];
    Strcpy (departments[0].DepartmentName, "Heart clinic");
    Strcpy (departments[1].DepartmentName, "Lung clinic");
    Strcpy (departments[2].DepartmentName, "Plastic surgery");
    While (MenuChoice != 4)
    {
    Clrscr();
    Cout << "Welcome to Software City Hospital";
    Cout << "Please enter your choice:";
    For(I=0;i<3;i )
    {
    Cout << ""<< (i 1) << ": " << departments[i].DepartmentName;
    }
    Cout << "4: Exit";
    MenuChoice = ReadNumber();
    If(MenuChoice>=1&&MenuChoice<=3)
    {
    DepartmentMenu(departments (MenuChoice-1));
    }
    }
    }
    Getch();
    }
    skhan00's Avatar
    skhan00 Posts: 1, Reputation: 1
    New Member
     
    #2

    May 12, 2012, 02:51 AM
    oject Program for Hospital Database Queue array.

    #include<iostream.h>
    #include<conio.h>
    #include<string.h>
    #include<stdlib.h>

    // 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
    {
    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;
    }


    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)
    {
    // 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) {
    // 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<NumberOfPatients; I++)
    {
    List[i] = List[i+1];
    }
    // return patient
    return p;
    }


    int queue::RemoveDeadPatient (patient * p)
    {
    // removes a patient from queue.
    // returns 1 if successful, 0 if patient not found
    int I, j, found = 0;
    // search for patient
    for (I=0; I<NumberOfPatients; I++)
    {
    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<NumberOfPatients; j++)
    {
    List[j] = List[j+1];
    }
    }
    }
    return found;
    }


    void queue::OutputList (void)
    {
    // lists entire queue on screen
    int I;
    if (NumberOfPatients == 0)
    {
    cout << "Queue is empty"<<endl;
    }
    else
    {

    for (I=0; I<NumberOfPatients; I++)
    {
    cout << "List[i].FirstName";
    cout << " " << List[i].LastName;
    cout << " " << List[i].ID;
    }
    }
    }


    // declare functions used by main:

    patient InputPatient (void)
    {
    // this function asks user for patient data.
    patient p;
    cout << "Please enter data for new patientFirst name: ";
    cin.getline(p.FirstName, sizeof(p.FirstName));
    cout << "Last name: ";
    cin.getline(p.LastName, sizeof(p.LastName));
    cout << "Social security number: ";
    cin.getline(p.ID, sizeof(p.ID));
    // check if data valid
    if (p.FirstName[0]==0 || p.LastName[0]==0 || p.ID[0]==0)
    {
    // rejected
    strcpy(p.ID,"");
    cout << "Error: Data not valid. Operation cancelled."<<endl;
    getch();
    }
    return p;
    }


    void OutputPatient (patient * p)
    {
    // this function outputs patient data to the screen
    if (p == NULL || p->ID[0]==0)
    {
    cout << "No patient";
    return;
    }
    else
    cout << "Patient data:";
    cout << "First name: " << p->FirstName<<endl;
    cout << "Last name: " << p->LastName<<endl;
    cout << "Social security number: " << p->ID<<endl;
    }


    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

    void();
    // print menu
    cout << "Welcome to department: " << q->DepartmentName<<endl;
    cout << "Please enter your choice:"<<endl;
    cout << "1: Add normal patient"<<endl;
    cout << "2: Add critically ill patient"<<endl;
    cout << "3: Take out patient for operation"<<endl;
    cout << "4: Remove dead patient from queue"<<endl;
    cout << "5: List queue"<<endl;
    cout << "6: Change department or exit"<<endl;
    // get user choice
    choice = ReadNumber();
    // do indicated action
    switch (choice)
    {
    case 1: // Add normal patient
    p = InputPatient();
    if (p.ID[0])
    {
    success = q->AddPatientAtEnd(p);
    void();
    if (success)
    {
    cout << "Patient added:"<<endl;

    }
    else
    {
    // error
    cout << "Error: The queue is full. Cannot add patient:"<<endl;
    }
    OutputPatient(&p);
    cout << "Press any key"<<endl;
    getch();
    }
    break;

    case 2: // Add critically ill patient
    p = InputPatient();
    if (p.ID[0])
    {
    success = q->AddPatientAtBeginning(p);
    void();
    if (success)
    {
    cout << "Patient added:"<<endl;
    }
    else
    {
    // error
    cout << "Error: The queue is full. Cannot addpatient:"<<endl;
    }

    OutputPatient(&p);
    cout << "Press any key"<<endl;
    getch();
    }
    break;

    case 3: // Take out patient for operation
    p = q->GetNextPatient();
    void();
    if (p.ID[0])
    {
    cout << "Patient to operate:"<<endl;
    OutputPatient(&p);}
    else
    {
    cout << "There is no patient to operate."<<endl;
    }
    cout << "Press any key"<<endl;
    getch();
    break;

    case 4: // Remove dead patient from queue
    p = InputPatient();
    if (p.ID[0])
    {
    success = q->RemoveDeadPatient(&p);
    void();
    if (success)
    {
    cout << "Patient removed:"<<endl;
    }
    else
    {
    // error
    cout << "Error: Cannot find patient:"<<endl;
    }
    OutputPatient(&p);
    cout << "Press any key";
    getch();
    }
    break;

    case 5: // List queue
    void();
    q->OutputList();
    cout << "Press any key";
    getch(); break;
    }
    }
    }


    // main function defining queues and main menu
    void main ()
    {
    int I, MenuChoice = 0;
    // define three queues
    queue departments[3];
    // set department names
    strcpy (departments[0].DepartmentName, "Heart clinic");
    strcpy (departments[1].DepartmentName, "Lung clinic");
    strcpy (departments[2].DepartmentName, "Plastic surgery");

    while (MenuChoice != 4)
    {
    // clear screen
    void();
    // print menu
    cout << "Welcome to Shiza City Hospital"<<endl;
    cout << "Please enter your choice:"<<endl;
    for (I = 0; I < 3; I++)
    {
    // write menu item for department I
    cout << "" << (i+1) << ": " << departments[i].DepartmentName<<endl;
    }
    cout << "4: Exit"<<endl;
    // get user choice
    MenuChoice = ReadNumber();
    // is it a department name?
    if (MenuChoice >= 1 && MenuChoice <= 3)
    {
    // call submenu for department
    // (using pointer arithmetics here:)
    DepartmentMenu (departments + (MenuChoice-1));
    }
    }
    }

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Hospital Development Project [ 3 Answers ]

Hello Advisor RE: Hospital Development Project We have tackled the initial key hurdles including financing & government permits. I have put together the key elements of the steps below, but if anyone has experience or can point me to a site/agency that has conducted such projects...


View more questions Search