Question

Instructions The Durban July is an annual horse race that has been presented every year since...

Instructions

The Durban July is an annual horse race that has been presented every year since 1897. Write a C/C++ program to handle registrations for the race. The program must meet the following specifications:

  • Create a structure (struct) to save the following information for each horse in the race:
    • Name - up to 20 characters;
    • Age - Age in years (integer);
    • Height - The height of the horse in hands (integer); and
    • Time that the horse achieved in the last race in seconds (real value).
  • Create an array of structures (structs) that are used to save the information for four horses. The user types in the information for each horse.
  • After the horse's information is stored in the array, the schedule for the race must be displayed based on the contents of the array. Iterate through the array and display the information on one line for each horse.
  • The horse with the best time for the previous race is named as the favorite. Iterate through the array, identify the horse with the best time and show it at the bottom of the schedule. Assume that each horse's time will be unique.

Homework Answers

Answer #1

#include <stdio.h>
struct horse{
char name[20];
int age;
int height;
float duration;
};
int main()
{
int flag = 0;
int number;
printf("ENter the number of horses");
scanf("%d",&number);
struct horse record[number];
for(int i =0;i<number;i++)
{
printf("Please enter the name of the %d horse",i+1);
scanf("%s",&record[i].name);
printf("Please enter the age of the %d horse",i+1);
scanf("%d",&record[i].age);
printf("Please enter the height of the %d horse",i+1);
scanf("%d",&record[i].height);
printf("Please enter the duration of the %d horse",i+1);
scanf("%f",&record[i].duration);
  
}
printf("The details of the horses are as follows \n");
for(int i =0;i<number;i++)
{
printf("Name = %s,Age = %d,Height = %d,Duration = %f",record[i].name,record[i].age,record[i].height,record[i].duration);
printf("\n");
}
for(int i =0;i<number;i++)
{
if(flag<record[i].duration)
{
flag = i;
}
}
printf("The Favourite horse is \n");
printf("Name = %s,Age = %d,height = %d,Duration = %f",record[flag].name,record[flag].age,record[flag].height,record[flag].duration);
  
return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions