Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1. (* auto eval 8.2 *)
  2.  
  3. #use "AP1utilbis.ml";;
  4. type t_judoka = {name : string; birth_year : int; licence_number : int; weight : float};;
  5.  
  6. (* On définie un type Judoka avec les caractéristiques requises *)
  7.  
  8. let get_judoka_name() : string =
  9. let name : string ref = ref "" in
  10. while !name = ""
  11. do
  12. print_string("Veuillez entrer le nom du judoka : ") ;
  13. name := read_line() ;
  14. done ;
  15. !name
  16. ;;
  17.  
  18. let get_judoka_birth_year() : int =
  19. let birth_year : int ref = ref 0 in
  20. while !birth_year <> 2003 && !birth_year <> 2004 && !birth_year <> 2005
  21. do
  22. print_string("Veuillez entrer l'âge de naissance du judoka : ") ;
  23. birth_year := read_int() ;
  24. done ;
  25. !birth_year
  26. ;;
  27.  
  28. let get_judoka_licence_number() : int =
  29. let number : int ref = ref 0 in
  30. while !number = 0
  31. do
  32. print_string("Veuillez entrer le numéro de licence : ") ;
  33. number := read_int() ;
  34. done ;
  35. !number
  36. ;;
  37.  
  38. let get_judoka_weight() : float =
  39. let weight : float ref = ref 0. in
  40. while !weight <= 0.
  41. do
  42. print_string("Veuillez entrer le poids du judoka : ") ;
  43. weight := read_float() ;
  44. done ;
  45. !weight
  46. ;;
  47.  
  48. (* J'ai créé une fonction auxiliaire pour chaque caractéristique de get judoka *)
  49.  
  50. let get_judoka() : t_judoka =
  51. {name = get_judoka_name(); birth_year = get_judoka_birth_year(); licence_number = get_judoka_licence_number(); weight = get_judoka_weight()}
  52. ;;
  53.  
  54. (* On a ensuite juste a demander chaque fonction auxilaire *)
  55.  
  56. let registration_tab : int array =
  57. arr_make(9,0)
  58. ;;
  59.  
  60. let registration(judoka, registration_tab) : unit =
  61. if judoka.weight <= 46.
  62. then registration_tab.(0) <- registration_tab.(0) + 1
  63. else if judoka.weight <= 50.
  64. then registration_tab.(1) <- registration_tab.(1) + 1
  65. else if judoka.weight <= 55.
  66. then registration_tab.(2) <- registration_tab.(2) + 1
  67. else if judoka.weight <= 60.
  68. then registration_tab.(3) <- registration_tab.(3) + 1
  69. else if judoka.weight <= 66.
  70. then registration_tab.(4) <- registration_tab.(4) + 1
  71. else if judoka.weight <= 73.
  72. then registration_tab.(5) <- registration_tab.(5) + 1
  73. else if judoka.weight <= 81.
  74. then registration_tab.(6) <- registration_tab.(6) + 1
  75. else if judoka.weight <= 90.
  76. then registration_tab.(7) <- registration_tab.(7) + 1
  77. else registration_tab.(8) <- registration_tab.(8) + 1
  78. ;;
  79.  
  80. (* On ajoute 1 à la catégorie correspondante au judoka *)
  81.  
  82. let get_registration() : int array =
  83. let finish : string ref = ref "" in
  84. while !finish <> "yes"
  85. do
  86. registration(get_judoka(), registration_tab);
  87. print_string("Do you have finish the registration ? (yes only)") ;
  88. finish := read_line();
  89. done ;
  90. registration_tab
  91. ;;
  92.  
  93. (* On enregistre des judokas et à chaque judoka on demande si la personne a fini, si elle n'a pas fini cela recommence, à noter que cela ne s'arrête que si la personne met "yes" *)
  94.  
  95. let grouping(registration_tab) : int array =
  96. if registration_tab.(1) < 3 || registration_tab.(2) < 3 || registration_tab.(3) < 3 || registration_tab.(4) < 3 || registration_tab.(5) < 3 || registration_tab.(6) < 3 || registration_tab.(7) < 3
  97. then failwith "Not enough members"
  98. else (if registration_tab.(0) < 3
  99. then (
  100. registration_tab.(1) <- registration_tab.(0) + registration_tab.(1) ;
  101. registration_tab.(0) <- 0 ;
  102. )) ;
  103. (if registration_tab.(8) < 3
  104. then (
  105. registration_tab.(7) <- registration_tab.(7) + registration_tab.(8) ;
  106. registration_tab.(8) <- 0 ;
  107. )) ;
  108. registration_tab ;;
  109.  
  110. (* Alors c'est le bordel mais ça marche ! Je check d'abord si y'a une catégorie à moins de 3, ensuite si elle se trouve entre 1 et 7, si oui alors ça renvoie un failwith, et sinon ça renvoie registration_tab mais avec des modifications, si c'est la première case (0) alors ça ajoute la première case à la deuxième, et pareil pour la dernière. *)
  111.  
  112. let category(judoka, tab : t_judoka*int array) : string =
  113. let grouped : int array = grouping(tab) in
  114. if grouped.(0) = 0 && judoka.weight < 46.
  115. then "-50kg"
  116. else if grouped.(8) = 0 && judoka.weight > 90.
  117. then "-90kg"
  118. else if judoka.weight > 90.
  119. then "+90kg"
  120. else if judoka.weight > 81.
  121. then "-90kg"
  122. else if judoka.weight > 73.
  123. then "-81kg"
  124. else if judoka.weight > 66.
  125. then "-73kg"
  126. else if judoka.weight > 60.
  127. then "-66kg"
  128. else if judoka.weight > 55.
  129. then "-60kg"
  130. else if judoka.weight > 50.
  131. then "-55kg"
  132. else if judoka.weight > 46.
  133. then "-50kg"
  134. else "-46kg"
  135. ;;
  136.  
  137. (* Renvoie simplement la catégorie du judoka, avec deux conditions pour voir si la personne n'est pas dans un groupe à moins de 3 personnes des groupes 0 et 8 -> renvoie respectivement la deuxième et avant dernière catégorie *)
  138.  
  139. let judoka_test : t_judoka = {name = "Pierrick" ; birth_year = 2004; licence_number = 456; weight = 90.9};;
  140.  
  141. let tab_test : int array = [|2;3;6;5;4;7;8;9;6|];;
  142.  
  143. (* Voici deux variables pour tester les différentes fonctions *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement