#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#define MAX_HORSES 20
#define MAX_RACES 10
#define MAX_NAME_LENGTH 50
#define MAX_TRACK_LENGTH 100
#define MAX_DATE_LENGTH 11 // Format: YYYY-MM-DD
// Enumerated types for track and race conditions
typedef enum {
DIRT,
TURF,
SYNTHETIC
} TrackSurface;
typedef enum {
FAST,
SLOW,
MUDDY,
FIRM,
YIELDING
} TrackCondition;
typedef enum {
MAIDEN,
CLAIMING,
ALLOWANCE,
STAKES,
HANDICAP
} RaceType;
// Structure for a horse's past performance
typedef struct {
int raceID; // Unique ID for the race
int position; // Finishing position
float time; // Time to complete the race TrackCondition condition; // Track condition during the race
} PastPerformance;
// Structure for a horse
typedef struct {
char name[MAX_NAME_LENGTH]; // Horse's name
int age; // Horse's age
float weight; // Horse's weight in pounds
char jockey[MAX_NAME_LENGTH]; // Jockey's name
char trainer[MAX_NAME_LENGTH]; // Trainer's name
char owner[MAX_NAME_LENGTH]; // Owner's name
int pastPerformanceCount; // Number of past performances
PastPerformance pastPerformances[MAX_HORSES]; // Past performance records
} Horse;
// Structure for a race
typedef struct {
int raceID; // Unique race ID
char name[MAX_NAME_LENGTH]; // Name of the race
float distance; // Distance in furlongs
TrackSurface surface; // Track surface
TrackCondition condition; // Track condition
RaceType type; // Type of race
int numHorses; // Number of horses in the race
Horse horses[MAX_HORSES]; // Array of horses
} Race;
// Structure for a racing program
typedef struct {
char date[MAX_DATE_LENGTH]; // Date of the program
char track[MAX_TRACK_LENGTH]; // Track name
int numRaces; // Number of races
Race races[MAX_RACES]; // Array of races
} RacingProgram;
/**************************************************
// Function: initializeProgram
//
// Description: Initializes a RacingProgram with default values.
//
// Parameters: program - pointer to a RacingProgram structure
//
// Returns: void
***************************************************/
void initializeProgram(RacingProgram *program) {
strcpy(program
->date
, "0000-00-00"); strcpy(program
->track
, "Unknown"); program->numRaces = 0;
}
/**************************************************
// Function: addRace
//
// Description: Adds a race to the RacingProgram.
//
// Parameters: program - pointer to a RacingProgram structure
// race - the Race to add
//
// Returns: true if successful, false if program is full
***************************************************/
bool addRace(RacingProgram *program, Race race) {
if (program->numRaces >= MAX_RACES) {
return false; // Program is full
}
program->races[program->numRaces++] = race;
return true;
}
/**************************************************
// Function: printRace
//
// Description: Prints information about a specific race.
//
// Parameters: race - the Race to print
//
// Returns: void
***************************************************/
void printRace(const Race *race) {
printf("Race ID: %d\n", race
->raceID
); printf("Name: %s\n", race
->name
); printf("Distance: %.2f furlongs\n", race
->distance
); printf("Surface: %d\n", race
->surface
); printf("Condition: %d\n", race
->condition
); printf("Type: %d\n", race
->type
); printf("Number of Horses: %d\n", race
->numHorses
); for (int i = 0; i < race->numHorses; i++) {
printf(" Horse %d: %s (Jockey: %s)\n", i
+ 1, race
->horses
[i
].
name, race
->horses
[i
].
jockey); }
}
/**************************************************
// Function: printProgram
//
// Description: Prints all races in the RacingProgram.
//
// Parameters: program - pointer to the RacingProgram structure
//
// Returns: void
***************************************************/
void printProgram(const RacingProgram *program) {
printf("Race Program for %s at %s:\n", program
->date
, program
->track
); for (int i = 0; i < program->numRaces; i++) {
printRace(&program->races[i]);
}
}
// Example usage
int main() {
RacingProgram program;
initializeProgram(&program);
strcpy(program.
date, "2024-12-15"); strcpy(program.
track, "Dublin Racecourse");
Race race1 = {
.raceID = 1,
.name = "Irish Nationals",
.distance = 8.0,
.surface = TURF,
.condition = FAST,
.type = STAKES,
.numHorses = 2,
.horses = {
{
.name = "Lucky Charm",
.age = 4,
.weight = 120.5,
.jockey = "John Doe",
.trainer = "Jane Trainer",
.owner = "Green Stable",
.pastPerformanceCount = 1,
.pastPerformances = {
{101, 1, 89.5, FAST}
}
},
{
.name = "Emerald Star",
.age = 3,
.weight = 118.0,
.jockey = "Jane Smith",
.trainer = "Mark Trainer",
.owner = "Blue Stable",
.pastPerformanceCount = 2,
.pastPerformances = {
{102, 2, 91.2, SLOW},
{103, 3, 92.8, MUDDY}
}
}
}
};
addRace(&program, race1);
printProgram(&program);
return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ogICAgVHJhY2tDb25kaXRpb24gY29uZGl0aW9uOyAgICAgICAgICAgLy8gVHJhY2sgY29uZGl0aW9uCiAgICBSYWNlVHlwZSB0eXBlOyAgICAgICAgICAgICAgICAgICAgICAvLyBUeXBlIG9mIHJhY2UKICAgIGludCBudW1Ib3JzZXM7ICAgICAgICAgICAgICAgICAgICAgIC8vIE51bWJlciBvZiBob3JzZXMgaW4gdGhlIHJhY2UKICAgIEhvcnNlIGhvcnNlc1tNQVhfSE9SU0VTXTsgICAgICAgICAgIC8vIEFycmF5IG9mIGhvcnNlcwp9IFJhY2U7CgovLyBTdHJ1Y3R1cmUgZm9yIGEgcmFjaW5nIHByb2dyYW0KdHlwZWRlZiBzdHJ1Y3QgewogICAgY2hhciBkYXRlW01BWF9EQVRFX0xFTkdUSF07ICAgICAgICAgLy8gRGF0ZSBvZiB0aGUgcHJvZ3JhbQogICAgY2hhciB0cmFja1tNQVhfVFJBQ0tfTEVOR1RIXTsgICAgICAgLy8gVHJhY2sgbmFtZQogICAgaW50IG51bVJhY2VzOyAgICAgICAgICAgICAgICAgICAgICAgLy8gTnVtYmVyIG9mIHJhY2VzCiAgICBSYWNlIHJhY2VzW01BWF9SQUNFU107ICAgICAgICAgICAgICAvLyBBcnJheSBvZiByYWNlcwp9IFJhY2luZ1Byb2dyYW07CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKLy8gRnVuY3Rpb246IGluaXRpYWxpemVQcm9ncmFtCi8vCi8vIERlc2NyaXB0aW9uOiBJbml0aWFsaXplcyBhIFJhY2luZ1Byb2dyYW0gd2l0aCBkZWZhdWx0IHZhbHVlcy4KLy8KLy8gUGFyYW1ldGVyczogcHJvZ3JhbSAtIHBvaW50ZXIgdG8gYSBSYWNpbmdQcm9ncmFtIHN0cnVjdHVyZQovLwovLyBSZXR1cm5zOiAgICB2b2lkCioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8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ICAgLndlaWdodCA9IDEyMC41LAogICAgICAgICAgICAgICAgLmpvY2tleSA9ICJKb2huIERvZSIsCiAgICAgICAgICAgICAgICAudHJhaW5lciA9ICJKYW5lIFRyYWluZXIiLAogICAgICAgICAgICAgICAgLm93bmVyID0gIkdyZWVuIFN0YWJsZSIsCiAgICAgICAgICAgICAgICAucGFzdFBlcmZvcm1hbmNlQ291bnQgPSAxLAogICAgICAgICAgICAgICAgLnBhc3RQZXJmb3JtYW5jZXMgPSB7CiAgICAgICAgICAgICAgICAgICAgezEwMSwgMSwgODkuNSwgRkFTVH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgLm5hbWUgPSAiRW1lcmFsZCBTdGFyIiwKICAgICAgICAgICAgICAgIC5hZ2UgPSAzLAogICAgICAgICAgICAgICAgLndlaWdodCA9IDExOC4wLAogICAgICAgICAgICAgICAgLmpvY2tleSA9ICJKYW5lIFNtaXRoIiwKICAgICAgICAgICAgICAgIC50cmFpbmVyID0gIk1hcmsgVHJhaW5lciIsCiAgICAgICAgICAgICAgICAub3duZXIgPSAiQmx1ZSBTdGFibGUiLAogICAgICAgICAgICAgICAgLnBhc3RQZXJmb3JtYW5jZUNvdW50ID0gMiwKICAgICAgICAgICAgICAgIC5wYXN0UGVyZm9ybWFuY2VzID0gewogICAgICAgICAgICAgICAgICAgIHsxMDIsIDIsIDkxLjIsIFNMT1d9LAogICAgICAgICAgICAgICAgICAgIHsxMDMsIDMsIDkyLjgsIE1VRERZfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfTsKCiAgICBhZGRSYWNlKCZwcm9ncmFtLCByYWNlMSk7CiAgICBwcmludFByb2dyYW0oJnByb2dyYW0pOwoKICAgIHJldHVybiAwOwp9Cg==