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 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 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 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 to Expert-Tailored 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

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions