Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a 'C' program to compute technical score for the new International
- Skating Union Figure Skating scoring system.
- Written By: David Bui
- davidbui101@hotmail.com
- Section # 4
- Lab: Monday and Wednesday
- Working With: Brendon Gill and Fred Chang
- Date: June 13th, 2011
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX 100
- //Structure Declarations
- typedef struct {
- char name [50];
- float scale_of_values [8];
- int element_and_scores [8][12];
- float total_score;
- } PERSON;
- //Function Declarations
- char get_data (FILE* fpIn,
- PERSON athlete [],
- char title [MAX],
- int* athlete_number);
- void calculate (PERSON athlete []);
- void sort ();
- void output ();
- void output_file ();
- //===============================================Starting Main
- int main (void)
- {
- //Local Declarations
- FILE* fpIn;
- PERSON athlete [MAX];
- char title [MAX];
- int athlete_number = 0;
- //Statements
- if((fpIn = fopen("OlympicsMenShort.txt", "r")) == NULL)
- {
- printf("\nNo Such File!!\n");
- system("pause");
- exit(100);
- }
- title[MAX] = get_data (fpIn, athlete, title, &athlete_number);
- calculate (athlete);
- sort ();
- output ();
- output_file ();
- printf("The title is not %s\n", title);
- system("pause");
- return 0;
- }
- /*====================================================================
- This function gets the data from the text file.
- Pre:
- Post:
- */
- char get_data (FILE* fpIn,
- PERSON athlete [],
- char title [MAX],
- int* athlete_number)
- {
- //Local Declarations
- char url [MAX];
- int i = 0;
- int j = 0;
- int k = 0;
- //Statements
- //while(!feof(fpIn))
- {
- fscanf(fpIn, "%[^/]", title);
- printf("The title is %s\n", title);
- fgets(url, MAX, fpIn);
- printf("The url is %s", url);
- while(!feof(fpIn))
- {
- fgets(athlete[*athlete_number].name, MAX, fpIn);
- for (j = 0; j < 8; j++)
- {
- fscanf(fpIn, "%d", &athlete[*athlete_number].element_and_scores[j][k]);
- fscanf(fpIn, "%f", &athlete[*athlete_number].scale_of_values[j]);
- for (k = 1; k <= 12; k++)
- {
- if(k == 12)
- {
- fscanf(fpIn, "%d%*c", &athlete[*athlete_number].element_and_scores[j][k]);
- }//if statement
- else
- {
- fscanf(fpIn, "%d", &athlete[*athlete_number].element_and_scores[j][k]);
- }//else statement
- }//for loop
- }//for loop
- j = 0;
- k = 0;
- *athlete_number = *athlete_number + 1;
- }//while loop
- }
- printf("\n\n");
- /*
- j = 0;
- k = 0;
- for (i = 0; i < *athlete_number; i++)
- {
- printf("The athlete's name is %s", athlete[i].name);
- for (j = 0; j < 8; j++)
- {
- printf("The scale of value is %.1f\n", athlete[i].scale_of_values[j]);
- for (k = 1; k <= 12; k++)
- {
- printf("The element is %i and the score is %d\n", j + 1,
- athlete[i].element_and_scores[j][k]);
- }
- if (j == 7)
- {
- printf("\n\n");
- }
- }
- }
- */
- printf("Athlete Number = %d\n", *athlete_number);
- return title[MAX];
- }
- /*====================================================================
- This function calculates the total score.
- Pre:
- Post:
- */
- void calculate (PERSON athlete [])
- {
- //Local Declarations
- //Statements
- return;
- }
- /*====================================================================
- This function sorts the skaters from the highest score to the least.
- Pre:
- Post:
- */
- void sort ()
- {
- //Local Declarations
- //Statements
- return;
- }
- /*====================================================================
- This function outputs the results to stdin.
- Pre:
- Post:
- */
- void output ()
- {
- //Local Declarations
- //Statements
- printf("\nLab 6: ISU Judging System\n\n");
- printf("David Bui\n");
- printf("davidbui101@hotmail.com\n");
- printf("Section # 4\n");
- printf("Lab: Monday and Wednesday\n\n");
- return;
- }
- /*====================================================================
- This function outputs the results to a text file called Lab 6.
- Pre:
- Post:
- */
- void output_file ()
- {
- //Local Declarations
- FILE* Lab6;
- //Statements
- if((Lab6 = fopen("Lab 6.txt", "w")) == NULL) //opens file to be written.
- {
- printf("\nNo Such File!!\n");
- exit (100);
- }
- fprintf(Lab6, "Lab 6: ISU Judging System\n\n");
- fprintf(Lab6, "David Bui\n");
- fprintf(Lab6, "davidbui101@hotmail.com\n");
- fprintf(Lab6, "Section # 4\n");
- fprintf(Lab6, "Lab: Monday and Wednesday\n\n");
- return;
- }
Add Comment
Please, Sign In to add comment