Hey C board members. I am a 1st year uni studnet and I'm in major strife. I've got this assignment to do by tommorow and I'm nowhere near finishing it. My fellow classmate was meant to this assignment (as I did the first two for her) but she can't do it and i cant as I missed out lectures on file handling, so my fate is in your hands. If you could bear with me and me help me out I would be eternally grateful.
We have to design a patient program for a doctor. Upon opening the program the doctor would see this screen:
Code:
Stevenson Dental Surgery
Patient System
1. Modify patient record
2. Display a patient record
3. Process work files
q. Quit the system
Choose 1, 2, 3, or q :
The doctor would then make a selection. If he was to choose option 1 he would then be able to modify the patients name, adress, suburb, state and postcode by entering the patients ID. After the user modifies the file will be updated and return to the main screen.
Option 2: The doctor enters a patients ID and then the patients information is displayed and then returned to the main menu.
Option 3: Once this is activated the user enters the patientID. It access the patients file and display the patients name and adress. Next the system asks for the jobcode to be entered (from the feeSchedule.txt attachment) - it asks for a while loop to be used as more than one job code can be applied.Then the jobcode is displayed and the corresponding description and fee. The previous balance is also listed - taken from the balance field of the patient record. The particulat patient record is updated by replacing its value with the value of the amount due for that patient.
Option 4: System ends gracefully.
The output of the file is saved to invoice.txt
Well I have maved a little attempt. So far I have managed to read the binary file and display it. Thats about it. Heres my messed up code so far:
Code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define true 1
#define false 0
#define patientFile "patient.dat"
#define feeScheduleFile "feeSchedule.txt"
#define invoiceFile "invoice.txt"
typedef struct
{
char fName[21];
char gName[21];
} name_struct;
typedef struct
{
char street[21];
char suburb[16];
char state[4];
int postcode;
} address_struct;
typedef struct
{
char id[5];
name_struct name;
address_struct address;
double balance ;
char lastUpdate[11];
} patient_struct;
FILE * openFile(char *, char *);
void closeFile(FILE *);
patient_struct getPatient(void);
void displayPatient(patient_struct);
patient_struct readPatientRecord(FILE *, patient_struct, long);
//void printDate();
main()
{
char resp;
double patientID;
int i = 0;
long count = 0;
patient_struct patient;
FILE *inFile = openFile(patientFile, "rb");
printf("\nDr Stevenson Dental Surgery");
printf("\n\tPatient System");
printf("\n");
printf("\n1. Modify patient record");
printf("\n2. Display a patient record");
printf("\n3. Process work files");
printf("\nq. Quit the system\n");
printf("\nChoose 1, 2, 3, or q :\n");
getchar();
resp=getchar();
switch(resp)
{
case '1': printf("\nPlease enter Patient ID:");
scanf("%lf", &patientID);
break;
case '2': patient = readPatientRecord(inFile, patient, count);
while(!feof(inFile))
{
displayPatient(patient);
count++;
patient = readPatientRecord(inFile, patient, count);
}
closeFile(inFile);
break;
case '3': printf("Processing");
break;
case 'q':
case 'Q': printf("Quting");
break;
default : printf("\nInvalid category.");
break;
}
/*int i = 0;
long count = 0;
patient_struct patient;
FILE *inFile = openFile(patientFile, "rb");
patient = readPatientRecord(inFile, patient, count);
while(!feof(inFile))
{
displayPatient(patient);
count++;
patient = readPatientRecord(inFile, patient, count);
}
closeFile(inFile);*/
}
/*void printDate()
{
char today[11];
time_t x;
struct tm *t;
time(&x);
t = localtime(&x);
sprintf(today,"%d/%d/%d\n", t->tm_mday, t->tm_mon + 1, t->tm_year + 1900);
puts(today);
}*/
patient_struct readPatientRecord(FILE *filePtr, patient_struct patient, long count)
{
fseek(filePtr, count * sizeof(patient), SEEK_SET);
fread(&patient, sizeof(patient), 1, filePtr);
return patient;
}
void displayPatient(patient_struct patient)
{
printf("\n");
printf("Patient id : %s \n", patient.id);
printf("Patient name : %s %s \n", patient.name.gName, patient.name.fName);
printf("Patient address: %s \n", patient.address.street);
printf(" %s %s %d\n", patient.address.suburb,
patient.address.state, patient.address.postcode);
printf("Balance : %.2lf \n", patient.balance);
printf("Last update : %s\n", patient.lastUpdate);
}
FILE * openFile(char *diskFileName, char *mode)
{
FILE *fName;
if((fName = fopen(diskFileName, mode)) == NULL)
{
printf("Error in opening file! Program terminated...");
exit(1);
}
return (fName);
}
void closeFile(FILE * fName)
{
if(fclose(fName) == EOF)
{
printf("File cannot be closed! Program terminated...");
exit(1);
}
}
Yeah its a mess. Thats why im begging for your help. Even if my system only half works I would be eternally grateful for any help you could give me.
Heres where you can find the files you need:
feeSchedule: has the prices you need:
http://www.uow.edu.au/~yang/buss111/...eeSchedule.txt
patient.dat - has the current patient information you need to update:
http://www.uow.edu.au/~yang/buss111/files/patient.dat
Well there u go. Again I thank you for your time and help.