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 */
#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
example output
Race:
Racer 101 Mickey Mouse 18
Racer 333 Pluto Disney 16
Racer 222 Goofy Diskey 21
Racer 912 Daisy Duke 28
Racer ages youngest: 16 yo, oldest: 28 yo, average age: 20.75
Race:
Racer 101 Mickey Mouse 18
Racer 333 Pluto Disney 16
Racer 222 Goofy Diskey 21
Racer 912 Daisy Duke 28
Racer 124 Mary Poppins 41
Racer 545 Pinkalicious 16
Racer 322 Huey Duck 15
Racer 122 Dewey Duck 15
Racer ages youngest: 15 yo, oldest: 41 yo, average age: 21.25
Race:
Racer 101 Mickey Mouse 18
Racer 333 Pluto Disney 16
Racer 222 Goofy Diskey 21
Racer 912 Daisy Duke 28
Racer 124 Mary Poppins 41
Racer 545 Pinkalicious 16
Racer 322 Huey Duck 15
Racer 122 Dewey Duck 15
Racer 111 Louie Duck 15
Racer 121 Peanut Brown 17
Racer ages youngest: 15 yo, oldest: 41 yo, average age: 20.20
Implement the following functions (can copy and paste function prototypes from racer.h): . create racer declare a racer object set parameters bib_num and age to data members of racer that make sense; negative racer ID numbers and negative age do not make sense, so you should set default values that do make sense o o o set the first MAX NAME LENGTH chars in the parameter name to the racer object name and ensure that the name of the racer is exactly MAX_NAME LENGTH chars long For example, if MAX_ NAME_LENGTH is 16 and the name passed in as the parameter is "Minnie Mouse", then the name of the racer should be "Minnie Mouse "(ith 4 extra spaces at the end to make name exactly 12 characters long) For example, if the racer name passed in is "Minnie Mouse - Disneylnct", then the name of the racer should be "Minnie Mouse D". This ensures that the printing of the race has a fixed width field for the name, so the printing of the racers lines up nicely. Implement the following functions (can copy and paste function prototypes from racer.h): . create racer declare a racer object set parameters bib_num and age to data members of racer that make sense; negative racer ID numbers and negative age do not make sense, so you should set default values that do make sense o o o set the first MAX NAME LENGTH chars in the parameter name to the racer object name and ensure that the name of the racer is exactly MAX_NAME LENGTH chars long For example, if MAX_ NAME_LENGTH is 16 and the name passed in as the parameter is "Minnie Mouse", then the name of the racer should be "Minnie Mouse "(ith 4 extra spaces at the end to make name exactly 12 characters long) For example, if the racer name passed in is "Minnie Mouse - Disneylnct", then the name of the racer should be "Minnie Mouse D". This ensures that the printing of the race has a fixed width field for the name, so the printing of the racers lines up nicelyStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started