Guest User

Untitled

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