Question

In: Computer Science

1. Competitors The results of a running competition are shown in the table below. Index Name...

1. Competitors

The results of a running competition are shown in the table below.

Index Name Birthdate Rank
0 Am, Erica 1984. 05. 06. 1
1 Abnorm, Al 1982. 09. 30. 3
2 Pri, Mary 1988. 08. 25. 2
3 Duck, Ling 1979. 06. 10. 5
4 Mac, Donald 1992. 04. 05. 4

Find an unfinished program below that contains the appropriate types and the above data in an array. Complete the program, step-by-step, according to the comments.

#include <stdio.h>
 
typedef struct Date {
    int year, month, day;
} Date;
 
typedef struct Competitor {
    char name[31];
    Date birth;
    int rank;
} Competitor;
 
void Date_print(Date d);
 
void Competitor_print(Competitor c);
 
int main() {
    Competitor competitors[5] = {
        { "Am, Erica", {1984, 5, 6}, 1 },
        { "Abnorm, Al", {1982, 9, 30}, 3 },
        { "Pri, Mary", {1988, 8, 25}, 2 },
        { "Duck, Ling", {1979, 6, 10}, 5 },
        { "Mac, Donald", {1992, 4, 5}, 4 },
    };
 
    /* name of competitor 0 - printf %s */
    /* rank of competitor 2 */
    /* birth date of competitor 4, use the given function */
    /* the first letter of the name of competitor 1 (a string is an array of characters) */
    /* is competitor 1 among the best three? yes/no, may use ?: operator */
    /* is competitor 4 faster than competitor 3? */
    /* was competitor 1 born in the same year as competitor 2? */
    /* complete the Competitor_print() function,
     * then print all data of competitor 1 */
    /* at last print all data of all competitors. */
 
    return 0;
}
 
void Date_print(Date d) {
    /* print year, month and day */
}
 
void Competitor_print(Competitor c) {
    /* print all data of the competitor */
}

Solutions

Expert Solution

#include <stdio.h>

typedef struct Date {
int year, month, day;
} Date;

typedef struct Competitor {
char name[31];
Date birth;
int rank;
} Competitor;

void Date_print(Date d);

void Competitor_print(Competitor c);

int main() {
Competitor competitors[5] = {
{ "Am, Erica", {1984, 5, 6}, 1 },
{ "Abnorm, Al", {1982, 9, 30}, 3 },
{ "Pri, Mary", {1988, 8, 25}, 2 },
{ "Duck, Ling", {1979, 6, 10}, 5 },
{ "Mac, Donald", {1992, 4, 5}, 4 },
};

/* name of competitor 0 - printf %s */
printf("Name of competitor 0: %s\n",competitors[0].name);

/* rank of competitor 2 */
printf("Rank of competitor 2: %d\n",competitors[2].rank);

/* birth date of competitor 4, use the given function */
printf("Birth date of competitor 4: ");
Date_print(competitors[4].birth);

/* the first letter of the name of competitor 1 (a string is an array of characters) */
printf("The first letter of the name of competitor 1: %c\n",competitors[1].name[0]);

/* is competitor 1 among the best three? yes/no, may use ?: operator */
printf("Is competitor 1 among the best three? ");
competitors[1].rank <= 3 ? printf("yes\n"): printf("no\n");

/* is competitor 4 faster than competitor 3? */
printf("Is competitor 4 faster than competitor 3? ");
competitors[4].rank < competitors[3].rank ? printf("yes\n"): printf("no\n");

/* was competitor 1 born in the same year as competitor 2? */
printf("Was competitor 1 born in the same year as competitor 2? ");
competitors[1].birth.year == competitors[2].birth.year ? printf("yes\n"): printf("no\n");

/* then print all data of competitor 1 */
printf("Competitor 1:\n");
Competitor_print(competitors[1]);

/* at last print all data of all competitors. */
printf("Details of all competitor:\n");
for(int i=0;i<5;i++)
Competitor_print(competitors[i]);

return 0;
}

// function to display input Date d
void Date_print(Date d) {
printf("%d/%d/%d\n",d.day,d.month,d.year);
}

// function to display all details of Competitor c
void Competitor_print(Competitor c) {
printf("Name: %s, Rank: %d, Date: %d/%d/%d\n",c.name, c.rank, c.birth.day, c.birth.month, c.birth.year);
}

//end of program

Output:


Related Solutions

In the following table, the profits from a duopoly model of competition are shown. Firms 1...
In the following table, the profits from a duopoly model of competition are shown. Firms 1 and 2 simultaneously choose the quantity of outputs to produce. Each firm is restricted to producing 25, 35, 50 or 100 units of output. Is there a Nash equilibrium? What is it? Briefly explain. Firm 2 Q2 = 25 35 50 100 Q1 = 25 125, 125 100, 140 63, 125 -63, -250 Firm 1 35 140, 100 105, 105 53, 75 -123, -350...
What is the IUPAC name for the compound shown below?
What is the IUPAC name for the compound shown below? Spelling and punctuation count!
Results from a civil servant exam are shown in the table to the right. Is there...
Results from a civil servant exam are shown in the table to the right. Is there sufficient evidence to support the claim that the results from the test are​ discriminatory? Use a 0.01 significance level. Passed Failed White candidates 15 13 Minority candidates 9 22
A study was done on proctored and nonproctored tests. The results are shown in the table....
A study was done on proctored and nonproctored tests. The results are shown in the table. Assume that the two samples are independent simple random samples selected from normally distributed​ populations, and do not assume that the population standard deviations are equal. Complete parts​ (a) and​ (b) below. Use a 0.05 significance level for both parts. The test​ statistic, t, is
Results from a civil servant exam are shown in the table to the right. Is there...
Results from a civil servant exam are shown in the table to the right. Is there sufficient evidence to support the claim that the results from the test are​ discriminatory? Use a 0.05 significance level. passed failed white candidates 20 15 minority candidates 9 26
1. Using the information in the table below, calculate the Index of Segregation by occupation. Interpret...
1. Using the information in the table below, calculate the Index of Segregation by occupation. Interpret the index number that you calculated and provide an explanation of it's meaning. Occupation Men Women Managerial 11,005 9,387 Professional and Technical 12,063 13,952 Sales 7,601 6,953 Clerical/Administrative 3,751 14,128 Service 6.465 10,066 Production/Craft 13,516 1,283 Operatives 9,302 3,007 Laborers 3,631 1,011 Total 67,334 59,787 **Note: All numbers are in thousands** 2. Carefully explain the two broad potential causes for the extent of gender...
he results of ANOVA test are summarized in Table 1. Table 1. Shows the results of...
he results of ANOVA test are summarized in Table 1. Table 1. Shows the results of ANOVA for three different procedures Source Sum of Square d.f Mean Square F Between 160.13 80.97 9.17 Within (error) 104.80 8.73 Total 264.93 14 The degrees of freedom for between and within are: Select one: A. 1 and 13 respectively B. 2 and 12 respectively C. 3 and 11 respectively D. 4 and 10 respectively QUESTION 42 Not yet answered Marked out of 2.00...
1. The experimental results in the table below represent real values from an experiment on the...
1. The experimental results in the table below represent real values from an experiment on the cat soleus muscle. For our purposes we will assume the muscle weighs 4 grams and is shaped like a cylinder that is 1 cm2 in cross-sectional area. Force                                                            Power Velocity Experiment # Force (N) Velocity (mm/s) 1 20 0 2 18 2 3 14 9 4 9 20 5 6 29 6 3 43 7 1.0 62 2. a Draw and label the...
1. Provide a description of competition. 2.What is the value of positioning in relationship to competitors?
1. Provide a description of competition. 2.What is the value of positioning in relationship to competitors?
Using these results, complete the table below and then use your results to answer the questions...
Using these results, complete the table below and then use your results to answer the questions that follow. (Please remember to round all answers to two decimal places: 0.00 at each step.) (23 points) X X-M (X-M)2 1 14 -15.85 251.22 2 16 -13.85 191.82 3 18 -11.85 140.42 4 20 -9.85 97.02 5 23 -6.85 46.92 6 23 -6.85 46.92 7 25 -4.85 23.52 8 27 -2.85 8.12 9 28 -1.85 3.42 10 29 -0.85 0.72 11 30 0.15...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT