Question

In: Computer Science

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

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.

Solutions

Expert Solution

C++ Code:

#include<iostream>
#include<string>
#include <cstring>
#include <climits>
using namespace std;
struct Horse        //structure of Horse type
{
    char name[20];
    int age;
    int height;
    int time;
};
void input(Horse &obj)      //taking details from user
{
    cout<<"ENTER NAME : ";
    cin.sync();             //clearing buffer
    cin.getline(obj.name,20); 
    cout<<"ENTER AGE : ";
    cin>>obj.age;
    cout<<"ENTER HEIGHT : ";
    cin>>obj.height;
    cout<<"ENTER TIME IN PREVIOUS RACE : ";
    cin>>obj.time;
}   
void output(Horse obj)      //Printing details from user
{
    cout<<"NAME : ";
    cout<<obj.name;
    cout<<" | AGE : ";
    cout<<obj.age;
    cout<<" | HEIGHT : ";
    cout<<obj.height;
    cout<<" | TIME IN PREVIOUS RACE : ";
    cout<<obj.time<<endl;
}
void Max_Display(Horse obj[])   //finding best horse according to previous race
{
    Horse Max;
    int ma=INT_MAX;
    for(int i=0;i<4;i++)
    {
        if(obj[i].time<ma)
        {
            ma=obj[i].time;
            Max=obj[i];
        }
    }
    cout<<"favorite HORSE ACCORDING TO PREVIOUS RACE : ";
    strcpy(Max.name,"favorite");
    output(Max);
}
int main()
{
    Horse arr[4];
    for(int i=0;i<4;i++)
    {
        cout<<"ENTER DETAILS OF HORSE "<<i+1<<" : \n";
        input(arr[i]);                                  //input details
        cout<<"-----------------------------"<<endl;
        output(arr[i]);                                  //printing details
        cout<<"-----------------------------"<<endl;
    }   
    Max_Display(arr);                                   //finding Best Horse
    return 0;
}

Output:

If you have any doubt feel free to ask and if you like the answer please upvote it .

Thanks


Related Solutions

A horse race contains 8 horses. If you wished to bet on every possible top three...
A horse race contains 8 horses. If you wished to bet on every possible top three finishes (first, second, and third place), how many bets would you need to place? The following represents a binomial experiment. Seven plants are operated by a garment manufacturer in seven different countries. There is a 10% chance of strike at any time. It is also believed that strikes at one plant do not influence strikes at any other plant (because these are in third...
How has race, class, and gender changed since the 17th century? What is race, class, and...
How has race, class, and gender changed since the 17th century? What is race, class, and gender now in the 21st century?
Your grandmother has been putting $3000 into a savings account on every birthday since your first...
Your grandmother has been putting $3000 into a savings account on every birthday since your first (that is, when you turned 1). The account pays an interest rate of 3% per year. How much money will be in the account on your 18th birthday immediately after your grandmother makes the deposit on that birthday? (Please write numbers only, no "$", no ",", round to the dollar, no decimal.  i.e. write  $1,234.56 as 1235)
Your grandmother has been putting $3000 into a savings account on every birthday since your first...
Your grandmother has been putting $3000 into a savings account on every birthday since your first (that is, when you turned 1). The account pays an interest rate of 3% per year. How much money will be in the account on your 18th birthday immediately after your grandmother makes the deposit on that birthday? (Please write numbers only, no "$", no ",", round to the dollar, no decimal.  i.e. write  $1,234.56 as 1235)
Your grandmother has been putting $3000 into a savings account on every birthday since your first...
Your grandmother has been putting $3000 into a savings account on every birthday since your first (that is, when you turned 1). The account pays an interest rate of 3% per year. How much money will be in the account on your 18th birthday immediately after your grandmother makes the deposit on that birthday? (Please write numbers only, no "$", no ",", round to the dollar, no decimal.  i.e. write  $1,234.56 as 1235)
Your grandma has been putting 1000 into a savings account on every bday since your first(that...
Your grandma has been putting 1000 into a savings account on every bday since your first(that is, when you turned 1). The account pays an interest rate of 3%. How much money will be in the account on your 18th birthday after you gma makes the deposit on that birthday?
There has been an annual 3.1% prevalence of Zika virus in South American countries since 1947....
There has been an annual 3.1% prevalence of Zika virus in South American countries since 1947. Only 1% of all cases resulted in any DALY count (all cases, any year). In 2015, clinicians observed increased microcephaly among children born to women who had been ill from Zika within the last 12 months. A new screening test was developed with more sensitivity to understand the rate ofZika among women ages 20-35 in three South American countries. It can detect Zika in...
11- Clampett, Inc., has been an S corporation since its inception. On July 15, 2020, Clampett,...
11- Clampett, Inc., has been an S corporation since its inception. On July 15, 2020, Clampett, Inc., distributed $53,000 to J.D. His basis in his Clampett, Inc., stock on January 1, 2020, was $46,000. For 2020, J.D. was allocated $6,000 of ordinary income from Clampett, Inc., and no separately stated items. What is J.D.'s basis in his Clampett, Inc., stock after all transactions in 2020? Multiple Choice $52,000. None of the choices are correct. ($6,000). $46,000. $40,000.
The Precision Parts Corporation manufactures automobile parts. The company has reported a profit every year since...
The Precision Parts Corporation manufactures automobile parts. The company has reported a profit every year since the company's inception in 1980. Management prides itself on this accomplishment and believes one important contributing factor is the company's incentive plan that rewards top management a bonus equal to a percentage of operating income if the operating income goal for the year is achieved. However, 2016 has been a tough year, and prospects for attaining the income goal for the year are bleak....
According to Stuart Hall’s lecture “Race, The Floating Signifier,” race discourse has been used as a...
According to Stuart Hall’s lecture “Race, The Floating Signifier,” race discourse has been used as a way of stabilizing culture. Hall specifically discusses “matter out of place” to illustrate the workings of classification as a system of power. Offer examples (from Stuart Hall, our class discussions, out of class experiences, etc.) that demonstrate how race discourse has perpetuated/maintained the “order” in our culture (in respect to race, intelligence, merit, ability, etc.).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT