fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdbool.h>
  4. #include <ctype.h>
  5.  
  6. #define MAX_HORSES 20
  7. #define MAX_RACES 10
  8. #define MAX_NAME_LENGTH 50
  9. #define MAX_TRACK_LENGTH 100
  10. #define MAX_DATE_LENGTH 11 // Format: YYYY-MM-DD
  11.  
  12. // Enumerated types for track and race conditions
  13. typedef enum {
  14. DIRT,
  15. TURF,
  16. SYNTHETIC
  17. } TrackSurface;
  18.  
  19. typedef enum {
  20. FAST,
  21. SLOW,
  22. MUDDY,
  23. FIRM,
  24. YIELDING
  25. } TrackCondition;
  26.  
  27. typedef enum {
  28. MAIDEN,
  29. CLAIMING,
  30. ALLOWANCE,
  31. STAKES,
  32. HANDICAP
  33. } RaceType;
  34.  
  35. // Structure for a horse's past performance
  36. typedef struct {
  37. int raceID; // Unique ID for the race
  38. int position; // Finishing position
  39. float time; // Time to complete the race
  40. TrackCondition condition; // Track condition during the race
  41. } PastPerformance;
  42.  
  43. // Structure for a horse
  44. typedef struct {
  45. char name[MAX_NAME_LENGTH]; // Horse's name
  46. int age; // Horse's age
  47. float weight; // Horse's weight in pounds
  48. char jockey[MAX_NAME_LENGTH]; // Jockey's name
  49. char trainer[MAX_NAME_LENGTH]; // Trainer's name
  50. char owner[MAX_NAME_LENGTH]; // Owner's name
  51. int pastPerformanceCount; // Number of past performances
  52. PastPerformance pastPerformances[MAX_HORSES]; // Past performance records
  53. } Horse;
  54.  
  55. // Structure for a race
  56. typedef struct {
  57. int raceID; // Unique race ID
  58. char name[MAX_NAME_LENGTH]; // Name of the race
  59. float distance; // Distance in furlongs
  60. TrackSurface surface; // Track surface
  61. TrackCondition condition; // Track condition
  62. RaceType type; // Type of race
  63. int numHorses; // Number of horses in the race
  64. Horse horses[MAX_HORSES]; // Array of horses
  65. } Race;
  66.  
  67. // Structure for a racing program
  68. typedef struct {
  69. char date[MAX_DATE_LENGTH]; // Date of the program
  70. char track[MAX_TRACK_LENGTH]; // Track name
  71. int numRaces; // Number of races
  72. Race races[MAX_RACES]; // Array of races
  73. } RacingProgram;
  74.  
  75. /**************************************************
  76. // Function: initializeProgram
  77. //
  78. // Description: Initializes a RacingProgram with default values.
  79. //
  80. // Parameters: program - pointer to a RacingProgram structure
  81. //
  82. // Returns: void
  83. ***************************************************/
  84. void initializeProgram(RacingProgram *program) {
  85. strcpy(program->date, "0000-00-00");
  86. strcpy(program->track, "Unknown");
  87. program->numRaces = 0;
  88. }
  89.  
  90. /**************************************************
  91. // Function: addRace
  92. //
  93. // Description: Adds a race to the RacingProgram.
  94. //
  95. // Parameters: program - pointer to a RacingProgram structure
  96. // race - the Race to add
  97. //
  98. // Returns: true if successful, false if program is full
  99. ***************************************************/
  100. bool addRace(RacingProgram *program, Race race) {
  101. if (program->numRaces >= MAX_RACES) {
  102. return false; // Program is full
  103. }
  104. program->races[program->numRaces++] = race;
  105. return true;
  106. }
  107.  
  108. /**************************************************
  109. // Function: printRace
  110. //
  111. // Description: Prints information about a specific race.
  112. //
  113. // Parameters: race - the Race to print
  114. //
  115. // Returns: void
  116. ***************************************************/
  117. void printRace(const Race *race) {
  118. printf("Race ID: %d\n", race->raceID);
  119. printf("Name: %s\n", race->name);
  120. printf("Distance: %.2f furlongs\n", race->distance);
  121. printf("Surface: %d\n", race->surface);
  122. printf("Condition: %d\n", race->condition);
  123. printf("Type: %d\n", race->type);
  124. printf("Number of Horses: %d\n", race->numHorses);
  125. for (int i = 0; i < race->numHorses; i++) {
  126. printf(" Horse %d: %s (Jockey: %s)\n", i + 1, race->horses[i].name, race->horses[i].jockey);
  127. }
  128. }
  129.  
  130. /**************************************************
  131. // Function: printProgram
  132. //
  133. // Description: Prints all races in the RacingProgram.
  134. //
  135. // Parameters: program - pointer to the RacingProgram structure
  136. //
  137. // Returns: void
  138. ***************************************************/
  139. void printProgram(const RacingProgram *program) {
  140. printf("Race Program for %s at %s:\n", program->date, program->track);
  141. for (int i = 0; i < program->numRaces; i++) {
  142. printf("Race %d:\n", i + 1);
  143. printRace(&program->races[i]);
  144. }
  145. }
  146.  
  147. // Example usage
  148. int main() {
  149. RacingProgram program;
  150. initializeProgram(&program);
  151.  
  152. strcpy(program.date, "2024-12-15");
  153. strcpy(program.track, "Dublin Racecourse");
  154.  
  155. Race race1 = {
  156. .raceID = 1,
  157. .name = "Irish Nationals",
  158. .distance = 8.0,
  159. .surface = TURF,
  160. .condition = FAST,
  161. .type = STAKES,
  162. .numHorses = 2,
  163. .horses = {
  164. {
  165. .name = "Lucky Charm",
  166. .age = 4,
  167. .weight = 120.5,
  168. .jockey = "John Doe",
  169. .trainer = "Jane Trainer",
  170. .owner = "Green Stable",
  171. .pastPerformanceCount = 1,
  172. .pastPerformances = {
  173. {101, 1, 89.5, FAST}
  174. }
  175. },
  176. {
  177. .name = "Emerald Star",
  178. .age = 3,
  179. .weight = 118.0,
  180. .jockey = "Jane Smith",
  181. .trainer = "Mark Trainer",
  182. .owner = "Blue Stable",
  183. .pastPerformanceCount = 2,
  184. .pastPerformances = {
  185. {102, 2, 91.2, SLOW},
  186. {103, 3, 92.8, MUDDY}
  187. }
  188. }
  189. }
  190. };
  191.  
  192. addRace(&program, race1);
  193. printProgram(&program);
  194.  
  195. return 0;
  196. }
  197.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Race Program for 2024-12-15 at Dublin Racecourse:
Race 1:
Race ID: 1
Name: Irish Nationals
Distance: 8.00 furlongs
Surface: 1
Condition: 0
Type: 3
Number of Horses: 2
  Horse 1: Lucky Charm (Jockey: John Doe)
  Horse 2: Emerald Star (Jockey: Jane Smith)