homework_help.pdf

ECE 263/264                     Fall 2016 

Final Project  

 

Due Date – Sunday, December 11, 2016,  11:59pm 

 

This semester’s final project involves implementing a simple Hospital Patient Management System that 

will allow the user to read, store, and manipulate patient data through a friendly text‐based interface. 

During execution, the program stores all patient data in a linked list, and upon termination this data is 

automatically writes/saves into a text file. Note that this project requires knowledge of some material 

from Chapters 12, 13, and 17, which will be covered during the week of Nov. 28. 

 

1) OVERVIEW OF THE PROJECT 

You will be provided with the following 6 files that contain the initial source code for this project: 

proj_main.c, structs.h, proj1.c, proj1.h, proj2.c and proj2.h. You will need all 6 of these files to build the 

program for this project (See Section 2). 

Below is a detailed description of the contents of each of each file. 

‐ File proj_main.c contains the “main” function. 

‐ File structs.h contains all the structure definitions for the project. 

‐ File proj1.c contains empty/shell function definitions, which you will need to fill in with 

appropriate code, according to the function description given below. 

‐ File proj1.h contains prototypes for the functions defined in proj1.c  

‐ File proj2.c contains function definitions that have already been implemented. 

‐ File proj2.h contains prototypes for the functions defined in proj2.c.  

 

When the program is executed, it repeatedly displays a menu asking the user to enter a command. Each 

item in the menu corresponds to a specific operation on patient data, and each operation is performed 

by calling one of the functions that you will be implementing (see Section 6). The menu items are:  

  D Display List A Add patient R Remove patient U Update patient checkup history C Show patient checkup history S Sort list either by patient name or by ward number Q Terminate program

 

2) YOUR TASK AND WHAT YOU NEED TO SUBMIT 

Your main task in this project is to complete the function definitions in proj1.c as described in Section 6. 

You must not change any of the other 5 files.  

You may only submit file proj1.c. 

 

 

3) HOW TO GET STARTED WITH THE PROJECT 

1. Download the above mentioned 6 files from Canvas. 

2. Create a new solution in Visual studio, add all files to the solution.  

3. Build  the  solution  then  run  the  program.  The  program  should  run  correctly  but  does  not  do 

anything useful; specifically, nothing is displayed on the screen when you select any menu item. 

4. Read the project description carefully, and try to understand which functions are called for each 

menu item and what each function is supposed to do. 

5. You may want to start by implementing function displayList. It is conceptually simple and will 

test your basic understanding of linked lists. 

6. You will notice that when you initially download and run the program, nothing seems to happen 

when you select any of the menu items. This  is because the function definitions have empty 

bodies (as mentioned above in Section 1). 

 

4) STRUCTURE TYPES AND LINKED LIST 

In this project, all patient data will be stored in a linked list (Chapter 17), where each node of the list 

contains one patient’s data. The linked list is implemented based on the following 3 structures types: 

 struct Node:  represents  one  element  of  the  linked  list;  has  two  fields  –  one  of  type  struct Patient containing one patient’s data, and the other is a pointer of type struct Node * 

containing the address of the next element in the linked list. 

 struct Patient: contains pertinent information about one patient, such as their name  medical condition, and ward number. 

 struct Date:  represents a specific date and hour. 

 

The definitions of these structure types are shown below in Figure 1, and illustrated in Figure 2. Notice 

that they are actually nested: Patient contains Date and Node contains Patient. Figure 3 shows how a 

linked list is created using these structure types. 

 

Figure 1. Definitions of the structure types for this project. 

 

 

Figure 2. Visualizing the structure types for this project. 

 

Figure 3.  Creating a linked list using our defined structure types. 

 

5) DESCRIPTION OF FUNCTIONS THAT ARE ALREADY IMPLEMENTED 

File proj2.c contains definitions of two functions that have already been written for you. Below are brief 

descriptions of what each function does. In principle, you do not need to know how these functions are 

implemented; you just need to know how to call them and what they do. 

void fillNewPatientData(struct Patient * ptr); The argument ptr is a pointer to an “empty” patient structure (i.e. containing garbage values), which are 

to be filled by this function with arbitrary patient information. 

struct Node * sortByID (struct Node * head); This function sorts the nodes of the linked list in increasing order of the ID field.  

 

 

6) DESCRIPTION OF THE FUNCTIONS TO BE COMPLETED 

File proj1.c contains the definitions of several functions but with a basically empty body. Your main task 

in this project is to fill in the missing code in these definitions, based on the following descriptions of 

what each function should do.  

struct Node * findPatientbyID (struct book * head, unsigned int ID); This function takes an ID number as an argument and returns the memory address (i.e. pointer) of its 

corresponding node in the linked list. However if the ID is not in the list then return NULL. This function 

is  called  by  several  other  functions  in  file  proj1.c.    This  function  should  be  implemented  with  the 

assumption that the linked list is already sorted by increasing order of ID value. 

void displayList (struct Node * head); This function prints to the screen all patient information in each element of the linked list in a nicely 

formatted manner. 

struct Node * addNewPatient (struct Node * head); This  function  should  first  create  a  struct Node  dynamic  variable  (using  malloc),  then  calls  the 

fillNewPatientData function (located in File proj2.c) which will fill in this node with patient data. 

The function then inserts the node into the linked list, and finally calls the sortByID function (located 

in File proj2.c) so that the list remains sorted in increasing order of ID value.  

 

struct Node * removePatient (struct Node * head, unsigned int ID); If the given ID number is invalid, i.e. there is no node for it the linked list, the function simply displays an 

appropriate message on the screen; otherwise it deletes the corresponding node from the linked list, 

and  frees  up  the  memory  for  this  node  (using  free).  This  function  can  call  the findPatientbyID 

function (described above) in order to find the node corresponding to the given ID in the linked list. 

 

struct Node * updatePatient(struct Node * head, unsigned int ID); This  function  updates  a  patient’s  checkup  history  by  adding  the  current  date  and  hour  into  the  checkupHistory field of the corresponding node in the linked list, and increments the num_checkups  field.  The  function  should  return  a  pointer  to  the  first  node  of  the  link  list.  You  can  call  function  findPatientbyID  to  find  the  node  corresponding  to  the  given  ID.  Also,  you  will  need  to  call  functions from the standard C library (<time.h>) in order to obtain the current date and hour.  void showCheckupHistory (struct Node * head, unsigned int ID); This function will display on the screen the checkup history of the patient with the given ID in a nicely  formatted manner. Once again, function findPatientbyID can be called to find the node  corresponding to the given ID.    

struct Node * sortByName (struct Node * head); This function should sort nodes of the linked list in increasing alphabetical order of the name field. It 

should return a pointer to the first node of the link list. 

 

struct Node * sortByWardNumber (struct Node * head); This function should sort nodes of the linked list in increasing order of the wardNumber field. It should 

return a pointer to the first node of the link list. 

void write2File (struct Node * head, char * filename); This function should write all patient data in the linked list to a text file. One line per patient. The lines 

should be in the same order of the patients in the linked list. 

 

struct Node * freeList (struct Node * head); This function should free up all dynamic memory variables used by the linked list, and return NULL. 

  Important Notes: 

 In all these functions, the argument head is a pointer to the first node of the linked list.  

 All functions, except for the first one, are called in function main. 

7) GRADE DISTRIBUTION BY FUNCTION 

  Function  Points

1  findPatientbyID  10 

2  displayList  10 

3  addNewPatient  15 

4  removePatient  15 

5  updatePatient  15 

6  showCheckupHistory  10 

7  sortByName  20 

8  sortByWardNumber  10 

9  write2File  15 

10  freeList  15 

    135 

  However the maximum grade that can be obtained for this project is only 100, which you can obtain by 

implementing 7 functions correctly.