Need help with my C homework. The idea is to use proj1.c to call all the functio
ID: 3576057 • Letter: N
Question
Need help with my C homework. The idea is to use proj1.c to call all the functions. The other functions are not to be modified. Any help would be appriciated! It would be easier to attatch the code given for the homework but the option was not given so I have just copy and pasted each .c and .h file required. If you need more info please comment and I will clearify.
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
Explanation / Answer
advertisements
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.