Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C only! All of these functions are not meant to be dependent on one another l

ID: 3731093 • Letter: I

Question

In C only!

All of these functions are not meant to be dependent on one another like typical labs/assignments. This is intended to be three independent exercises. For example, when reading from a file, the binary file is read into dynamic memory where the timeAvailable function checks for availability directly from a file pointer.

Format of struct evernt Variables:

name - This is the name of the event and has a limit of 64 characters.

startTime - The start time of an event. An event can start any time between 8 am and 8 pm (we won't be error checking any events that start before/after 8 am/pm). Start times are stored as an hour using a 24 hour clock. i.e. 14 = 2:00 pm.

halfHour - boolean type to say whether or not the event starts after a half hour or at the start of the hour. i.e. startTime of 14 and halfHour = true starts at 2:30 pm.

duration - This is the length of an event in minutes. i.e. If an event starts at 10:00 am and has a duration of 60 minutes, the event ends at 11:00 am and thus is NOT listed as an event at 11:00 am. Events can last any length of time.

Creating the binary file.

The function for writing a binary file for testing has already been written for you. The binary file created for testing is hard coded to test cases. You just need to make sure you call the function or the fill will not be created. Feel free to add, remove, switch order, or change any of the events in the generic schedule included (remeber you solution needs should be adaptable for events that are not saved in order).

Reading the binary file. (out of 4)

The file can contain any amount of events in any order. The passed file name must be opened and read into the list pointer. It can be assumed that the pointer passed is empty and set to null. This means you are responsible for allocating memory to store the entire content of the file.

Printing the schedule. (out of 4)

The schedule will be printed in a format that is similar to a table. It will be printed from 8:00 am to 9:30 pm in half an hour intervals. It will print the schedule in the following format "08:00 am - name". It is assumed there will be no overlapping events. The name of the event will be written beside the time from start to finish and left blank when there are no events. For example, breakfast starts at 8:00 am for 30 minutes and commute starts at 9:00 am for 50 minutes. You must make sure that the schedule is printed in the proper format to receive any marks.

08:00 am - breakfast
08:30 am -
09:00 am - commute
09:30 am - commute
10:00 am -

A Couple Remarks About the Schedule

There are a few points to take note of before you start developing the program. Make sure to read the following instructions carefully so the schedule format is understood.

The binary file of the scheduled events do not need to be saved in order relative to time.

When printing the schedule, make sure to add a space after the - even if there is not an event in that time slot.

The event only flows over to the next half hour if it is strictly greater than the amount of time. i.e. if commute above was 60 minutes, the time would not overflow and would only show 9 am.

When you get to the afternoon, the time switches from a 24 hour clock to the 12 hour am/pm model.

Remember to seek/set the file pointer to the file location where you would like to begin reading when a file pointer is passed.

Hint: Since start times are limited to everything 30 minutes, treat the length of times as a discrete number of blocks.

-----------------------------------------------------------------------------------------------------------------

%%file lab08/schedule.h

/* You can add anything you would like to the header file but DO NOT DELETE ANYTHING */

/*****
* Standard Libraries
*****/

#include
#include
#include


/*****
* Self-defined Data Structures
*****/

/* enumerate a Boolean datatype for convenience */
typedef int abstractBoolean;
enum abstractBoolean {
   false,
   true
};
typedef abstractBoolean boolean;

/* Start time is in hours, duration is in minutes */
typedef struct eventNode {
    char name[64];
    int startTime;
    boolean halfHour;
    int duration;
} Event;


/*****
* Function Prototypes for schedule.c
*****/

/***** The only stipulation of this lab is that you must make these functional *****/

/* Writes to a binary file */
void createBinaryFile(char *fileName);

/* Prints a schedule of events from a list of events */
void printSchedule(Event *list, int listLength);

/* Reads the content from a binary file named fileName into the Event list pointer. Returns the number of Events. */
int readBinaryFile(char *fileName, Event **list);

-----------------------------------------------------------------------------------------------------------------

%%file lab08/schedule.c

#include "schedule.h"


/* Writes to a binary file */
void createBinaryFile(char *name) {
    int i;
    FILE *ptr = fopen(name,"wb");
    char names[][64] = {"breakfast", "commute", "meeting", "lunch", "seminar", "gym", "commute", "dinner"};
    int starts[] = {8, 8, 10, 12, 13, 16, 18, 19};
    boolean halfHours[] = {false, true, false, false, false, true, false, false};
    int durations[] = {30, 45, 75, 60, 180, 80, 45, 30};
  
  
    for(i = 0; i < 8; i++) {
        Event new;
      
        sprintf(new.name, "%s", names[i]);
        new.startTime = starts[i];
        new.halfHour = halfHours[i];
        new.duration = durations[i];
      
        fwrite(&new, sizeof(Event), 1, ptr);
    }
  
    fclose(ptr);
}


/* Prints a schedule of events from a list of events */
void printSchedule(Event *list, int listLength) {

}


/* Reads the content from a binary file named fileName. Returns the length of the list. */
int readBinaryFile(char *fileName, Event **list) {
    int listLength = 0;

    return listLength;
}

-----------------------------------------------------------------------------------------------------------------

%%file lab08/main.c


#include "schedule.h"


int main(int argc, char *argv[]) {
    char *fileName = "lab08/docs/schedule.bin";
  
    createBinaryFile(fileName);
  
    return 0;
}

Explanation / Answer

ANSWER:

#include