Question

Take a hospital as an example.

When a patient is admitted, he/she receives a status:

2 = Highest priority
1 = High priority
0 = Low priority

Each time a patient is admitted, a node is created, and the patient and their status (2,1 or 0) are entered into a priority queue.

For the sake of testing, two files have been created:

patient.txt contains data for patients. For each patient there are four fields:
name – a string
condition – a string with the condition of the patient
age – an int
priority – an int (0, 1, or 2)

cmnd.txt – contains a sequence of commands:
Add – add the next patient to the queue
Get – remove the patient with the highest priority
End – end of the file

Write the C function in PriorityQueue.c according to PriorityQueue.h.
In your main program keep reading the commands from cmnd.txt until the end is reached. If the command is “Add” then read the next patient from patient.txt. If the command is “Get” and there are patients in the queue, then get the next patient from the queue. Print the patient data after reading it and when the patient is treated.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

int main(int argc, char** argv) {
    FILE * commands ;
    FILE * patient ;
    const int COMMAND_LENGTH = 4;
    char command[COMMAND_LENGTH];
    Node *n;
    Node * head;
   
    // open files
    commands = fopen("cmnd.txt", "r");
    patient = fopen("patient.txt", "r");
   
    // catch errors
    if (commands == NULL) {
       printf("Cannot open and read cmnd.txt\n") ;
       return EXIT_FAILURE;
    }
    if (patient == NULL) {
       printf("Cannot open and read patient.txt\n") ;
       return EXIT_FAILURE;
    }
   
    head = NULL;
   
    // reach each string in cmnd.txt
    while (!feof(commands)) {...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Array Min and Max in C++
Homework Solution
$10.00
Computer Science
C++ Programming
Arrays
Min
Max
Users
Range
Incorrect Entries
Numbers
Samples
Input
Output
Rational Numbers in C++
Homework Solution
$75.00
Computer Science
C++ Programming
Classes
Rational Numbers
Integers
Principles
Numerator
Denominator
Constructors
Objects
Summation
Instances
Library Application in C++
Homework Solution
$20.00
Computer Science
C++ Programming
Library Application
Classes
Books
Members
Attributes
Statements
Conditions
Constructors
Variables
Objects
Methods
Battleship Game in C
Homework Solution
$50.00
Computer Science
C Programming
Battleship Game
Players
Grid
Ships
Missile
Letters
Guesses
Scores
C# Hotel Application
Homework Solution
$8.00
Computer Science
C# Programming
Hotel Application
Customers
Invoices
Weekdays
Weekends
Criteria
Fees
Taxes
Buttons
Controls
Matrix Problems in C++
Homework Solution
$20.00
Computer Science
C++ Programming
Matrix Problems
Arrays
Algorithms
Columns
Functions
Elements
Pointers
Statements
Boundary Conditions
Get help from a qualified tutor
Live Chats