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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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;
}

Add a comment
Know the answer?
Add Answer to:
in C PROGRAM but the techniques required are common for many real-world data situations. Input Data...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Football Game Scores Write a C++ program that stores the following data about a football game...

    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...

    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...

    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...

    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...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT