[CONTEST] - Calendario perpetuo

« Older   Newer »
  Share  
MHack
CAT_IMG Posted on 2/1/2011, 17:33     +1   -1




Questa è la mia funzione:
SPOILER (click to view)
CODICE
;$g = giorno del mese
;$M = numero del mese (da wikipedia);Gennaio = 0 (se l'anno è bisestile = 6),Febbraio = 3 (se l'anno è bisestile = 2),Marzo = 3 (se l'anno è bisestile = 4),Aprile = 6,
;Maggio = 1,Giugno = 4,Luglio = 6,Agosto = 2,Settembre = 5,Ottobre = 0, Novembre = 3,Dicembre = 5
;$s = prime due cifre dell'anno
;$a = ultime due cifre dell'anno
_CalendarioP(1,0,20,11)
Func _CalendarioP($g,$M,$s,$a)
$G = Mod($g,7)
$A = Mod($a,28) + Int(((Mod($a,28) -1)/4))
$C = ""
If Mod($s,4) = 0 Then
       $C = 6
ElseIf Mod($s,4) = 1 Then
       $C = 4
ElseIf Mod($s,4) = 2 Then
       $C = 2
ElseIf Mod($s,4) = 3 Then
       $C = 0
EndIf
$tot = $G+$M+$A+$C
$day = Mod($tot,7)
If $day = 0 Then
       MsgBox(0,"","domenica")
ElseIf $day = 1 Then
       MsgBox(0,"","lunedì")
ElseIf $day = 2 Then
       MsgBox(0,"","martedì")
ElseIf $day = 3 Then
       MsgBox(0,"","mercoledì")
ElseIf $day = 4 Then
       MsgBox(0,"","giovedì")
ElseIf $day = 5 Then
       MsgBox(0,"","venerdì")
ElseIf $day = 6 Then
       MsgBox(0,"","sabato")
Else
       MsgBox(16,"","errore "&@error)
EndIf
EndFunc
Non è migliorata come funzione, nel senso che non puoi inserire direttamente il numero del mese, ma quello di $M.


Versione 2 xD
SPOILER (click to view)
CODICE
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$gui = GUICreate("Calendario Perpetuo",295,100,-1,-1)
GUISetState(@SW_SHOW)


;label
$lgiorno = GUICtrlCreateLabel("Giorno:",16,8,38,17)
$lmese = GUICtrlCreateLabel("Mese:",112,8,33,17)
$lanno = GUICtrlCreateLabel("Anno:",192,8,32,17)
$lris = GUICtrlCreateLabel("",8,80,280,17)



;input
$giorno = GUICtrlCreateInput("",56,8,41,21)
GUICtrlSetTip(-1,"Inserire il numero del giorno del mese(es. 12)")
GUICtrlSetLimit(-1,31,1)
$mese = GUICtrlCreateInput("",144,8,41,21)
GUICtrlSetTip(-1,"Inserire il numero del mese (es. Aprile = 4)")
GUICtrlSetLimit(-1,12,1)
$anno = GUICtrlCreateInput("",232,8,41,21)


;button
$get = GUICtrlCreateButton("Calcola",112,45,75,25)


While 1
   $nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
       Exit
Case $get
       $g = GUICtrlRead($giorno)
       $read_anno = GUICtrlRead($anno)
       $read_mese = GUICtrlRead($mese)
       $M = ""
       _ReplaceM()
       If $g And $read_anno And $read_mese <> "" Then
               $a = Mod($read_anno,100)
           $s = Int($read_anno/100)
           _CalendarioP($g,$M,$s,$a)
               GUICtrlSetData($lris,"Il giorno "&$g&"/"&$read_mese&"/"&$read_anno&" sarà (o è stato) un "&$days[$day])
       Else
               MsgBox(16,"","Errore! Riempi tutti i campi!")
       EndIf
EndSwitch
WEnd


Func _ReplaceM()
       $read_mese = GUICtrlRead($mese)
       If $read_mese = 1 Or 01 Then
               If Mod($read_anno,4) <> 0 Then
                    $M = 0
               Else
                       $M = 6
               EndIf
       ElseIf $read_mese = 2 Or 02 Then
               If Mod($read_anno,4) <> 0 Then
                    $M = 3
               Else
                       $M = 2
               EndIf
       ElseIf $read_mese = 3 Or 03 Then
               If Mod($read_anno,4) <> 0 Then
                    $M = 3
               Else
                       $M = 4
               EndIf
       ElseIf $read_mese = 4 Or 04 Then
               $M = 6
       ElseIf $read_mese = 5 Or 05 Then
               $M = 1
       ElseIf $read_mese = 6 Or 06 Then
               $M = 4
       ElseIf $read_mese = 7 Or 07 Then
               $M = 6
       ElseIf $read_mese = 8 Or 08 Then
               $M = 2
       ElseIf $read_mese = 9 Or 09 Then
               $M = 5
       ElseIf $read_mese = 10 Then
               $M = 0
       ElseIf $read_mese = 11 Then
               $M = 3
       ElseIf $read_mese = 12 Then
               $M = 5
       EndIf
EndFunc


Func _CalendarioP($g,$M,$s,$a)
$G = Mod($g,7)
$A = Mod($a,28) + Int(((Mod($a,28) -1)/4))
$C = ""
If Mod($s,4) = 0 Then
       $C = 6
ElseIf Mod($s,4) = 1 Then
       $C = 4
ElseIf Mod($s,4) = 2 Then
       $C = 2
ElseIf Mod($s,4) = 3 Then
       $C = 0
EndIf
$tot = $G+$M+$A+$C
Global $day = Mod($tot,7)
Global $days[7]=["domenica", "lunedì", "martedì", "mercoledì", "giovedì", "venerdì", "sabato"]
MsgBox(0,"",$days[$day])
EndFunc

Versione 2.1 (xD)
SPOILER (click to view)
CODICE
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$gui = GUICreate("Calendario Perpetuo",295,100,-1,-1)
GUISetState(@SW_SHOW)


;label
$lgiorno = GUICtrlCreateLabel("Giorno:",16,8,38,17)
$lmese = GUICtrlCreateLabel("Mese:",112,8,33,17)
$lanno = GUICtrlCreateLabel("Anno:",192,8,32,17)
$lris = GUICtrlCreateLabel("",8,80,280,17)



;input
$giorno = GUICtrlCreateInput("",56,8,41,21)
GUICtrlSetTip(-1,"Inserire il numero del giorno del mese(es. 12)")
GUICtrlSetLimit(-1,31,1)
$mese = GUICtrlCreateInput("",144,8,41,21)
GUICtrlSetTip(-1,"Inserire il numero del mese (es. Aprile = 4)")
GUICtrlSetLimit(-1,12,1)
$anno = GUICtrlCreateInput("",232,8,41,21)


;button
$get = GUICtrlCreateButton("Calcola",112,45,75,25)


While 1
   $nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
       Exit
Case $get
       $g = GUICtrlRead($giorno)
       $read_anno = GUICtrlRead($anno)
       $read_mese = GUICtrlRead($mese)
       $M = ""
       _ReplaceM()
       If $g And $read_anno And $read_mese <> "" Then
               $a = Mod($read_anno,100)
           $s = Int($read_anno/100)
           _CalendarioP($g,$M,$s,$a)
               If @YEAR&@MON&@MDAY > $read_anno&$read_mese&$g Then
                   GUICtrlSetData($lris,"Il giorno "&$g&"/"&$read_mese&"/"&$read_anno&" è stato "&$days[$day])
               ElseIf @YEAR&@MON&@MDAY < $read_anno&$read_mese&$g Then
                       GUICtrlSetData($lris,"Il giorno "&$g&"/"&$read_mese&"/"&$read_anno&" sarà "&$days[$day])
               Else
                       GUICtrlSetData($lris,"Oggi è "&$days[$day])
               EndIf
       Else
               MsgBox(16,"","Errore! Riempi tutti i campi!")
       EndIf
EndSwitch
WEnd


Func _ReplaceM()
       $read_mese = GUICtrlRead($mese)
       If $read_mese = 1 Or 01 Then
               If Mod($read_anno,4) <> 0 Then
                    $M = 0
               Else
                       $M = 6
               EndIf
       ElseIf $read_mese = 2 Or 02 Then
               If Mod($read_anno,4) <> 0 Then
                    $M = 3
               Else
                       $M = 2
               EndIf
       ElseIf $read_mese = 3 Or 03 Then
               If Mod(Mod($read_anno,100),4) <> 0 Then
                    $M = 3
               Else
                       $M = 4
               EndIf
       ElseIf $read_mese = 4 Or 04 Then
               $M = 6
       ElseIf $read_mese = 5 Or 05 Then
               $M = 1
       ElseIf $read_mese = 6 Or 06 Then
               $M = 4
       ElseIf $read_mese = 7 Or 07 Then
               $M = 6
       ElseIf $read_mese = 8 Or 08 Then
               $M = 2
       ElseIf $read_mese = 9 Or 09 Then
               $M = 5
       ElseIf $read_mese = 10 Then
               $M = 0
       ElseIf $read_mese = 11 Then
               $M = 3
       ElseIf $read_mese = 12 Then
               $M = 5
       EndIf
EndFunc


Func _CalendarioP($g,$M,$s,$a)
;$g = giorno del mese
;$M = numero del mese (da wikipedia);Gennaio = 0 (se l'anno è bisestile = 6),Febbraio = 3 (se l'anno è bisestile = 2),Marzo = 3 (se l'anno è bisestile = 4),Aprile = 6,
;Maggio = 1,Giugno = 4,Luglio = 6,Agosto = 2,Settembre = 5,Ottobre = 0, Novembre = 3,Dicembre = 5
;$s = prime due cifre dell'anno
;$a = ultime due cifre dell'anno
$G = Mod($g,7)
$A = Mod($a,28) + Int(((Mod($a,28) -1)/4))
$C = ""
If Mod($s,4) = 0 Then
       $C = 6
ElseIf Mod($s,4) = 1 Then
       $C = 4
ElseIf Mod($s,4) = 2 Then
       $C = 2
ElseIf Mod($s,4) = 3 Then
       $C = 0
EndIf
$tot = $G+$M+$A+$C
Global $day = Mod($tot,7)
Global $days[7]=["domenica", "lunedì", "martedì", "mercoledì", "giovedì", "venerdì", "sabato"]
MsgBox(0,"",$days[$day])
EndFunc


Edited by MHack - 3/1/2011, 12:28
 
Top
3ad_Pr0grammer
CAT_IMG Posted on 2/1/2011, 20:48     +1   -1




Vedo che posso fare..
 
Top
Utente Registrato
CAT_IMG Posted on 2/1/2011, 22:43     +1   -1




CITAZIONE (MHack @ 2/1/2011, 17:33) 
Questa è la mia funzione:
SPOILER (click to view)
CODICE
;$g = giorno del mese
;$M = numero del mese (da wikipedia);Gennaio = 0 (se l'anno è bisestile = 6),Febbraio = 3 (se l'anno è bisestile = 2),Marzo = 3 (se l'anno è bisestile = 4),Aprile = 6,
;Maggio = 1,Giugno = 4,Luglio = 6,Agosto = 2,Settembre = 5,Ottobre = 0, Novembre = 3,Dicembre = 5
;$s = prime due cifre dell'anno
;$a = ultime due cifre dell'anno
_CalendarioP(1,0,20,11)
Func _CalendarioP($g,$M,$s,$a)
$G = Mod($g,7)
$A = Mod($a,28) + Int(((Mod($a,28) -1)/4))
$C = ""
If Mod($s,4) = 0 Then
       $C = 6
ElseIf Mod($s,4) = 1 Then
       $C = 4
ElseIf Mod($s,4) = 2 Then
       $C = 2
ElseIf Mod($s,4) = 3 Then
       $C = 0
EndIf
$tot = $G+$M+$A+$C
$day = Mod($tot,7)
If $day = 0 Then
       MsgBox(0,"","domenica")
ElseIf $day = 1 Then
       MsgBox(0,"","lunedì")
ElseIf $day = 2 Then
       MsgBox(0,"","martedì")
ElseIf $day = 3 Then
       MsgBox(0,"","mercoledì")
ElseIf $day = 4 Then
       MsgBox(0,"","giovedì")
ElseIf $day = 5 Then
       MsgBox(0,"","venerdì")
ElseIf $day = 6 Then
       MsgBox(0,"","sabato")
Else
       MsgBox(16,"","errore "&@error)
EndIf
EndFunc
Non è migliorata come funzione, nel senso che non puoi inserire direttamente il numero del mese, ma quello di $M.


Versione 2 xD
SPOILER (click to view)
CODICE
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$gui = GUICreate("Calendario Perpetuo",295,100,-1,-1)
GUISetState(@SW_SHOW)


;label
$lgiorno = GUICtrlCreateLabel("Giorno:",16,8,38,17)
$lmese = GUICtrlCreateLabel("Mese:",112,8,33,17)
$lanno = GUICtrlCreateLabel("Anno:",192,8,32,17)
$lris = GUICtrlCreateLabel("",8,80,280,17)



;input
$giorno = GUICtrlCreateInput("",56,8,41,21)
GUICtrlSetTip(-1,"Inserire il numero del giorno del mese(es. 12)")
GUICtrlSetLimit(-1,31,1)
$mese = GUICtrlCreateInput("",144,8,41,21)
GUICtrlSetTip(-1,"Inserire il numero del mese (es. Aprile = 4)")
GUICtrlSetLimit(-1,12,1)
$anno = GUICtrlCreateInput("",232,8,41,21)


;button
$get = GUICtrlCreateButton("Calcola",112,45,75,25)


While 1
   $nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
       Exit
Case $get
       $g = GUICtrlRead($giorno)
       $read_anno = GUICtrlRead($anno)
       $read_mese = GUICtrlRead($mese)
       $M = ""
       _ReplaceM()
       If $g And $read_anno And $read_mese <> "" Then
               $a = Mod($read_anno,100)
           $s = Int($read_anno/100)
           _CalendarioP($g,$M,$s,$a)
               GUICtrlSetData($lris,"Il giorno "&$g&"/"&$read_mese&"/"&$read_anno&" sarà (o è stato) un "&$days[$day])
       Else
               MsgBox(16,"","Errore! Riempi tutti i campi!")
       EndIf
EndSwitch
WEnd


Func _ReplaceM()
       $read_mese = GUICtrlRead($mese)
       If $read_mese = 1 Or 01 Then
               If Mod($read_anno,4) <> 0 Then
                    $M = 0
               Else
                       $M = 6
               EndIf
       ElseIf $read_mese = 2 Or 02 Then
               If Mod($read_anno,4) <> 0 Then
                    $M = 3
               Else
                       $M = 2
               EndIf
       ElseIf $read_mese = 3 Or 03 Then
               If Mod($read_anno,4) <> 0 Then
                    $M = 3
               Else
                       $M = 4
               EndIf
       ElseIf $read_mese = 4 Or 04 Then
               $M = 6
       ElseIf $read_mese = 5 Or 05 Then
               $M = 1
       ElseIf $read_mese = 6 Or 06 Then
               $M = 4
       ElseIf $read_mese = 7 Or 07 Then
               $M = 6
       ElseIf $read_mese = 8 Or 08 Then
               $M = 2
       ElseIf $read_mese = 9 Or 09 Then
               $M = 5
       ElseIf $read_mese = 10 Then
               $M = 0
       ElseIf $read_mese = 11 Then
               $M = 3
       ElseIf $read_mese = 12 Then
               $M = 5
       EndIf
EndFunc


Func _CalendarioP($g,$M,$s,$a)
$G = Mod($g,7)
$A = Mod($a,28) + Int(((Mod($a,28) -1)/4))
$C = ""
If Mod($s,4) = 0 Then
       $C = 6
ElseIf Mod($s,4) = 1 Then
       $C = 4
ElseIf Mod($s,4) = 2 Then
       $C = 2
ElseIf Mod($s,4) = 3 Then
       $C = 0
EndIf
$tot = $G+$M+$A+$C
Global $day = Mod($tot,7)
Global $days[7]=["domenica", "lunedì", "martedì", "mercoledì", "giovedì", "venerdì", "sabato"]
MsgBox(0,"",$days[$day])
EndFunc

Attenzione che il primo anno del secolo non è bisestile (1000, 1800, 1900, 2000 ecc...) quindi la funzione che controlla gli anni bisestili non funziona correttamente sul primo giorno del secolo. Per ora ti metto secondo, se correggerai ti metterò primo a meno che xMasteRx non aggiunga gli anni bisestili prima di te.
 
Top
xMasteRx
CAT_IMG Posted on 2/1/2011, 22:46     +1   -1




CITAZIONE (Utente Registrato @ 2/1/2011, 22:43) 
Attenzione che il primo anno del secolo non è bisestile (1000, 1800, 1900, 2000 ecc...) quindi la funzione che controlla gli anni bisestili non funziona correttamente sul primo giorno del secolo. Per ora ti metto secondo, se correggerai ti metterò primo a meno che xMasteRx non aggiunga gli anni bisestili prima di te.

ma è già messo XXXXXD guarda un pò il source lol
 
Top
Utente Registrato
CAT_IMG Posted on 2/1/2011, 22:50     +1   -1




CITAZIONE (xMasteRx @ 2/1/2011, 22:46) 
CITAZIONE (Utente Registrato @ 2/1/2011, 22:43) 
Attenzione che il primo anno del secolo non è bisestile (1000, 1800, 1900, 2000 ecc...) quindi la funzione che controlla gli anni bisestili non funziona correttamente sul primo giorno del secolo. Per ora ti metto secondo, se correggerai ti metterò primo a meno che xMasteRx non aggiunga gli anni bisestili prima di te.

ma è già messo XXXXXD guarda un pò il source lol

Sicuro? Nel tuo o nel suo? Nel suo vedo solo un If che controlla se il modulo dell'anno è diverso da 0, non controlla le ultime due cifre dell'anno... O forse mi è sfuggito?
 
Top
xMasteRx
CAT_IMG Posted on 2/1/2011, 22:53     +1   -1




secondo il algoritmo presentato in wikipedia sapere se il anno era bissestile o no era utile soltanto nell'ora di assegnare i valori a m a seconda del mese e se il ano era bissestile, per verificarlo io ho usato questo
If IsInt(Number($s&$a)/4) Then $M1=
 
Top
Utente Registrato
CAT_IMG Posted on 2/1/2011, 23:04     +1   -1




Scusa, ma temo di non aver capito niente. Puoi ricontrollare la tua frase? xD

Niente, ho capito, ma quello prende per vero anche se ad esempio l'anno è 2000, invece gli anni che finiscono con due zeri sono per definizione NON bisestili, anche se divisibili per 4
 
Top
xMasteRx
CAT_IMG Posted on 2/1/2011, 23:05     +1   -1




loooooooooooooool XD
ho detto che io controllavo se il anno era bissestile o no quando dovevo assegnare M a seconda del mese [guarda Switch $m ecc lol]
 
Top
Utente Registrato
CAT_IMG Posted on 2/1/2011, 23:12     +1   -1




Ok, ma il tuo codice come quello di MHack, non controlla se l'anno finisce con 2 zeri, controlla solo se è divisibile per 4. Quindi considera bisestili anni come il 2000, che finisce con 2 eri e che quindi NON è bisestile.
 
Top
xMasteRx
CAT_IMG Posted on 2/1/2011, 23:17     +1   -1




lol dopo vedo di aggiustare XD
 
Top
Utente Registrato
CAT_IMG Posted on 2/1/2011, 23:19     +1   -1




Ok xD
 
Top
Ikezawa
CAT_IMG Posted on 2/1/2011, 23:34     +1   -1




Posto anche io la mia :P Avverte se è bisestile

SPOILER (click to view)
CODICE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void estrai(char* string,char* input,int da, int a);

int main()
{
//            Gen Febb Mar AP Mag Giu LUG AG  SET OTT NOV DEC Gen Febb Mar (// Bisestile)
char M[16] = {0,  3,  3,  6,  1,  4,  6,  2,  5,  0,  3,  5,  6,   2,   4};
  //            0   1   2   3
char ssM[5]= {6,  4,  2,  0 };
char week[7][11]={"Domenica","Lunedì","Martedì","Mercoledì","Giovedì","Venerdì","Sabato"};

char data[11];
char gg[3] ;
char mm[3] ;
char aaaa[5] ;
char aa[3];
char ss[3];
int G,Mid,A,C,anno;
int tmp,tot,offset;

 printf("Inserisci la data nel formato gg/mm/aaaa \n");
 scanf("%10s",data);
 printf("Hai inserito: %­s \n",data);

       estrai(gg,data,0,2);
       estrai(mm,data,3,5);
       estrai(aaaa,data,6,10);
       estrai(aa,data,8,10);
       estrai(ss,data,6,8);

           G = atoi(gg);
           G = G%­7;   // giorno
           anno = atoi(aaaa);
           offset=0;
           if ((anno % 4 == 0 && anno % 100 != 0) || anno % 400 == 0)
           {
                      printf("\n Bisestile\n");
                      offset =13;
           }

           Mid = atoi(mm)-1; //mese
           //M[Mid] mese
           A= atoi(aa); // anno
           tmp = A%28;
           tmp = tmp +(tmp -1)/4;
           C = atoi(ss) ; // secolo
           C= C%­4;
           tot = G+M[Mid+offset]+tmp+ssM[C];
           tot = tot%­7;
       printf ("\nil %­s/%­s/%­s sarà un %­s",gg,mm,aaaa,week[tot]);
   return 0;
}

void estrai(char* string,char* input,int da, int a)
{
       int scan = 0;
       int cont;

       for(cont = da; cont < a; cont++)
       {
               string[scan++] = input[cont];

       }

       string[scan] = 0;
}

Mettete i codici negli spoiler, così non abbiamo 30 pagine. MHack

Edited by MHack - 3/1/2011, 12:27
 
Top
Utente Registrato
CAT_IMG Posted on 2/1/2011, 23:39     +1   -1




Bene, Ikezawa è il primo che l'ha implementato completamente funzionante, passa primo.
 
Top
MHack
CAT_IMG Posted on 3/1/2011, 12:26     +1   -1




Ho aggiornato tutto, dimmi se funziona.
 
Top
3ad_Pr0grammer
CAT_IMG Posted on 3/1/2011, 15:48     +1   -1




Ecco il mio =)

Funzione:
SPOILER (click to view)
CODICE
Func _Calculate($GG,$MESE,$ANNO)
$a=StringRight($ANNO,2)
$s=StringLeft($ANNO,2)
$G=Mod($GG,7)
$A=Mod($a,28) + Int(((Mod($a,28) -1)/4))

Const $CAr[4]=[6,4,2,0]
$Mod=Mod($s,4)
$C=$CAr[$Mod]

Const $Me[12]=[0,3,3,6,1,4,6,2,5,0,3,5]
Const $MeB[12]=[6,2,4,6,1,4,6,2,5,0,3,5]
If IsInt($ANNO/4) And $a Not=00 Then
$M=$MeB[$MESE-1]
Else
$M=$Me[$MESE-1]
EndIf

$Ris=Mod($G+$M+$A+$C,7)
$Get=Mod($Ris,7)
Const $GetDay[7]=["Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato"]
Return $GetDay[$Get]
EndFunc


Esempio:
SPOILER (click to view)
CODICE
ConsoleWrite(_Calculate(@MDAY,@MON,@YEAR))


Edited by 3ad_Pr0grammer - 4/1/2011, 12:24
 
Top
37 replies since 2/1/2011, 03:57   621 views
  Share