#include #include #include #define MAXRUNNERS 100 /* --------------------------------------------------- */ /* Type declarations which are used for this program. */ /* DO NOT CHANGE (or add to) these type declarations. */ /* --------------------------------------------------- */ typedef struct { int hr; int min; int sec; } runtime_t; typedef struct { char name[30]; int runid; runtime_t pb; runtime_t recent; } runner_t; typedef struct { int total; runner_t runners[MAXRUNNERS]; } runclub_t; typedef struct { char name[30]; int runid; runtime_t result; } result_t; /* ----------------- End of type declarations ------------------ */ /* ------------------------------------------------------------- */ /* We have one global variable storing a runclub_t database. */ /* DO NOT CHANGE and DO NOT ADD ANY EXTRA GLOBAL VARIABLES */ /* ------------------------------------------------------------- */ runclub_t slowAC; /* ------------------------------------------------------------ */ /* The following three function declarations must be completed */ /* as your solution for Q1 of Section B. ---------------------- */ /* ------------------------------------------------------------ */ /* -------------------------------------------------------------- */ /* This function should compute (and return) the minutes-per-mile */ /* pace indicated by the given half-marathon (13.1) mile time. */ /* -------------------------------------------------------------- */ double minpermile(runtime_t time) { /* BEGIN ANSWER (a) -- do not delete this line */ return 0.0; /* END ANSWER (a) -- do not delete this line */ } /* ---------------------------------------------------------------- */ /* This function should search for the runner with the fastest 'pb' */ /* time in the database, and return the user id of this runner, or */ /* the value -1 if the database is empty. */ /* ---------------------------------------------------------------- */ int fastest() { /* BEGIN ANSWER (b) -- do not delete this line */ return -1; /* END ANSWER (b) -- do not delete this line */ } /* --------------------------------------------------------------- */ /* This function takes one argument of type result_t, searches the */ /* running database for the user id mentioned of the argument. If */ /* the user is already in the database, the runners 'recent' time */ /* must be updated, and possibly the 'pb' (personal best) time. If */ /* the user id is not in the database, a new entry must be created */ /* with the details of the input argument, and the 'total' entry */ /* of the database must be updated. */ /* This function should return 1 *unless* it is a new runner and */ /* the database is full. */ /* --------------------------------------------------------------- */ int updateDB(result_t res) { /* BEGIN ANSWER (c) -- do not delete this line */ return 1; /* END ANSWER (c) -- do not delete this line */ } /* --------------------------------------------------------------- */ /* -------- END OF FUNCTIONS WHICH MUST BE IMPLEMENTED ---------- */ /* -------- DO NOT CHANGE THE REMAINDER OF THE PROGRAM ---------- */ /* --------------------------------------------------------------- */ /* ------------------------------------------------------------- */ /* Initialisation function is to help you test. DO NOT CHANGE. */ /* ------------------------------------------------------------- */ void initialize() { runtime_t tempt; strcpy(slowAC.runners[0].name, "Vicky"); slowAC.runners[0].runid=10; tempt.hr = 1; tempt.min = 10, tempt.sec= 03; slowAC.runners[0].pb=tempt; slowAC.runners[0].recent=tempt; strcpy(slowAC.runners[1].name, "Haile"); slowAC.runners[1].runid=15; tempt.hr = 1; tempt.min = 01, tempt.sec= 16; slowAC.runners[1].pb=tempt; slowAC.runners[1].recent=tempt; strcpy(slowAC.runners[2].name, "Paula"); slowAC.runners[2].runid=6; tempt.hr = 1; tempt.min = 22, tempt.sec= 13; slowAC.runners[2].pb=tempt; slowAC.runners[2].recent=tempt; strcpy(slowAC.runners[3].name, "Gary"); slowAC.runners[3].runid=22; tempt.hr = 1; tempt.min = 42, tempt.sec= 35; slowAC.runners[3].pb=tempt; slowAC.runners[3].recent=tempt; strcpy(slowAC.runners[4].name, "Eamonn"); slowAC.runners[4].runid=14; tempt.hr = 1; tempt.min = 10, tempt.sec= 11; slowAC.runners[4].pb=tempt; slowAC.runners[4].recent=tempt; strcpy(slowAC.runners[5].name, "Sonia"); slowAC.runners[5].runid=33; tempt.hr = 1; tempt.min = 03, tempt.sec= 20; slowAC.runners[5].pb=tempt; slowAC.runners[5].recent=tempt; strcpy(slowAC.runners[6].name, "Barry"); slowAC.runners[6].runid=17; tempt.hr = 1; tempt.min = 32, tempt.sec= 50; slowAC.runners[6].pb=tempt; slowAC.runners[6].recent=tempt; slowAC.total=7; } /* ----------------------------------------------------------- */ /* Function to print a time in --:--:-- format. DO NOT CHANGE. */ /* ----------------------------------------------------------- */ void printtime(runtime_t time) { printf("%2d:%2d:%2d", time.hr, time.min, time.sec); } /* ------------------------------------------------------------- */ /* This function searches for a runner with the given id, and */ /* outputs runner details if the runner is in the database. It */ /* is provided to help with your testing. DO NOT CHANGE. */ /* -------------------------------------------------------------- */ void runnerdetails(int id) { int r=0, found = 0; runner_t person; while ((r