Description
BLG 233E DATA STRUCTURES
HOMEWORK -3
A hospital has an emergency room with a doctor and a secretariat for patient registration. According to patient’s complaint, the secretariat gives the patient an appropriate code (RED, YELLOW, GREEN). The order of precedence of the codes is RED> YELLOW> GREEN. In addition, each code has a minimum duration of treatment: RED = 1 time slot, YELLOW = 2 time slots, GREEN = 3 time slots.
This minimum length of treatment period is not divisible, which means that even if a new and privileged patient arrives, the patient will be treated for the minimum amount of time the color s/he has. The patient’s color code is renewed after this minimum time expires (e.g. a patient with RED code will have a yellow code after s/he has treatment for a 1 time slot, a patient with YELLOW code will have green code after s/he has treatment for 2 time slots, the code of the patient with GREEN code doesn’t change after s/he has treatment 3 time slots).
A sample flow is presented below.
Patients When they arrive at the hospital Time of treatment they need Their complaint
Patient1 0 7 Vascular (RED)
Patient2 2 3 Fever(RED)
Patient3 3 6 Sickness(GREEN)
The first treatment of the doctor:
Patient1 will have a red code when s/he checks in the secretariat, and since no one is in treatment, Patient1’s treatment will start immediately (time = 0). Patient1 will be treated for 1 time slot. When 1 time slot has elapsed (time = 1), the patient will now have a yellow code and the time of treatment required will be 6 time slots.
The second treatment of the doctor:
Treatment of Patient1 will continue because no other patients with red code and yellow code are waiting. When Patient1 is being treated, Patient2 will arrive at the hospital and have RED code (time = 2). Though the color code of Patient2 (RED) is more privileged than the color code of the Patient1 (YELLOW), Patient2 has to wait for the minimum treatment period of Patient1 to finish because the minimum treatment duration cannot be divided. When Patient1’s minimum treatment time expires (time = 3), Patient1 will now have the GREEN code and the remaining treatment duration will be 4 time slots. At this exact time, Patient3 will arrive at the hospital (time = 3) and will have GREEN code. NOTE: Although they have the same color code, Patient3 is more privileged than Patient1 because s/he is new at the hospital.
The third treatment of the doctor:
There are now three patients (time = 3). Patient1 and Patient3 have GREEN and Patient2 has RED code. Because of its code’s privilege, Patient2 is treated (time = 3). Patient2 will now have the YELLOW code when one unit of therapy is over (time = 4).
The fourth treatment of the doctor:
Patient2 has priority because it has the YELLOW code. Treatment of Patient2 is continued (time = 4). When Patient2’s treatment finish, also the total duration of treatment of Patient2 is over (time = 6). So Patient2 leaves the hospital. (Time = 6).
The fifth treatment of the doctor:
Patient1 and Patient3 have the same color code. However, since Patient3 has a higher priority, Patient3 will receive treatment (time = 6). Patient3 will be treated for three time slots. When one time slot has elapsed (time = 9), the patient will continue to be GREEN code and the time of treatment required will be 3 time slots.
The sixth treatment of the doctor:
Patient1 and Patient3 have the same color code. However, since Patient1 is waiting longer, Patient1 will receive treatment (time = 9). Patient1 will be treated for three time slices. When a period of time has elapsed (time = 12), the patient will continue to be green code and the time of treatment required will be 1 time slots.
The seventh treatment of the doctor:
Patient1 and Patient3 have the same color code. However, since Patient3 is waiting longer, Patient3 will receive treatment (time = 12). Patient3 will be treated for three time slots. When 3 time slots have elapsed (time = 12), Patient3’s treatment finish, also the total duration of treatment of Patient3 is over (time = 15). So Patient3 leaves the hospital. (Time = 15).
The eighth treatment of the doctor:
Since there is no other patient, Patient1 will receive treatment (time = 15). When one time slot of treatment ends, Patient1 will leave the hospital (time = 16) because the treatment he needs is over.
Output of the program:
NOTE: You have an input file. The first one is “patientsInfo.txt” which has several information for each patient as “name”, “arriving time”, “treatment time” and “complaint”. Your code will be evaluated on another input file which is in the same form of “patientsInfo.txt” file.
Requirements & Grading:
1. Read the “patientsInfo.txt” input file and store patients in the queue structure (10),
2. Patients should be kept in proper queue for treatment according to given constraints (use the required number of patients) (20)
3. The existing library functions for the queue can not be used, and the required functions must be written by the programmer (empty, pop etc.) (20),
4. Patients are held in appropriate queues (20)
5. The patient whose treatment is over, leave the hospital (give back memory) (10)
6. Getting program output correctly (20)
NOTE: If you have any question about the homework, please contact to the research assistant Nurullah ATEŞ via email (atesn@itu.edu.tr).
Submission Procedure:
1. Briefly explain the main structure of your homework in your REPORT. You must use C++ programming language (don’t use C language). Also remember to add the screenshots of console outputs to the report. Use comments wherever necessary in your code to explain your aim.
2. Create a README file and briefly explain how your code can be compiled and run using GNU/Linux command line.
3. Compile the code in SSH before you send your homework.




Reviews
There are no reviews yet.