Need help with my C homework. The idea is to use proj1.c to define all the funct
ID: 3576445 • Letter: N
Question
Need help with my C homework. The idea is to use proj1.c to define all the functions. The other functions are not to be modified. Any help would be appriciated! The list of directions are as follows:
PROJ1.C:
#define _CRT_SECURE_NO_WARNINGS#include <stdlib.h>#include "proj1.h"#include "proj2.h"
/* This functions returns a pointer to the node containing the given patient'srecord */struct Node * findPatientbyID(struct Node * head, unsigned int ID){
struct Node * ptr = NULL;return ptr; //pointer to the node containing the patient's data
}
/* Display current elements of the linked list in their current order. For eachelement, display the patient's name, ID, and ward number on a single line,separated by commas . */void displayList(struct Node * head) {
}
/* This function first calls genNewPatient, then stores the returned data in anew Node structure, and finally attaches this node at the start of the linkedlist */struct Node * addNewPatient(struct Node * head) {
return head;
}
/* This function first find the Node where the given patient's record is storedin the list, then deletes it from the list */struct Node * removePatient(struct Node * head, unsigned int ID) {
return head;
}
/* This function adds today's date and current hour as a new checkup date in thecheckupHistory field of the given patient's record */struct Node * updatePatient(struct Node * head, unsigned int ID) {
return head;
}
void showCheckupHistory(struct Node * head, unsigned int ID) {}
struct Node * sortByName(struct Node * head) {
return head;
}
struct Node * sortByWardNumber(struct Node * head) {
return head;
}
/* This function writes the information in all patient records into a text file*/void write2File(struct Node * head, char * filename) {
}
/* This function deallocates all the dynamic variables used to store the nodesof the linked list */struct Node * freeList(struct Node * head) {
return head;
}
Proj1.h:
#include "structs.h"
struct Node * findPatientbyID(struct Node * head, unsigned int ID);void displayList(struct Node * head);struct Node * addNewPatient(struct Node * head);struct Node * removePatient(struct Node * head, unsigned int ID);struct Node * updatePatient(struct Node * head, unsigned int ID);void showCheckupHistory(struct Node * head, unsigned int ID);struct Node * sortByName(struct Node * head);struct Node * sortByWardNumber(struct Node * head);void write2File(struct Node * head, char * filename);struct Node * freeList(struct Node * head);
proj2.c:
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>#include <time.h>#include <string.h>#include "proj2.h"
char *NAMES [] = {"Farhad Akbar", "Bassam Awad Alanazi", "Roger Cungtha Biak","Christian Curtis Collier", "Tanner Durnil", "Melissa Gudeman", "Daniel PatrickKobold Jr", "Travis Lee Leondis", "Cleopatrio Soares Neto", "Daniel BiaklianSang", "Bryant Bernard", "Joaquin John Garcia", "Jacob Austin Shebesh","D'Artagnan S. Engle", "You Zhou", "SYAMIL ALI", "Joi Ashlyn Officer"};char *ILLNESSES[] = { "Heart disease", "Diabetes", "Melanoma", "Colon Cancer","Eye Surgery", "Lung Cancer", "High Blood Pressure", "Ear infection" };const int NumWards = 10;
void fillNewPatientData(struct Patient * V){
static int first_time = 1;time_t t;
/* Intialize the random number generator */if (first_time) {
srand((unsigned)time(&t));first_time = 0;
}
V->ID = rand() % 9000 + 1000;strcpy(V->name, NAMES[rand() % 17]);strcpy(V->illness, ILLNESSES[rand() % 8]);V->wardNumber = 100 + rand() % NumWards;V->num_checkups = 0;
}
//one the famous sorting methods, adapted to linked lists ...struct Node * sortByID(struct Node * head){
int done;struct Node *ptr;struct Node *tmp, *stmp;
//Special cases: when the list contains 0 or 1 elements, then no need to
sort!
if (head == NULL || head->hook == NULL)
return head;
done = 0;
while(!done){done = 1;
for (ptr = head; ptr->hook != NULL; ){if(ptr->data.ID > ptr->hook->data.ID)
{
done = 0;if(ptr == head)
{
head = ptr->hook;tmp = head->hook;head->hook = ptr;ptr->hook = tmp;
} else {
tmp = head;while (tmp->hook != ptr)tmp = tmp->hook;stmp = ptr->hook->hook;tmp->hook = ptr->hook;ptr->hook->hook = ptr;ptr->hook = stmp;
}
}else
ptr=ptr->hook;
}
}return head;
}
Proj2.h:
#include "structs.h"
void fillNewPatientData(struct Patient * new_patient_ptr);struct Node * sortByID(struct Node * head);
Proj_main.c:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>#include <ctype.h>
#include "structs.h"#include "proj1.h"#include "proj2.h"
#define OUTPUT_FILENAME "final_proj_patients.txt"void printMainMenu();
int main(void){
struct Node *head; //pointer to the first node (element) of the linked
list
char X;unsigned int id;unsigned int sorting_option;int done = 0;
/* Initialize the linked list to be empty */head = NULL;
while (!done){
printMainMenu();printf(">>>>> Enter a command : ");
X = getchar();fflush(stdin);X = toupper(X);
switch(X) {
case 'D':// Display list
displayList(head);break;
case 'A':
// Add new patienthead = addNewPatient(head);displayList(head);break;
case 'R':
// Remove patientif (head == NULL)
printf("The list is empty. ");
else {
displayList(head);do {
printf(">>>>> Choose a Patient ID : ");
} while (scanf("%u", &id) == 0);head = removePatient(head, id);displayList(head);
}break;
case 'U':
// Update patient checkup historyif (head == NULL)printf("The list is empty. ");else {
displayList(head);do {
printf(">>>>> Choose a Patient ID : ");
} while (scanf("%u", &id) == 0);head = updatePatient(head, id);
}break;
case 'C':
// Show patient checkup historyif (head == NULL)
printf("The list is empty. ");
else {
displayList(head);do {
printf(">>>>> Choose a Patient ID : ");
} while (scanf("%u", &id) == 0);showCheckupHistory(head, id);
}break;
case 'S':
// Sort list by patient name OR by ward numberif (head == NULL)printf("The list is empty. ");else {
do {
printf(">>>>> Enter 1 to sort by Patient
Name, Enter 2 to sort by Ward Number : ");
} while (scanf("%u", &sorting_option) == 0 ||
(sorting_option != 1 && sorting_option != 2));
if (sorting_option == 1)
head = sortByName(head);else //if (sorting_option == 2)head = sortByWardNumber(head);displayList(head);//now put the list back in its original order!head = sortByID(head);
}break;
case 'Q':// Terminate
if (head != NULL) {
write2File(head, OUTPUT_FILENAME);head = freeList(head);
}done = 1;break;
} //end switchfflush(stdin);
} //end whilereturn 0;
}
void printMainMenu(){
printf("******************************************************* ");printf("******************************************************* ");printf(" Main Menu ");printf("******************************************************* ");printf(" D Display List ");printf(" A Add New Patient ");printf(" R Remove Patient ");printf(" U Update Patient Checkup History ");printf(" C Show Patient Checkup History ");printf(" S Sort list by Patient Name or by Ward Number ");printf(" Q Terminate Program ");printf("******************************************************* ");printf("******************************************************* ");
}
Structs.h:
#ifndef __STRUCTS__#define __STRUCTS__
struct Date {
unsigned int day; // a value between 1 and 31unsigned int month; // 1: January, ..., 12: Decemberunsigned int year; // birth year, for example 1986unsigned int hour; //0: midnight, 1: 1am, ..., 23 : 11pm
};struct Patient {
unsigned int ID; //unique hospital admission number for each patientchar name[30]; //Patient's namechar illness[100];unsigned short wardNumber; //ward number where patient is stayingunsigned int num_checkups; //number of currently used elements in the
checkupHistory array
struct Date checkupHistory[100];
};struct Node {
struct Patient data;struct Node * hook;
};
#endif
Show transcribed image text
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. find PatientbyID struct Node 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 nked list owever 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 imp ented with the Plem assumption that the linked list is already orted by increasing order of ID value void. display List (struct Node head) This function prints to the screen all patient information in each element of the linked list in a nicely form atted manner struct Node addNewPatient (struct Node head) This function should first create a struct Node dy namic 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 nked list, and finally calls the sortByID function ocated in File proj2.c) so that the list remains sorted in increasing order of ID val struct Node Patient (struct Node head unsigned int ID f the given ID number is inval d, i.e. there is no node for it the nked list, the function simply displays a 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 update Patient (struct Node head unsigned int ID) This function pdates 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 pointer to the first node of the k 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 (ktimeh 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 findPatientbyIDcan 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 lis struct Node sortByWardNumber struct Node head) This function should sort nodes of the nked 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 ne per patient. The nes should be in the same order of the patients in the linked lis struct Node freelist (struct Node head) This function should free up all dy mory variables used by the nked list, and return NULL namic melExplanation / Answer
Paste your text here and click on "Next" to observe this text redactor do it's issue.
haven't any text to check? haven't any text to check? Click "Select Samples".struct Node * ptr = NULL;return ptr; //pointer to the node containing the patient's information
}
/* show current parts of the joined list in their current order. For eachelement, show the patient's name, ID, and ward range on one line,separated by commas . */void displayList(struct Node * head)
/* This operate initial calls genNewPatient, then stores the came information in afresh Node structure, and eventually attaches this node at the beginning of the linkedlist */struct Node * addNewPatient(struct Node * head)
/* This operate initial realize the Node wherever the given patient's record is storedin the list, then deletes it from the list */struct Node * removePatient(struct Node * head, unsigned int ID)
/* This operate adds today's date and current hour as a brand new medical date in thecheckupHistory field of the given patient's record */struct Node * updatePatient(struct Node * head, unsigned int ID)
void showCheckupHistory(struct Node * head, unsigned int ID)
struct Node * sortByName(struct Node * head)
struct Node * sortByWardNumber(struct Node * head)
/* This operate writes the data altogether patient records into a text file*/void write2File(struct Node * head, char * filename)
/* This operate deallocates all the dynamic variables accustomed store the nodesof the joined list */struct Node * freeList(struct Node * head)
Proj1.h:
#include "structs.h"
struct Node * findPatientbyID(struct Node * head, unsigned int ID);void displayList(struct Node * head);struct Node * addNewPatient(struct Node * head);struct Node * removePatient(struct Node * head, unsigned int ID);struct Node * updatePatient(struct Node * head, unsigned int ID);void showCheckupHistory(struct Node * head, unsigned int ID);struct Node * sortByName(struct Node * head);struct Node * sortByWardNumber(struct Node * head);void write2File(struct Node * head, char * filename);struct Node * freeList(struct Node * head);
proj2.c:
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>#include <time.h>#include <string.h>#include "proj2.h"
char *NAMES [] =
V->ID = rand() the concerns 9000 + 1000;strcpy(V->name, NAMES[rand() the concerns 17]);strcpy(V->illness, ILLNESSES[rand() the concerns 8]);V->wardNumber = one hundred + rand() the concerns NumWards;V->num_checkups = 0;
}
//one the celebrated sorting strategies, tailored to joined lists ...struct Node * sortByID(struct Node * head)once the list contains zero or one parts, then no have to be compelled to
sort!
if (head == NULL || head->hook == NULL)
return head;
done = 0;
while(!done) else
}else
ptr=ptr->hook;
}
}return head;
}
Proj2.h:
#include "structs.h"
void fillNewPatientData(struct Patient * new_patient_ptr);struct Node * sortByID(struct Node * head);
Proj_main.c:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>#include <ctype.h>
#include "structs.h"#include "proj1.h"#include "proj2.h"
#define OUTPUT_FILENAME "final_proj_patients.txt"void printMainMenu();
int main(void)the primary node (element) of the joined
list
char X;unsigned int id;unsigned int sorting_option;int done = 0;
/* Initialize the joined list to be empty */head = NULL;
while (!done){
printMainMenu();printf(">>>>> Enter a command : ");
X = getchar();fflush(stdin);X = toupper(X);
switch(X) {
case 'D':// show list
displayList(head);break;
case 'A':
// Add new patienthead = addNewPatient(head);displayList(head);break;
case 'R':
// take away patientif (head == NULL)
printf("The list is empty. ");
else done = 1;break;
} //end switchfflush(stdin);
} //end whilereturn 0;
}
void printMainMenu(){
printf("******************************************************* ");printf("******************************************************* ");printf(" Main Menu ");printf("******************************************************* ");printf(" D Display List ");printf(" A Add New Patient ");printf(" R Remove Patient ");printf(" U Update Patient medical History ");printf(" C Show Patient medical History ");printf(" S Sort list by Patient Name or by Ward Number ");printf(" Q Terminate Program ");printf("******************************************************* ");printf("******************************************************* ");
}
Structs.h:
#ifndef __STRUCTS__#define __STRUCTS__
struct Date a worth between one and 31unsigned int month; // 1: Jan, ..., 12: Decemberunsigned int year; // birth year, for instance 1986unsigned int hour; //0: hour, 1: 1am, ..., 23 : 11pm
};struct Patient {
unsigned int ID; //unique hospital admission range for every patientchar name[30]; //Patient's namechar illness[100];unsigned short wardNumber; //ward range wherever patient is stayingunsigned int num_checkups; //number of presently used parts within the
checkupHistory array
struct Date checkupHistory[100];
};struct Node ;
#endif