Question: ============================================================================================================== Main.c code : * creates race and racers * main.c driver provides tests of race and racer * * compile with race.c and racer.c

 ============================================================================================================== Main.c code : * creates race and racers * main.c

driver provides tests of race and racer * * compile with race.c

and racer.c * gcc race.c racer.c main.c * OR * gcc -o

signup race.c racer.c main.c * * If creating signup object file, then

run with command: * signup * Otherwise, run with command: * a.out

==============================================================================================================

Main.c code :

* creates race and racers * main.c driver provides tests of race and racer * * compile with race.c and racer.c * gcc race.c racer.c main.c * OR * gcc -o signup race.c racer.c main.c * * If creating signup object file, then run with command: * signup * Otherwise, run with command: * a.out */

#include #include #include "race.h" #include "racer.h"

/* prototypes */ int run_test(void);

/* main * using void paramater since we are not using command line arguments * for this program */ int main(void) { run_test(); }

/* run_test * runs a test, creating races and adding/deleting racers */ int run_test(void) { /* create two races */ /* note: using pointers for races so the race data can be modified */ race *tdf = create_race(-3); race *vuelta = create_race(2);

/* create riders */ /* note: not using pointers to racers since once they are created * they are not later modified -- only used as data */ // create riders racer mickey = create_racer(101, "Mickey Mouse", 18); racer pluto = create_racer(333, "Pluto Disney", 16); racer goofy = create_racer(222, "Goofy Diskey", 21); racer daisy = create_racer(912, "Daisy Duke", 28); racer mary = create_racer(124, "Mary Poppins", 41); racer pink = create_racer(545, "Pinkalicious", 16); racer huey = create_racer(322, "Huey Duck", 15); racer dewey = create_racer(122, "Dewey Duck", 15); racer louie = create_racer(111, "Louie Duck", 15); racer peanut = create_racer(121, "Peanut Brown", 17); racer froom = create_racer(1, "Chris Froom", 38); racer contador = create_racer(201, "Alberto Contador", 40); // put some riders into Race (scanned for checkout) add_racer(tdf,mickey); add_racer(tdf,pluto); add_racer(tdf,goofy); add_racer(tdf,daisy); // for write-up: draw a picture of what tdf's racer roster looks like // print Race print_race(tdf); // put more riders into Race add_racer(tdf,mary); add_racer(tdf,pink); add_racer(tdf,huey); add_racer(tdf,dewey); // print Race print_race(tdf); // add riders add_racer(tdf,louie); add_racer(tdf,peanut); // print Race print_race(tdf); // add riders to vuelta add_racer(vuelta,pluto); add_racer(vuelta,pink); print_race(vuelta); // add another rider add_racer(vuelta,huey);

print_race(tdf);

/* put more riders in */ add_racer(tdf, louie); add_racer(tdf, louie); add_racer(tdf, froom); add_racer(tdf, contador);

/* print the race */ print_race(tdf);

/* print the race */ print_race(tdf);

/* at point to draw picture 1 in report */

/* delete riders */ //printf("Trying to delete rider 333 "); delete_racer(tdf, 333);

/* print the race */ print_race(tdf);

/* at point to draw picture 2 in report */

/* delete rider */ //printf("Trying to delete rider 0000 "); delete_racer(tdf, 0000);

/* add riders to vuelta */ add_racer(vuelta, contador); add_racer(vuelta, froom);

/* print race */ print_race(vuelta);

/* add another riders to vuelta */ add_racer(vuelta, mickey); add_racer(vuelta, mary);

/* delete riders */ //printf("Trying to delete rider 1 "); delete_racer(vuelta, 333); //printf("Trying to delete rider 0000 "); delete_racer(vuelta, 000); print_race(vuelta); //printf("Trying to delete rider 101 "); delete_racer(vuelta, 545); print_race(vuelta); //printf("Trying to delete rider 124 "); delete_racer(vuelta, 545); print_race(vuelta);

/* add riders to vuelta */ add_racer(vuelta, huey); add_racer(vuelta, dewey); print_race(vuelta);

/* free memory for races */ free_race(vuelta); free_race(tdf);

return EXIT_SUCCESS; } /* end main */

==========================================================================

Header codes

Race.h code :

#ifndef RACE_H

#define RACE_H

#include "racer.h"

/* define receipt struct below */

/* function prototypes - should match your .c implementations */

race * create_race(int max_racers);

int add_racer(race * rec, racer rcr);

int calc_min_age(race * rec);

int calc_max_age(race * rec);

double calc_avg_age(race * rec);

int delete_racer(race * rec, int racer_num);

void print_race(race * rec);

void free_race(race * rec);

#endif

==================================================================================

Racer.h code

#ifndef RACER_H

#define RACER_H

#define MAX_NAME_LENGTH 16

/* define retail_item struct below */

/* here is an example of defining a point struct with a typedef;

* delete this in your final code

typedef struct point {

double x;

double y;

} point;

*/

/* function prototypes -- should match your .c implementation */

racer create_racer (int num, char *name, int age);

void print(racer rcr);

#endif

1. Open racer.h. Below are the struct members. Complete the struct definition racer (use typedef so the type racer can be used in your code) acer bib number: int name char[MAX NAME_LENGTH1] age : int 2. Open race.h. Below are the struct members for race. Complete the struct definition for race (use typedef so the type race can be used in your code). Note that racers is a pointer to racer (aka, an array of racer objects). race acers racer* num racers : int max racers : int 3. Open main.c to see how the code can be used and tested. Similar to HWO, the run_test function creates two races and adds and deletes racers and prints the race participants (including rage age stats). 4. Create a new file called racer.c. At the top, put a useful comment that at least includes your name. Then, include , "racer.h", and "race.h". If you need to see a syntax example of how to include header files, see main.c. 1. Open racer.h. Below are the struct members. Complete the struct definition racer (use typedef so the type racer can be used in your code) acer bib number: int name char[MAX NAME_LENGTH1] age : int 2. Open race.h. Below are the struct members for race. Complete the struct definition for race (use typedef so the type race can be used in your code). Note that racers is a pointer to racer (aka, an array of racer objects). race acers racer* num racers : int max racers : int 3. Open main.c to see how the code can be used and tested. Similar to HWO, the run_test function creates two races and adds and deletes racers and prints the race participants (including rage age stats). 4. Create a new file called racer.c. At the top, put a useful comment that at least includes your name. Then, include , "racer.h", and "race.h". If you need to see a syntax example of how to include header files, see main.c

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!