Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in C PROGRAM but the techniques required are common for many real-world data sit

ID: 3798746 • Letter: I

Question

in C PROGRAM

but the techniques required are common for many real-world data situations. Input Data The following data is available in the file WHLdata-txt attached to the assignment on connex. You can open the file in a text editor and then copy and paste the data into the console window when testing your program. This data was captured on Feb. 4. We will test your program using up to date data. There are 22 teams and that will be the same for our test of your program. Brandon Wheat King 23 Calgary Bitmen Edmonton Oil Kings 18 30 Everett silvertips 30 Kamloops Blazers 31 18 23 19 Kootenay Ice 12 Lethbridge Hurricanes 30 Medicine Hat Tigers 36 16 Moose Jaw Warriors 31 14 2B 21 Prince Albert Raiders 13 36 e Cougars 36 Prince Georg Red Deer Rebels 23 21 356 Regina Pats Saskatoon Blades 20 26 Spokane Chiefs 21 22 Swift Current Bronco8 26 17 Tri-City Americans 31 20 Vancouver Giants 17 30 23 19 Victoria Royals Each row of data has a team name and four integers which in order from left to right are the number of games won the number of games lost in regular time the number of games lost in overtime the number of games lost in a shootout Note that the data is in alphabetical order of team name. Programming Task You are to write a C program that 1. inputs this data 2. computes the number of points for each team which2for each win plus 1 for each overtime loss plus l for each

Explanation / Answer

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]=''; \initialize with ""
       while(1) {
           fscanf(fp,"%s",tempChar); eads 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 Won L in RT L in OT L in SO ");
   for(i=0; i<n; i++)
       printf("%s %d %d %d %d ",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;
}