Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// CSE240 Spring 2019 HW5 // Write your name here // Write the compiler used: Visual studio or gcc // READ BEFORE YOU START: //

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

// CSE240 Spring 2019 HW5 // 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 list of patients, like patients' record. // Each record 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. // An array of structs 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 IN YOUR CODE.

#include #include #include #pragma warning(disable: 4996) // for Visual Studio Only

#define MAX_PATIENTS 15 #define MAX_NAME_LENGTH 25

typedef enum { very_critical = 0, critical, not_critical } criticalType; // enum type

struct patientRecord { // struct for patient details char patientName[MAX_NAME_LENGTH]; char doctorName[MAX_NAME_LENGTH]; criticalType criticalLevel; unsigned int roomNumber; };

struct patientRecord list[MAX_PATIENTS]; // declare list of patients int count = 0; // the number of patients currently stored in the list (initialized to 0)

// functions already implmented void flushStdIn(); void executeAction(char); void save(char* fileName);

// functions that need implementation: int add(char* patientName_input, char* doctorName_input, char* criticalLevel_input, unsigned int roomNumber_input); // 20 points void display(); // 10 points void sort(); // 10 points void load(char* fileName); // 10 points

int main() { char* fileName = "Patient_List.txt"; load(fileName); // load list of patients from file (if it exists). Initially there will be no file. char choice = 'i'; // initialized to a dummy value do { printf(" Enter your selection: "); printf(" a: add a new patient "); printf(" d: display patient list "); printf(" s: sort patient list by name "); printf(" q: quit "); choice = getchar(); flushStdIn(); executeAction(choice); } while (choice != 'q');

save(fileName); // save list of patients to file (overwrites file, if it exists) 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 void executeAction(char c) { char patientName_input[MAX_NAME_LENGTH], doctorName_input[MAX_NAME_LENGTH]; unsigned int roomNumber_input, add_result= 0; char criticalLevel_input[20]; switch (c) { case 'a': // input patient record from user printf(" Enter patient name: "); fgets(patientName_input, sizeof(patientName_input), stdin); patientName_input[strlen(patientName_input) - 1] = '

Programming Assignment (50 points) 1. You are given a partially completed program hw05q1.c. You should follow the instructions given in the program to complete the functions so that the program executes as instructed. The program declares a struct 'patientRecord' with elements for patient's name, doctor's name, critical level of patient, room number. You will be completing a program that creates a list of patients (array of structures). 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 patient's 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 list (array of structs) of patients having sorted patients. There is save() already implemented to write the patients list to a file 'Patient_List.txt'. save() is executed at the end of the program when the user quits the program. You need to implement load() which is called at the start of the program. This function will read the saved file and fill in the array of structures. You need to read the file in the same order and manner that it is saved in save() add: atient_List.txt not found Enter your selection a: add a new patient d: display patient 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 lease enter room number: 101 Patient successfully added to the list! Enter your selection: a: add a new patient d: display patient list s: sort patient list by name q: quit Notice that since this is the first execution of the program, load) gave message "Patient_List.txt not found". This file is created at the end of the program by save). display: (after adding 3 patient details) Enter your selection: a: add a new patient d: display patient 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 Enter your selection: a: add a new patient d: display patient list s: sort patient list by name q: quit sort: Enter your selection: a: add a new patient d: display patient list s: sort patient list by name q: quit Patient list sorted! Use display option 'd' to view sorted list. Enter your selection: a: add a new patient d: display patient list s: sort patient 1list by name q: quit Patient name: David Luiz octor name: Steve Rogers ritical level: very critical Room number: 290 Patient name: Eden Hazard Doctor name: Tony Stark ritical level: not critical Room number: 101 Patient name: Willian Borges Doctor name: Bruce Banner ritical level: critical oom number: 155 Enter your selection: a: add a new patient d: display patient list s: sort patient list by name q: quit The 3 patients seen in display() output above are sorted in sort(). Use 'd' option to verify sorted result. load atients record loaded from Patient List.txt. nter your selection: a: add a new patient d: display patient list s: sort patient list by name q: quit atient name: David Luiz octor name: Steve Rogers ritical level: very critical Room number: 290 atient name: Eden Hazard Doctor name: Tony Stark ritical level: not critical oom number: 101 atient name: Willian Borges octor name: Bruce Banner ritical level: critical oom number: 155 nter your selection: a: add a new patient d: display patient list s: sort patient list by name q: quit Notice the message given by load() "Patients record loaded from Patient_List.txt" at the top. To verify that load() worked as expected, use 'd' display option to display loaded list

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions