Guest User

Untitled

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