Question
Programming Assignment (50 points) 1. You are given a partially completed program hw06q1.c. The structure of this homework is similar to previous homework. In this
Programming Assignment (50 points) 1. You are given a partially completed program hw06q1.c. The structure of this homework is similar to previous homework. In this homework, you should use linked list to do the same work in the previous homework. You should follow the instructions given in the program to complete the functions so that the program executes properly. You will be completing a program that creates a linked list of books. It is a menu-driven program where the user is given the following options:
a) Add a new patient to the list. When adding a new patient to the list, the user is prompted for patient's name, doctor's name, critical level of patient and room number of the patient. The patient should be added at the end of the list. If the patient already exists in the list, then you should not add to the list. The critical level is enum type. b) Display the list of patients. This should display each patients details one after the other. c) Sort the list of patients alphabetically by patient name. The sorting should happen within the list. You should not create a new linked list of patients having sorted patients. d) Remove the patient from the linked list. After removing the patient, the linked list should not be broken.
Expected output of each menu option: (similar as previous homework) add:
displayList:
deleteNode: ( see displayList() photo for list before deleting node )
sortList: ( see displayList() photo for unsorted list )
// CSE240 Spring 2019 HW6 // Write your name here // Write the compiler used: Visual studio or gcc
// READ BEFORE YOU START: // You are given a partially completed program that creates a linked list of patient records. // Each record(struct) has this information: patient's name, doctor's name, critical level of patient, room number. // The struct 'patientRecord' holds information of one patient. Critical level is enum type. // A linked list called 'list' is made to hold the list of patients. // To begin, you should trace through the given code and understand how it works. // Please read the instructions above each required function and follow the directions carefully. // You should not modify any of the given code, the return types, or the parameters, you risk getting compile error. // You are not allowed to modify main (). // You can use string library functions. // ***** WRITE COMMENTS FOR IMPORANT STEPS OF YOUR CODE. 10% deduction for not using comments ***** // ***** GIVE MEANINGFUL NAMES TO VARIABLES. *****
#include
#pragma warning(disable: 4996) // for Visual Studio Only
#define MAX_NAME_LENGTH 25
typedef enum { very_critical = 0, critical, not_critical } criticalType; // enum type
struct patientRecord { char patientName[MAX_NAME_LENGTH]; char doctorName[MAX_NAME_LENGTH]; criticalType criticalLevel; unsigned int roomNumber; struct patientRecord* next; // pointer to next node } *list = NULL; // Declare linked list 'list'
// forward declaration of functions (already implmented) void flushStdIn(); void executeAction(char);
// functions that need implementation: int add(char* patientName_input, char* doctorName_input, char* criticalLevel_input, unsigned int roomNumber_input); // 10 points void displayList(); // 10 points int countNodes(); // 5 points int deleteNode(char* patientName_input); // 10 points void swapNodes(struct patientRecord* node1, struct patientRecord* node2); // 5 points void sortList(); // 10 points
int main() { char selection = 'i'; // initialized to a dummy value printf(" CSE240 HW6 "); do { printf(" Currently %d patient(s) on the list.", countNodes()); // NOTE: countNodes() called here printf(" Enter your selection: "); printf(" a: add a new patient "); printf(" d: display patient list "); printf(" r: remove a patient from the list "); printf(" s: sort patient list by name "); printf(" q: quit "); selection = getchar(); flushStdIn(); executeAction(selection); } while (selection != 'q');
return 0; }
// flush out leftover ' ' characters void flushStdIn() { char c; do c = getchar(); while (c != ' ' && c != EOF); }
// Ask for details from user for the given selection and perform that action // Read the code in the function, case by case void executeAction(char c) { char patientName_input[MAX_NAME_LENGTH], doctorName_input[MAX_NAME_LENGTH]; unsigned int roomNumber_input, result = 0; char criticalLevel_input[20]; switch (c) { case 'a': // add patient // input patient details from user printf(" Enter patient name: "); fgets(patientName_input, sizeof(patientName_input), stdin); patientName_input[strlen(patientName_input) - 1] = '
CSE240 HW6 Currently e patient (s) on the list. Enter your selection: a: add a new patient d: display patient list r: remove a patient from the list s: sort patient list by name q: quit Enter patient name: Eden Hazard Enter doctor name: Tony Stark Enter whether patient is 'very critical' or 'critical' or 'not critical': not critical Please enter room number: 101 successfully added to the list! Currently 1 patient (s) on the list. Enter your selection: a: add a new patient d: display patient list r: remove a patient from the list s: sort patient list by name q: quit Currently 3 patient (s) on the list Enter your selection: a: add a new patient d: display patient list r: remove a patient from the list s: sort patient list by name q: quit Patient name: Eden Hazard Doctor name: Tony Stark Critical level: not critical Room number: 101 Patient name: Willian Borges Doctor name: Bruce banner Critical level: critical Room number: 155 Patient name: David Luiz Doctor name: Steve Rogers Critical level: very critical Room number: 290 Currently 3 patient (s) on the list. Enter your selection: a: add a new patient d: display patient list r: remove a patient from the list s: sort patient list by name q: quit Please enter patient name: Eden Hazard Patient successfully removed from the list. Currently 2 patient (s) on the list. Enter your selection: a: add a new patient d: display patient list r: remove a patient from the list s: sort patient list by name q: quit Patient name: David Luiz Doctor name: Steve Rogers Critical level: very critical Room number: 29 Patient name: Willian Borges Doctor name: Bruce banner Critical level: critical Room number 155 Currently 3 patient (s) on the list Enter your selection: a: add a new patient : display patient list r: remove a patient from the list s: sort patient list by name q: quit Patient list sorted! Use display option 'd' to view sorted list Currently 3 patient (s) on the list Enter your selection: a: add a new patient : display patient list r: remove a patient from the list s: sort patient list by name q: quit Patient name: David Luiz Doctor name: Steve Rogers Critical level: very critical Room number: 29e Patient name: Eden Hazard Doctor name: Tony Stark Critical level: not critical Room number 101 Patient name: Willian Borges Doctor name: Bruce banner Critical level: critical Room number: 155Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started