Since the file is not available I cannot test the program, but am sure this prog will help you a lot in your assignment. minor changes may be required. Please do co-operate.
#include<stdio.h>
typedef struct tuple {
char *name;
int gw, glr,glo,gls;
int score;
}TeamData;
TeamData* input (char* fileName, int* n) { //for input
FILE* fp = fopen(fileName, "r");
TeamData* tdArray = (TeamData*)malloc(sizeof(TeamData)
* 1000); //atmost 1000 teams expected
char *tempChar, *tempName, *sp = " ";
*n = 0;
while(feof(fp)) { //till the file ends
tempName =
(char*)malloc(sizeof(char)*100); \\temp place to store name
tempName[0]='\0'; \\initialize with
""
while(1) {
fscanf(fp,"%s",tempChar); \\reads a word
if
(tempChar[0]>='0' && tempChar[0]<='9') \\if the word
starts with digit, it is score and not name
break;
strcat(tempName,sp); //if it is a name, concat space
strcat(tempName,
tempChar);//then concat remaining name
}
(tdArray + (*n))->name =
tempName; //store name in the structure
(tdArray + (*n))->gw =
atoi(tempChar); //and also the first numerical coulumn
fscanf(fp,"%d %d %d",
&(tdArray[(*n)].glr), &(tdArray[(*n)].glo),
&(tdArray[(*n)].gls)); //read remaining 3 cols
(*n)++; //increase counter
}
fclose(fp);
}
void computeScore(TeamData* tdArray, int n) { //simple. to
compute score
int i;
for(i=0; i<n; i++)
tdArray[i].score = 2*tdArray[i].gw
+ tdArray[i].glr + tdArray[i].glo + tdArray[i].gls;
}
void sort(TeamData* tdArray, int n) { //simple sorting using qsort
lib. func
int comparator(const void*, const void*);
qsort(tdArray, n, sizeof(TeamData), comparator);
}
int comparator(const void* a, const void* b) { // this function
is used for qsort. You may need to tweak operators here
TeamData* x = (TeamData*)a;
TeamData* y = (TeamData*)b;
if (x->score == y->score)
return strcmp(x->name,
y->name); //u may need to change the ordering here!
return x->score - y->score; //change
may be required here!
}
void disp(TeamData* tdArray, int n) { //function to display
tabular data including score
int i;
printf("Name\tWon\tL in RT\tL in OT\tL in
SO\n");
for(i=0; i<n; i++)
printf("%s\t%d\t%d\t%d\t%d\n",tdArray[i].name,tdArray[i].gw,tdArray[i].glr,tdArray[i].glo,
tdArray[i].gls, tdArray[i].score);
}
int main() {
//get file name from user
//store data in array by calling input
//TeamData* array = input(filename, &n); //n will
store count
//count score here
//disp
//sort
//disp again
return 0;
}
in C PROGRAM but the techniques required are common for many real-world data situations. Input Data...
Football Game Scores Write a C++ program that stores the following data about a football game in a structure: Field Name Description visit_team string (name of visiting team) home_score int visit_score int The program should read the number of games from a data file named “games.txt”, dynamically allocate an array of structures for the games using one structure for each game, and then read the information for each game from the same file (visiting team, home score, visiting team’s score)....
Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D array of integers which is 10x10. 2. Prints out the contents of the 2D array after assigning the data to make sure correct data was assigned. 3. Figures out and prints out the square root of the sum of ALL the elements in the 2D array. 4. Figures out and prints out the average of ALL THE ELEMENTS in the 2D array. 5. Figures...
This project will allow you to practice with one dimensional arrays, function and the same time review the old material. You must submit it on Blackboard and also demonstrate a run to your instructor. General Description: The National Basketball Association (NBA) needs a program to calculate the wins-losses percentages of the teams. Write a complete C++ program including comments to do the following: Create the following: •a string array that holds the names of the teams •an integer array that...
Write a C++ program with a function to read in the file parts.txt into either parallel vectors or a vector of structs. The data file is on ANGEL in zipped format. The first few lines of the file look like: P-13725 A 23 61.46 P-13726 B 12 51.08 P-13754 D 27 4.56 P-13947 C 34 27.71 Representing part number, Class, On hand balance, cost. After the vector(s) has/have been filled, display a menu which allows the user to request the...
Write a C program for:
One technique for dealing with deadlock is called “detect and
recover.” In this scheme, some procedure is used
to identify when a deadlock occurs, and then another procedure
is used to deal with the blocked processes. One technique to
identify a deadlock is to maintain a resource graph that identifies
all processes, all resources, and the relationships between them
(that is, which processes exclusively own which resources, and
which processes are blocked waiting for which...