Question

In: Computer Science

C Programming The score table will be printed by reading the match information made between the...

C Programming

The score table will be printed by reading the match information made between the teams.

It is not known how many teams. The team information will be kept in a dynamically changed memory area as the new team enters. The match list should also be kept in a dynamic area that is recorded as new match information is entered.

There should be 2 structs in the program.

Mac struct: Consists of 1st team name, 2nd team name, 1st team goal, 2nd team goal information.

Team struct: consists of team name (one word, 20), number of wins, number of draws, number of defeats, number of goals scored, number of goals eaten, point.

Example input: abc xyz 3 1 (Information will be entered completely and correctly.)

A single line of match information, with a space between them, 1 Team name, 2 Team name, 1.

The goal scored by the team will be entered as the goal scored by the 2nd team. In the case where the above example is the first match information entered for these teams, two teams will be identified in the abc and xyz names, and will be added to the team list, since there are no teams defined in these names yet. At the same time, a match struct will be defined, this match struct will be added to the match list, and all information of both teams in the team struct will be updated with this match information.

If the above example is not the first match information entered about the abc and xyz teams, since both teams will be defined before, these teams will be found in the teams list and their relevant information will be updated.

In summary, for the above entry, if the team has not yet been identified in these names, both teams will be identified and added to the team list. The number of victories of the ABC team will be increased by one, the number of goals scored will be increased by 3, the number of goals scored will be increased by 1, and the score will be increased by 3. The xyz team's number of defeats will be increased by 1, the goal scored will be increased by 1, the goal it has scored will be increased by 3, its score will be reduced by 1. (wins 3 points, draw 1 point, defeat -1 point). The match struct will be added to the match list.

After entering the match information, the scoreboard will be printed.

Scoreboard: The information in the team struct will be printed one after the other in the order given in the description. The scoreboard should be in descending order according to the score. In case of score equality, the team with a high average score (goals scored and goals scored) should be on the top. It can be assumed that the score and average will not be equal teams.

After the scoreboard is printed, the user will receive a sequence number from 1-teamnumber, and the matches of the team in the row entered will be listed. Unless -1 is entered, the sequence number will be read again after printing the information of a tool, and the program will end when -1 is entered. If a number between 1-teamnumber or an entry other than -1 has been made, an appropriate message will be given and the entry will be waited again.

Solutions

Expert Solution

Program:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

//structure of score table
typedef struct ScoreTable
{
char team1[20];
char team2[20];
int team1score;
int team2score;
}stable;

//structure of league table
typedef struct LeagueTable
{
char team[20];
int win;
int draw;
int loss;
int points;
int average;
int goals;
}ltable;

//load the score table
int LoadScoreTable(char fname[], stable t[])
{
FILE *f;
//open the file
f = fopen(fname, "r");
//check if file not exist
if(f==NULL)
{
printf("File not exist!");
exit(1);
}
int i=0, n;
//read the file contents
while(1)
{
fscanf(f, "%s", t[i].team1);
if(feof(f)) break;
fscanf(f, "%s", t[i].team2);
fscanf(f, "%d", &t[i].team1score);
fscanf(f, "%d", &t[i].team2score);
i++;
}

n = i;
printf("Score Table:\n");
printf("Team1 Team2 Team1Score Team2Score\n");
printf("-------------------------------------------------------\n");
//display the table
for(i=0; i<n; i++)
{
printf("%-15s%-15s%-15d%-15d\n", t[i].team1, t[i].team2, t[i].team1score, t[i].team2score);
}

fclose(f);
return n;
}

//create the league table
ltable* createLeagueTable(stable st[], int n)
{
int i, j = 0;

//allocate memory for league table
ltable *lt = (ltable*)malloc(sizeof(ltable)*(2*n));
//initialization
for(i=0; i<2*n; i++)
{
lt[i].win = 0;
lt[i].draw = 0;
lt[i].loss = 0;
lt[i].points = 0;
lt[i].average = 0;
lt[i].goals = 0;
}

for(i=0; i<n; i++)
{
strcpy(lt[j].team, st[i].team1);
strcpy(lt[j+1].team, st[i].team2);

if(st[i].team1score>st[i].team2score){
lt[j].win++; lt[j].points+=3;
lt[j+1].loss++;
}
else if(st[i].team1score<st[i].team2score){
lt[j].loss++;
lt[j+1].win++; lt[j+1].points+=3;
}
else{
lt[j].draw++; lt[j].points++;
lt[j+1].draw++; lt[j+1].points++;
}
lt[j].average += st[i].team1score - st[i].team2score;
lt[j+1].average += st[i].team2score - st[i].team1score;

lt[j].goals += st[i].team1score;
lt[j+1].goals += st[i].team2score;

j+=2;
}

return lt;
}

//arrange the league table
void OrderLeagueTable(ltable lt[], int n)
{
ltable t;
int i, j;
for(i=0; i<n-1; i++)
{
for(j=i+1; j<n; j++)
{
if((lt[i].points<lt[j].points) || (lt[i].points==lt[j].points && lt[i].goals<lt[j].goals))
{
t = lt[i];
lt[i] = lt[j];
lt[j] = t;
}
}
}
}

//display league table
void DisplayLeagueTable(ltable lt[], int n)
{
int i;

printf("No. Team Win Draw Loss Points Average Goals\n");
printf("-------------------------------------------------------------------------\n");
//print the league table
for(i=0; i<n; i++)
{
printf("%-4d%-15s%-10d%-10d%-10d%-10d%-10d%-10d\n", i+1, lt[i].team, lt[i].win,
lt[i].draw,lt[i].loss,lt[i].points,lt[i].average,lt[i].goals);
}
}

//main function
void main()
{
stable st[20];
ltable *lt;
int m, n, k, p;
char team[20];

//load score table
n = LoadScoreTable("scoretable.txt", st);
//create league table
lt = createLeagueTable(st, n);
m = 2*n;
//arrange league table
OrderLeagueTable(lt, m);
printf("\nScore Board:\n");
//display league table
DisplayLeagueTable(lt, m);

while(1)
{
//prompt to enter E for exit or S for search
printf("\nPress -1 for exit or 1-6 for search: ");
scanf("%d", &p);

if(p == -1) return;
p--;
printf("Team Win Draw Loss Points Average Goals\n");
printf("%-15s%-10d%-10d%-10d%-10d%-10d%-10d\n", lt[p].team, lt[p].win,
lt[p].draw,lt[p].loss,lt[p].points,lt[p].average,lt[p].goals);
}
}

input File: scoretable.txt

Galatasaray Besiktas 2 3
Fenerbahce Denixlispor 0 0
Alanyaspar Trabzonspor 1 5
Rizespor Konyaspor 0 1
Gaztepe Antalyaspor 1 1

Output:


Related Solutions

A table tennis match is played between Jack and Rose. The winner of the match is...
A table tennis match is played between Jack and Rose. The winner of the match is the one who first wins 4 games in total, and in any game the winner is the one who first scores 11 points. Note that in an individual game, if the score is 10 to 10, the game goes into extra play (called deuce) until one player has gained a lead of 2 points. Let p be the probability that Rose wins a point...
C Programming Debug -> error: expected expression before 'score' typedef enum LetterGrade {     A =...
C Programming Debug -> error: expected expression before 'score' typedef enum LetterGrade {     A = 4,     B = 3,     C = 2,     D = 1,     F = 0 } score; score getLetterGradeFromAverage(const double avg) {     if (avg >= 90)         return score::A;         // error here     else if (avg >= 80)         return score::B;        // error here     else if (avg >= 70)         return score::C;       // error here     else if (avg >=...
Write a code in C or C++ programming language that generates the hexadecimal values in Table...
Write a code in C or C++ programming language that generates the hexadecimal values in Table 6-2 in the same format. Table 6-2 Hexadecimal text file specifying the contents of a 4 × 4 multiplier ROM. 00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 20: 00 02 04 06 08 0A 0C 0E 10...
1.What is the relationship between the LSD and a Z score? (R programming Language) Write a...
1.What is the relationship between the LSD and a Z score? (R programming Language) Write a fragment of code comparing how both would be computed. Use the Z score for the standard error of a mean, $z_i = (x_i - \mu)/(\sigma / \sqrt(n))$ 2. How would you modify the calculations of LSD to produce Tukey's Honest Signficant Difference?
Match the side effects to the receptor Using the supplied table, complete the information that is...
Match the side effects to the receptor Using the supplied table, complete the information that is missing. Explain what clinical side effects would be presented using anti-depressant medication that blocks/antagonises that particular receptor or transporter. NOTE: Only focus on blocking (Antagonising) the receptor/transporter Blocking Receptor/Transporter Possible clinical Side Effects/Benefits SERT Monoamine transporter Serotonin reuptake transporter Transporter Increase the Serotonin around synaptic axonal end NET Monoamine Transporter Noradrenaline reuptake transporter Bring stuff back to the neuron 5HT2A GPCR Post synaptic receptor...
What is different between procedural and object-oriented programming? Match each of the following OOP concepts with...
What is different between procedural and object-oriented programming? Match each of the following OOP concepts with its example/description. Question 2 options: 12345678 Providing a way for an entity to behave in several ways OR providing multiple entities to be treated in a similar way 12345678 A key way of saving having to retype a lot of code for similar but different objects 12345678 The removal of non-essential information 12345678 Allowing which function to be called by an object to be...
PRACTICAL 10 C PROGRAMMING. Question 1 - Reading into a dynamic array. Write a program called...
PRACTICAL 10 C PROGRAMMING. Question 1 - Reading into a dynamic array. Write a program called temperatures01 that reads a (non-empty) sequence maximum daily temperatures. Your program should first ask for the number of temperatures to read and dynamically allocate an array just big enough to hold the number of temperatures you read. You should then read in the elements of the array using a loop. You then should print out the elements of the array in reverse order (from...
c programming Explain the difference between the statements on the left and the statements on the...
c programming Explain the difference between the statements on the left and the statements on the right for each group of statements, give the final value of x if the initial value of x is 1 If (x>=0) x =x +1; Else if (x>=1) x = x+2; If ( x>=0) x = x+1; if (x>= 1) x=x+2;
A contingency table, also called a two-way table, is made up of r rows and c...
A contingency table, also called a two-way table, is made up of r rows and c columns. In general, how many cells are in a contingency table with r rows and c columns? 1) r x c (r times c) 2) (r-1)(c-1) 3) r + c In general, how many degrees of freedom are associated with a contingency table with r rows and c columns? 1) r + c 2) r times c 3) (r-1)(c-1) When should Fishers Exact Test...
Using the Standard Normal Table. What is the probability a z-score is between -1.82 and -0.68?...
Using the Standard Normal Table. What is the probability a z-score is between -1.82 and -0.68? In other words, what is P( -1.82 < z < -0.68)? A. 0.2827 B. 0.0422 C. 0.2139 D. 0.1114
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT