Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* auto eval 8.2 *)
- #use "AP1utilbis.ml";;
- type t_judoka = {name : string; birth_year : int; licence_number : int; weight : float};;
- (* On définie un type Judoka avec les caractéristiques requises *)
- let get_judoka_name() : string =
- let name : string ref = ref "" in
- while !name = ""
- do
- print_string("Veuillez entrer le nom du judoka : ") ;
- name := read_line() ;
- done ;
- !name
- ;;
- let get_judoka_birth_year() : int =
- let birth_year : int ref = ref 0 in
- while !birth_year <> 2003 && !birth_year <> 2004 && !birth_year <> 2005
- do
- print_string("Veuillez entrer l'âge de naissance du judoka : ") ;
- birth_year := read_int() ;
- done ;
- !birth_year
- ;;
- let get_judoka_licence_number() : int =
- let number : int ref = ref 0 in
- while !number = 0
- do
- print_string("Veuillez entrer le numéro de licence : ") ;
- number := read_int() ;
- done ;
- !number
- ;;
- let get_judoka_weight() : float =
- let weight : float ref = ref 0. in
- while !weight <= 0.
- do
- print_string("Veuillez entrer le poids du judoka : ") ;
- weight := read_float() ;
- done ;
- !weight
- ;;
- (* J'ai créé une fonction auxiliaire pour chaque caractéristique de get judoka *)
- let get_judoka() : t_judoka =
- {name = get_judoka_name(); birth_year = get_judoka_birth_year(); licence_number = get_judoka_licence_number(); weight = get_judoka_weight()}
- ;;
- (* On a ensuite juste a demander chaque fonction auxilaire *)
- let registration_tab : int array =
- arr_make(9,0)
- ;;
- let registration(judoka, registration_tab) : unit =
- if judoka.weight <= 46.
- then registration_tab.(0) <- registration_tab.(0) + 1
- else if judoka.weight <= 50.
- then registration_tab.(1) <- registration_tab.(1) + 1
- else if judoka.weight <= 55.
- then registration_tab.(2) <- registration_tab.(2) + 1
- else if judoka.weight <= 60.
- then registration_tab.(3) <- registration_tab.(3) + 1
- else if judoka.weight <= 66.
- then registration_tab.(4) <- registration_tab.(4) + 1
- else if judoka.weight <= 73.
- then registration_tab.(5) <- registration_tab.(5) + 1
- else if judoka.weight <= 81.
- then registration_tab.(6) <- registration_tab.(6) + 1
- else if judoka.weight <= 90.
- then registration_tab.(7) <- registration_tab.(7) + 1
- else registration_tab.(8) <- registration_tab.(8) + 1
- ;;
- (* On ajoute 1 à la catégorie correspondante au judoka *)
- let get_registration() : int array =
- let finish : string ref = ref "" in
- while !finish <> "yes"
- do
- registration(get_judoka(), registration_tab);
- print_string("Do you have finish the registration ? (yes only)") ;
- finish := read_line();
- done ;
- registration_tab
- ;;
- (* 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" *)
- let grouping(registration_tab) : int array =
- 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
- then failwith "Not enough members"
- else (if registration_tab.(0) < 3
- then (
- registration_tab.(1) <- registration_tab.(0) + registration_tab.(1) ;
- registration_tab.(0) <- 0 ;
- )) ;
- (if registration_tab.(8) < 3
- then (
- registration_tab.(7) <- registration_tab.(7) + registration_tab.(8) ;
- registration_tab.(8) <- 0 ;
- )) ;
- registration_tab ;;
- (* 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. *)
- let category(judoka, tab : t_judoka*int array) : string =
- let grouped : int array = grouping(tab) in
- if grouped.(0) = 0 && judoka.weight < 46.
- then "-50kg"
- else if grouped.(8) = 0 && judoka.weight > 90.
- then "-90kg"
- else if judoka.weight > 90.
- then "+90kg"
- else if judoka.weight > 81.
- then "-90kg"
- else if judoka.weight > 73.
- then "-81kg"
- else if judoka.weight > 66.
- then "-73kg"
- else if judoka.weight > 60.
- then "-66kg"
- else if judoka.weight > 55.
- then "-60kg"
- else if judoka.weight > 50.
- then "-55kg"
- else if judoka.weight > 46.
- then "-50kg"
- else "-46kg"
- ;;
- (* 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 *)
- let judoka_test : t_judoka = {name = "Pierrick" ; birth_year = 2004; licence_number = 456; weight = 90.9};;
- let tab_test : int array = [|2;3;6;5;4;7;8;9;6|];;
- (* Voici deux variables pour tester les différentes fonctions *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement