Thread: Student desperately needing help!

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    8

    Question Student desperately needing help!

    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.

  2. #2
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    First off, you probably want to put the program in a loop, otherwise you have no need for the "Quit" option and cannot return to the menu.

    Next, you might want to give us an idea where your problem is. Since you say the program's a mess, you don't really want us to search through the mess, do you?

    What is your most immediate problem? Is it say displaying a record? Or entering a name? What is your step by step process to solve it, and where is your program not doing it's job?

    Be sure to break each menu section cleanly into separate steps.

    And the correct statement is
    Code:
    int main()
    (most other forms are incorrect) and be sure to return a value at the end of your program.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    8
    You're right mate its my mess, lol. Well i dont where to begin with my problems. Well my most immediate problem would probably be when selecting option 2 - displaying an singular record by selecting the patientID and option q when it quits the program. If anyone could show me how to do that I would be very grateful.

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    8
    Anyone? Please, something that I can at least get marks for?
    Please.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
        case '2':
            number = callfunctionthatpromptsfornumber( );
            callfunctionthatdisplaysrecord( number );
        break;
    
        ...
    
        case 'q':
            closefilesandfreemallocedmemory( );
            return 0;
        ...
    As suggested, put it all in a loop. A better idea would be to try one thing at a time. Make a program that loops until you use 'q' to quit.

    Once that works, add another piece of functionality to it.

    Lather, rinse, repeat.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Updating in a sequential file?
    By Ronnyv1 in forum C Programming
    Replies: 1
    Last Post: 03-24-2009, 04:41 PM
  2. Database assignment is Killing me!
    By Boltrig in forum C Programming
    Replies: 2
    Last Post: 11-29-2007, 03:56 AM
  3. Student Needing Help (not cheating-just help)
    By Captn Japan in forum C++ Programming
    Replies: 4
    Last Post: 04-09-2003, 05:58 AM
  4. LinkList Sorting in C
    By simly01 in forum C Programming
    Replies: 3
    Last Post: 11-25-2002, 01:21 PM
  5. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM