richie3366

jour de la semaine

Oct 9th, 2012
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 4.31 KB | None | 0 0
  1.     with entrees_sorties; use entrees_sorties;
  2.     procedure jour is
  3.        
  4.       moisBissex : array(1..12) of Integer := (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  5.       moisPasBissex : array(1..12) of Integer := (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  6.        
  7.       joursSemaine : array(1..7) of String(1..8) := ("Lundi   ", "Mardi   ", "Mercredi", "Jeudi   ", "Vendredi", "Samedi  ", "Dimanche");
  8.        
  9.       dateString : String(1..255);
  10.       dateStringLen : Integer;
  11.       jourEntre : Integer;
  12.       moisEntre : Integer;
  13.       anneeEntree : Integer;
  14.      
  15.       jourRef : Integer := 8;
  16.       moisRef : Integer := 10;
  17.       anneeRef : Integer := 2012;
  18.      
  19.       ij, im, ia : Integer;      
  20.       nbJours : Integer := 0;
  21.      
  22.       sens : Integer := -1;
  23.      
  24.       function estBissextile(annee : Integer) return Boolean is
  25.         begin
  26.             if(((annee mod 4)=0) AND (((annee mod 100)/=0) OR ((annee mod 400)=0))) then
  27.                 return true;
  28.             else
  29.                 return false;
  30.             end if;
  31.         end estBissextile;
  32.      
  33.      
  34.         function minJour(mois, annee, sens : Integer) return Integer is
  35.         begin
  36.            
  37.             if(sens < 0) then
  38.                 return 1;
  39.             else   
  40.                 if(estBissextile(annee)) then
  41.                     return moisBissex(mois);
  42.                 else
  43.                     return moisPasBissex(mois);
  44.                 end if;
  45.             end if;
  46.         end minJour;
  47.  
  48.         function maxJour(mois, annee, sens : Integer) return Integer is
  49.         begin
  50.            
  51.             if(sens > 0) then
  52.                 return 1;
  53.             else   
  54.                 if(estBissextile(annee)) then
  55.                     return moisBissex(mois);
  56.                 else
  57.                     return moisPasBissex(mois);
  58.                 end if;
  59.             end if;
  60.         end maxJour;    
  61.        
  62.         function minMois(sens : Integer) return Integer is
  63.         begin
  64.            
  65.             if(sens < 0) then
  66.                 return 1;
  67.             else   
  68.                 return 12;
  69.             end if;
  70.         end minMois;
  71.  
  72.         function maxMois(sens : Integer) return Integer is
  73.         begin
  74.            
  75.             if(sens > 0) then
  76.                 return 1;
  77.             else   
  78.                 return 12;
  79.             end if;
  80.         end maxMois;    
  81.      
  82.      
  83.     begin
  84.        put("Entrez une date (JJ/MM/AAAA) : ");
  85.        get_line(dateString, dateStringLen);
  86.        new_line;
  87.        
  88.        if(dateStringLen = 10) then
  89.           if(dateString(3)='/' AND dateString(6)='/') then
  90.             jourEntre := Integer'Value(dateString(1..2));
  91.             moisEntre := Integer'Value(dateString(4..5));
  92.             anneeEntree := Integer'Value(dateString(7..10));
  93.            
  94.             --put("Date : ");put(jourEntre, 0);put('/');put(moisEntre, 0);put('/');put(anneeEntree, 0);new_line;
  95.            
  96.             if(anneeEntree = anneeRef) then
  97.                 if(moisEntre = moisRef) then
  98.                     if(jourEntre < jourRef) then
  99.                         sens := -1;
  100.                     else
  101.                         sens := 1;
  102.                     end if;
  103.                 else
  104.                     if(moisEntre < moisRef) then
  105.                         sens := -1;
  106.                     else
  107.                         sens := 1;
  108.                     end if;
  109.                 end if;
  110.             else
  111.                 if(anneeEntree < anneeRef) then
  112.                     sens := -1;
  113.                 else
  114.                     sens := 1;
  115.                 end if;
  116.             end if;
  117.            
  118.                 ij := jourRef;
  119.                 im := moisRef;
  120.                 ia := anneeRef;            
  121.            
  122.             while(not(ij = jourEntre AND im = moisEntre AND ia = anneeEntree)) loop
  123.                
  124.                 ij := ij + sens;
  125.                
  126.                     --put(Integer'Image(ij)&"/"&Integer'Image(im)&"/"&Integer'Image(ia));new_line;                 
  127.                
  128.                 if(ij*sens > minJour(im, ia, sens)*sens) then
  129.                     im := im + sens;
  130.                     if(im*sens > minMois(sens)*sens) then
  131.                         ia := ia + sens;
  132.                         im := maxMois(sens);
  133.                     end if;
  134.                    
  135.                         ij := maxJour(im, ia, sens);                   
  136.                    
  137.                 end if;
  138.                
  139.                 --put(Integer'Image(ij)&"/"&Integer'Image(im)&"/"&Integer'Image(ia));
  140.                 --new_line;
  141.                
  142.                 nbJours := nbJours + sens;
  143.                
  144.             end loop;
  145.            
  146.            put("Nombre de jours [depuis 08/10/2012 !] ="&Integer'Image(nbJours*sens));
  147.            new_line;
  148.            put("Jour de la semaine : "&joursSemaine((nbJours mod 7) + 1));
  149.            
  150.           else
  151.             put("Mauvais format de date !");
  152.           end if;
  153.        else
  154.           put("Mauvais format de date !");
  155.        end if;
  156.      
  157.     end jour;
Advertisement
Add Comment
Please, Sign In to add comment