Guest User

Untitled

a guest
Oct 30th, 2017
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. /* Write a 'C' program to compute technical score for the new International
  2. Skating Union Figure Skating scoring system.
  3. Written By: David Bui
  4. davidbui101@hotmail.com
  5. Section # 4
  6. Lab: Monday and Wednesday
  7. Working With: Brendon Gill and Fred Chang
  8. Date: June 13th, 2011
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #define MAX 100
  16.  
  17. //Structure Declarations
  18. typedef struct {
  19. char name [50];
  20. float scale_of_values [8];
  21. int element_and_scores [8][12];
  22. float total_score;
  23. } PERSON;
  24.  
  25. //Function Declarations
  26. char get_data (FILE* fpIn,
  27. PERSON athlete [],
  28. char title [MAX],
  29. int* athlete_number);
  30.  
  31. void calculate (PERSON athlete []);
  32.  
  33. void sort ();
  34. void output ();
  35. void output_file ();
  36.  
  37. //===============================================Starting Main
  38. int main (void)
  39. {
  40. //Local Declarations
  41. FILE* fpIn;
  42. PERSON athlete [MAX];
  43. char title [MAX];
  44. int athlete_number = 0;
  45. //Statements
  46. if((fpIn = fopen("OlympicsMenShort.txt", "r")) == NULL)
  47. {
  48. printf("\nNo Such File!!\n");
  49. system("pause");
  50. exit(100);
  51. }
  52.  
  53. title[MAX] = get_data (fpIn, athlete, title, &athlete_number);
  54. calculate (athlete);
  55. sort ();
  56. output ();
  57. output_file ();
  58.  
  59. printf("The title is not %s\n", title);
  60.  
  61. system("pause");
  62. return 0;
  63. }
  64.  
  65.  
  66. /*====================================================================
  67. This function gets the data from the text file.
  68. Pre:
  69. Post:
  70. */
  71. char get_data (FILE* fpIn,
  72. PERSON athlete [],
  73. char title [MAX],
  74. int* athlete_number)
  75. {
  76. //Local Declarations
  77. char url [MAX];
  78. int i = 0;
  79. int j = 0;
  80. int k = 0;
  81.  
  82. //Statements
  83. //while(!feof(fpIn))
  84. {
  85. fscanf(fpIn, "%[^/]", title);
  86. printf("The title is %s\n", title);
  87. fgets(url, MAX, fpIn);
  88. printf("The url is %s", url);
  89.  
  90. while(!feof(fpIn))
  91. {
  92. fgets(athlete[*athlete_number].name, MAX, fpIn);
  93. for (j = 0; j < 8; j++)
  94. {
  95. fscanf(fpIn, "%d", &athlete[*athlete_number].element_and_scores[j][k]);
  96. fscanf(fpIn, "%f", &athlete[*athlete_number].scale_of_values[j]);
  97. for (k = 1; k <= 12; k++)
  98. {
  99. if(k == 12)
  100. {
  101. fscanf(fpIn, "%d%*c", &athlete[*athlete_number].element_and_scores[j][k]);
  102. }//if statement
  103. else
  104. {
  105. fscanf(fpIn, "%d", &athlete[*athlete_number].element_and_scores[j][k]);
  106. }//else statement
  107. }//for loop
  108. }//for loop
  109. j = 0;
  110. k = 0;
  111. *athlete_number = *athlete_number + 1;
  112. }//while loop
  113.  
  114. }
  115. printf("\n\n");
  116.  
  117.  
  118. j = 0;
  119. k = 0;
  120.  
  121. for (i = 0; i < *athlete_number; i++)
  122. {
  123. printf("The athlete's name is %s", athlete[i].name);
  124. for (j = 0; j < 8; j++)
  125. {
  126. printf("The scale of value is %.1f\n", athlete[i].scale_of_values[j]);
  127. for (k = 1; k <= 12; k++)
  128. {
  129. printf("The element is %i and the score is %d\n", j + 1,
  130. athlete[i].element_and_scores[j][k]);
  131. }
  132. if (j == 7)
  133. {
  134. printf("\n\n");
  135. }
  136. }
  137. }
  138.  
  139. printf("Athlete Number = %d\n", *athlete_number);
  140.  
  141.  
  142. return title[MAX];
  143. }
  144.  
  145.  
  146.  
  147. /*====================================================================
  148. This function calculates the total score.
  149. Pre:
  150. Post:
  151. */
  152. void calculate (PERSON athlete [])
  153. {
  154. //Local Declarations
  155. //Statements
  156.  
  157. return;
  158. }
  159.  
  160.  
  161.  
  162. /*====================================================================
  163. This function sorts the skaters from the highest score to the least.
  164. Pre:
  165. Post:
  166. */
  167. void sort ()
  168. {
  169. //Local Declarations
  170. //Statements
  171.  
  172. return;
  173. }
  174.  
  175.  
  176.  
  177. /*====================================================================
  178. This function outputs the results to stdin.
  179. Pre:
  180. Post:
  181. */
  182. void output ()
  183. {
  184. //Local Declarations
  185. //Statements
  186. printf("\nLab 6: ISU Judging System\n\n");
  187. printf("David Bui\n");
  188. printf("davidbui101@hotmail.com\n");
  189. printf("Section # 4\n");
  190. printf("Lab: Monday and Wednesday\n\n");
  191.  
  192. return;
  193. }
  194.  
  195.  
  196. /*====================================================================
  197. This function outputs the results to a text file called Lab 6.
  198. Pre:
  199. Post:
  200. */
  201. void output_file ()
  202. {
  203. //Local Declarations
  204. FILE* Lab6;
  205.  
  206. //Statements
  207. if((Lab6 = fopen("Lab 6.txt", "w")) == NULL) //opens file to be written.
  208. {
  209. printf("\nNo Such File!!\n");
  210. exit (100);
  211. }
  212.  
  213. fprintf(Lab6, "Lab 6: ISU Judging System\n\n");
  214. fprintf(Lab6, "David Bui\n");
  215. fprintf(Lab6, "davidbui101@hotmail.com\n");
  216. fprintf(Lab6, "Section # 4\n");
  217. fprintf(Lab6, "Lab: Monday and Wednesday\n\n");
  218.  
  219. return;
  220. }
Add Comment
Please, Sign In to add comment