quarta-feira, 11 de outubro de 2017

Gerador de calendários II

 Não estamos aqui tentando reinventar a roda,
nada disto, digo isto porque alguns de meus críticos,
já me disseram isto algumas veses.
Sei que isto já vem pronto nas melhores IDES
do mercado, a saber: Qt creator e C++ builder em C++,
VS em C# e outras.
Eu tambem estive muito pensativo sobre isto,
tive muitas dificuldades para tirar algumas
partes do código, e me levantei de madrugada
em silêncio porque o cérebro não aceitava derrotas,
e acabei achando a solução programando na minha
própria cabeça.
Quando terminei, não tive coragem de postar,
mas hoje, quase dois anos depois resolvi compilar
e disponibilizar para quem precisar,
e me supreendi com o seu ótimo funcionamento.
Este código é dedicado aos que estão num nível
do intermediário ao avançado em linguagem C.


Mais avançado do que o outro que postei a poucos dias atrás,
este programa gera calendários entre as datas de 1004 a 2099,
fica claro que a data superior pode ser alterada se o calendário do
Windows também for alterado para uma data posterior. 
O destaque do programa é seu estilo profissional, imprimindo os 
domingos em vermelho, como também o dia atual. Já o dia pesquisado
na entrada de dados é grifado na cor azul, e o programa mostra
se aquele ano foi ou será bissexto, como também informa 
o dia da semana na data inserida, acompanhe atentamente seu 
funcionamento no vídeo abaixo:



//GERADOR DE CALENDÁRIOS II
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
int dia, dia_x, ano = 0, mes, ano_bi, x, w;
int Calendario ( char num [ 4 ] ) {
    int i, a = 0;
    a = strlen ( num );
    for ( i = 0; i < a; i++ ) {
         if ( num [ i ] < '0' || num [ i ] > '9' )
             return 0;
    }
    return 1;
}
void Ano_call ( ) {
    textcolor ( LIGHTRED );
    gotoxy ( 20, 3 );
    printf ( "GERADOR DE CALENDÁRIOS II" );
    textcolor ( LIGHTBLUE );
    gotoxy ( 20, 5 );
    printf ( "Digite um ano => " );
    if ( ( ano >= 1004 && ano < 2137 ) ) {
         textcolor ( LIGHTRED );
         printf ( "%d", ano );
    }
}
void Mes_call ( ) {
    textcolor ( LIGHTBLUE );
    gotoxy ( 20, 7 );
    printf ( "Digite um mes entre " );
    textcolor ( LIGHTRED );
    printf ( "1 " );
    textcolor ( LIGHTBLUE );
    printf ( "e " );
    textcolor ( LIGHTRED );
    printf ( "12 " );
    textcolor ( LIGHTBLUE );
    printf ( "=> " );
    if ( ( mes > 1 && mes < 13 ) ) {
         textcolor ( LIGHTRED );
         printf ( "%d", mes );
    }
}
void Dia_call ( ) {
    textcolor ( LIGHTBLUE );
    gotoxy ( 20, 9 );
    printf ( "Digite um dia entre " );
    textcolor ( LIGHTRED );
    printf ( "1 " );
    textcolor ( LIGHTBLUE );
    printf ( "e " );
    textcolor ( LIGHTRED );
    printf ( "31 " );
    textcolor ( LIGHTBLUE );
    printf ( "=> " );
    if ( ( dia > 1 && dia < 31 ) ) {
         textcolor ( LIGHTRED );
         printf ( "%d", dia );
    }
}
void Janela ( ) {
    int n, c;
    c = 0;
    for ( n = 2; n <= 24; n++ )
         for ( c = 3; c <= 63; c++ ) {
             gotoxy ( c, n );
             textbackground ( WHITE );
             printf ( " " );
         }
}
void Pausa ( ) {
    Sleep ( 400 );
    textcolor ( LIGHTRED );
    gotoxy ( 20, 22 );
    printf ( "PRESSIONE QUALQUER TECLA" );
    getche ( );
}
void Gera_Calendario ( );
void Inicia_Dia ( ) {
    struct tm *ptr;
    time_t lt;
    lt = time ( NULL );
    ptr = localtime ( &lt );

    dia = ptr
             ->tm_mday;
    mes = ptr
             ->tm_mon + 1;
    ano = ptr
             ->tm_year + 1900;
    Janela ( );
    textcolor ( LIGHTRED );
    gotoxy ( 20, 3 );
    printf ( "GERADOR DE CALENDÁRIOS II" );
    textcolor ( LIGHTMAGENTA );
    gotoxy ( 20, 5 );
    printf ( "Abaixo os dados coletados" );
    textcolor ( LIGHTBLUE );
    gotoxy ( 20, 7 );
    printf ( "Ano " );
    textcolor ( LIGHTRED );
    printf ( "%d", ano );
    textcolor ( LIGHTBLUE );
    gotoxy ( 29, 7 );
    printf ( "mes " );
    textcolor ( LIGHTRED );
    printf ( "%d", mes );
    textcolor ( LIGHTBLUE );
    gotoxy ( 36, 7 );
    printf ( "dia " );
    textcolor ( LIGHTRED );
    printf ( "%d", dia );
    Gera_Calendario ( );
    Pausa ( );
}
////////////////////////////////////////////////////////////////////////
void Gera_Calendario ( ) {
    struct tm *ptr;
    time_t lt;
    lt = time ( NULL );
    ptr = localtime ( &lt );
    int i, x = 0, y = 0, k = 0, w = 0;
    int a, b, c, d, dia_sem;
    int vet [ 31 ];
////////////////////////////////////////////////////////////////////////
    if ( ( ano % 4 == 0 ) && ( ( ano % 100 != 0 ) || ( ano % 400 == 0 ) ) ) {
         textcolor ( LIGHTBLUE );
         gotoxy ( 20, 8 );
         printf ( "Este ano foi " );
         textcolor ( LIGHTRED );
         printf ( "bissexto" );
         ano_bi = 1;
    } else {
         textcolor ( LIGHTBLUE );
         gotoxy ( 20, 8 );
         printf ( "Este ano não é " );
         textcolor ( LIGHTRED );
         printf ( "bissexto" );
         ano_bi = 0;
    }
////////////////////////////////////////////////////////////////////////
    a = ( 14 - mes );
    a = a / 12;
    b = ano - a;
    c = mes + ( 12 * a ) - 2;
    d = dia + 31 * c / 12 + b + b / 4 + b / 400 - b / 100;
    dia_sem = ( d % 7 ) + 1;
    //Chaves da semana
    textcolor ( LIGHTBLUE );
    gotoxy ( 20, 9 );
    printf ( "O dia da semana é " );
    textcolor ( LIGHTRED );
    if ( dia_sem == 1 )
         printf ( "Domingo " );
    if ( dia_sem == 2 )
         printf ( "Segunda feira " );
    if ( dia_sem == 3 )
         printf ( "Terça feira " );
    if ( dia_sem == 4 )
         printf ( "Quarta feira " );
    if ( dia_sem == 5 )
         printf ( "Quinta feira " );
    if ( dia_sem == 6 )
         printf ( "Sexta feira " );
    if ( dia_sem == 7 )
         printf ( "Sábado " );
////////////////////////////////////////////////////////////////////////
    dia = 1;
    a = ( 14 - mes );
    a = a / 12;
    b = ano - a;
    c = mes + ( 12 * a ) - 2;
    d = dia + 31 * c / 12 + b + b / 4 + b / 400 - b / 100;
    dia_sem = ( d % 7 ) + 1;
////////////////////////////////////////////////////////////////////////
    textcolor ( LIGHTRED );
    gotoxy ( 19, 11 );
    printf ( "Abaixo o calendário do mês " );
    textcolor ( LIGHTBLUE );
    gotoxy ( 19, 13 );
    printf ( "D   S   T   Q   Q   S   S" );
    if ( mes == 2 && ano_bi == 1 )
         w = 29;
    if ( mes == 2 && ano_bi == 0 ) {
         w = 28;
    }
////////////////////////////////////////////////////////////////////////
    if ( mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10
             || mes == 12 ) {
         w = 31;
    } else if ( mes == 4 || mes == 6 || mes == 9 || mes == 11 ) {
         w = 30;
    }
    x = dia_sem;
    textcolor ( BLACK );
    //Dia primeiro começa no domingo
    if ( x == 1 ) {
         printf ( "\a\a" );
         k = 5;
         y = 17;
         for ( i = 1; i <= w; i++ ) {
             vet [ i ] = i;
             if ( i == 1 ) {
                 gotoxy ( y, 15 );
             }
             if ( i == k + 3 ) {
                 gotoxy ( 17, 16 );
             }
             if ( i == k + 10 ) {
                 gotoxy ( 17, 17 );
             }
             if ( i == k + 17 ) {
                 gotoxy ( 17, 18 );
             }
             if ( i == k + 24 ) {
                 gotoxy ( 17, 19 );
             }
             if ( i == k + 31 ) {
                 gotoxy ( 17, 20 );
             } else if ( vet [ i ] == 1 || vet [ i ] == 8 || vet [ i ] == 15
                     || vet [ i ] == 22 || vet [ i ] == 29 ) {
                 textcolor ( LIGHTRED );
                 printf ( " %2d ", vet [ i ] );
             } else if ( vet [ i ] == ( ptr
                     ->tm_mday ) && ( mes == ptr
                              ->tm_mon + 1 ) && ( ano == ptr
                                       ->tm_year + 1900 ) ) {
                 textcolor ( LIGHTRED );
                 printf ( " %2d ", vet [ i ] );
             } else if ( vet [ i ] == dia_x ) {
                 textcolor ( LIGHTBLUE );
                 printf ( " %2d ", vet [ i ] );
             } else {
                 textbackground ( 15 );
                 textcolor ( BLACK );
                 printf ( " %2d ", vet [ i ] );
             }
         }
    }
////////////////////////////////////////////////////////////////////////
    //Dia primeiro começa na segunda-feira
    if ( x == 2 ) {
         k = 4;
         y = 21;
         for ( i = 1; i <= w; i++ ) {
             vet [ i ] = i;
             if ( i == 1 ) {
                 gotoxy ( y, 15 );
             }
             if ( i == k + 3 ) {
                 gotoxy ( 17, 16 );
             }
             if ( i == k + 10 ) {
                 gotoxy ( 17, 17 );
             }
             if ( i == k + 17 ) {
                 gotoxy ( 17, 18 );
             }
             if ( i == k + 24 ) {
                 gotoxy ( 17, 19 );
             }
             if ( i == k + 31 ) {
                 gotoxy ( 17, 20 );
             } else if ( vet [ i ] == 7 || vet [ i ] == 14 || vet [ i ] == 21
                     || vet [ i ] == 28 ) {
                 textcolor ( LIGHTRED );
                 printf ( " %2d ", vet [ i ] );
             } else if ( vet [ i ] == ( ptr
                     ->tm_mday ) && ( mes == ptr
                              ->tm_mon + 1 ) && ( ano == ptr
                                       ->tm_year + 1900 ) ) {
                 textcolor ( LIGHTRED );
                 printf ( " %2d ", vet [ i ] );
             } else if ( vet [ i ] == dia_x ) {
                 textcolor ( LIGHTBLUE );
                 printf ( " %2d ", vet [ i ] );
             } else {
                 textbackground ( 15 );
                 textcolor ( BLACK );
                 printf ( " %2d ", vet [ i ] );
             }
         }
    }
////////////////////////////////////////////////////////////////////////
    //Dia primeiro começa na terça-feira
    if ( x == 3 ) {
         k = 3;
         y = 25;
         for ( i = 1; i <= w; i++ ) {
             vet [ i ] = i;
             if ( i == 1 ) {
                 gotoxy ( y, 15 );
             }
             if ( i == k + 3 ) {
                 gotoxy ( 17, 16 );
             }
             if ( i == k + 10 ) {
                 gotoxy ( 17, 17 );
             }
             if ( i == k + 17 ) {
                 gotoxy ( 17, 18 );
             }
             if ( i == k + 24 ) {
                 gotoxy ( 17, 19 );
             }
             if ( i == k + 31 ) {
                 gotoxy ( 17, 20 );
             } else if ( vet [ i ] == 6 || vet [ i ] == 13 || vet [ i ] == 20
                     || vet [ i ] == 27 ) {
                 textcolor ( LIGHTRED );
                 printf ( " %2d ", vet [ i ] );
             } else if ( vet [ i ] == ( ptr
                     ->tm_mday ) && ( mes == ptr
                              ->tm_mon + 1 ) && ( ano == ptr
                                       ->tm_year + 1900 ) ) {
                 textcolor ( LIGHTRED );
                 printf ( " %2d ", vet [ i ] );
             } else if ( vet [ i ] == dia_x ) {
                 textcolor ( LIGHTBLUE );
                 printf ( " %2d ", vet [ i ] );
             } else {
                 textbackground ( 15 );
                 textcolor ( BLACK );
                 printf ( " %2d ", vet [ i ] );
             }
         }
    }
////////////////////////////////////////////////////////////////////////
    //Dia primeiro começa na quarta-feira
    if ( x == 4 ) {
         k = 2;
         y = 29;
         for ( i = 1; i <= w; i++ ) {
             vet [ i ] = i;
             if ( i == 1 ) {
                 gotoxy ( y, 15 );
             }
             if ( i == k + 3 ) {
                 gotoxy ( 17, 16 );
             }
             if ( i == k + 10 ) {
                 gotoxy ( 17, 17 );
             }
             if ( i == k + 17 ) {
                 gotoxy ( 17, 18 );
             }
             if ( i == k + 24 ) {
                 gotoxy ( 17, 19 );
             }
             if ( i == k + 31 ) {
                 gotoxy ( 17, 20 );
             } else if ( vet [ i ] == 5 || vet [ i ] == 12 || vet [ i ] == 19
                     || vet [ i ] == 26 ) {
                 textcolor ( LIGHTRED );
                 printf ( " %2d ", vet [ i ] );
             } else if ( vet [ i ] == ( ptr
                     ->tm_mday ) && ( mes == ptr
                              ->tm_mon + 1 ) && ( ano == ptr
                                       ->tm_year + 1900 ) ) {
                 textcolor ( LIGHTRED );
                 printf ( " %2d ", vet [ i ] );
             } else if ( vet [ i ] == dia_x ) {
                 textcolor ( LIGHTBLUE );
                 printf ( " %2d ", vet [ i ] );
             } else {
                 textbackground ( 15 );
                 textcolor ( BLACK );
                 printf ( " %2d ", vet [ i ] );
             }
         }
    }
////////////////////////////////////////////////////////////////////////
    //Dia primeiro começa na quinta-feira
    if ( x == 5 ) {
         k = 4;
         y = 33;
         for ( i = 1; i <= w; i++ ) {
             vet [ i ] = i;
             if ( i == 1 ) {
                 gotoxy ( y, 15 );
             }
             if ( i == k ) {
                 gotoxy ( 17, 16 );
             }
             if ( i == k + 7 ) {
                 gotoxy ( 17, 17 );
             }
             if ( i == k + 14 ) {
                 gotoxy ( 17, 18 );
             }
             if ( i == k + 21 ) {
                 gotoxy ( 17, 19 );
             }
             if ( i == k + 28 ) {
                 gotoxy ( 17, 20 );
             }
             if ( i == k + 35 ) {
                 gotoxy ( 17, 21 );
             } else if ( vet [ i ] == 4 || vet [ i ] == 11 || vet [ i ] == 18
                     || vet [ i ] == 25 ) {
                 textcolor ( LIGHTRED );
                 printf ( " %2d ", vet [ i ] );
             } else if ( vet [ i ] == ( ptr
                     ->tm_mday ) && ( mes == ptr
                              ->tm_mon + 1 ) && ( ano == ptr
                                       ->tm_year + 1900 ) ) {
                 textcolor ( LIGHTRED );
                 printf ( " %2d ", vet [ i ] );
             } else if ( vet [ i ] == dia_x ) {
                 textcolor ( LIGHTBLUE );
                 printf ( " %2d ", vet [ i ] );
             } else {
                 textbackground ( 15 );
                 textcolor ( BLACK );
                 printf ( " %2d ", vet [ i ] );
             }
         }
    }
////////////////////////////////////////////////////////////////////////
    //Dia primeiro começa na sexta-feira
    if ( x == 6 ) {
         k = 3;
         y = 37;
         for ( i = 1; i <= w; i++ ) {
             vet [ i ] = i;
             if ( i == 1 ) {
                 gotoxy ( y, 15 );
             }
             if ( i == k ) {
                 gotoxy ( 17, 16 );
             }
             if ( i == k + 7 ) {
                 gotoxy ( 17, 17 );
             }
             if ( i == k + 14 ) {
                 gotoxy ( 17, 18 );
             }
             if ( i == k + 21 ) {
                 gotoxy ( 17, 19 );
             }
             if ( i == k + 28 ) {
                 gotoxy ( 17, 20 );
             }
             if ( i == k + 35 ) {
                 gotoxy ( 17, 21 );
             } else if ( vet [ i ] == 3 || vet [ i ] == 10 || vet [ i ] == 17
                     || vet [ i ] == 24 || vet [ i ] == 31 ) {
                 textcolor ( LIGHTRED );
                 printf ( " %2d ", vet [ i ] );
             } else if ( vet [ i ] == ( ptr
                     ->tm_mday ) && ( mes == ptr
                              ->tm_mon + 1 ) && ( ano == ptr
                                       ->tm_year + 1900 ) ) {
                 textcolor ( LIGHTRED );
                 printf ( " %2d ", vet [ i ] );
             } else if ( vet [ i ] == dia_x ) {
                 textcolor ( LIGHTBLUE );
                 printf ( " %2d ", vet [ i ] );
             } else {
                 textbackground ( 15 );
                 textcolor ( BLACK );
                 printf ( " %2d ", vet [ i ] );
             }
         }
    }
////////////////////////////////////////////////////////////////////////
    //Dia primeiro começa na sabado
    if ( x == 7 ) {
         k = 2;
         y = 41;
         printf ( "\a\a" );
         for ( i = 1; i <= w; i++ ) {
             vet [ i ] = i;
             if ( i == 1 ) {
                 gotoxy ( y, 15 );
             }
             if ( i == k ) {
                 gotoxy ( 17, 16 );
             }
             if ( i == k + 7 ) {
                 gotoxy ( 17, 17 );
             }
             if ( i == k + 14 ) {
                 gotoxy ( 17, 18 );
             }
             if ( i == k + 21 ) {
                 gotoxy ( 17, 19 );
             }
             if ( i == k + 28 ) {
                 gotoxy ( 17, 20 );
             }
             if ( i == k + 35 ) {
                 gotoxy ( 17, 21 );
             } else if ( vet [ i ] == 2 || vet [ i ] == 9 || vet [ i ] == 16
                     || vet [ i ] == 23 || vet [ i ] == 30 ) {
                 textcolor ( LIGHTRED );
                 printf ( " %2d ", vet [ i ] );
             } else if ( vet [ i ] == ( ptr
                     ->tm_mday ) && ( mes == ptr
                              ->tm_mon + 1 ) && ( ano == ptr
                                       ->tm_year + 1900 ) ) {
                 textcolor ( LIGHTRED );
                 printf ( " %2d ", vet [ i ] );
             } else if ( vet [ i ] == dia_x ) {
                 textcolor ( LIGHTBLUE );
                 printf ( " %2d ", vet [ i ] );
             } else {
                 textbackground ( 15 );
                 textcolor ( BLACK );
                 printf ( " %2d ", vet [ i ] );
             }
         }
    }
}
////////////////////////////////////////////////////////////////////////
int main ( ) {
    system ( "title GERADOR DE CALENDÁRIOS II" );
    struct tm *ptr;
    time_t lt;
    lt = time ( NULL );
    ptr = localtime ( &lt );
    char num [ 10 ];
    char me_s [ 4 ];
    char di_a [ 4 ];
    int erro = 0;
    int a, b, c, d, dia_sem;
    do {
         Inicia_Dia ( );
         dia = 0;
         ano = 0;
         ano_bi = 0;
         mes = 0;
         do {
             Janela ( );
             Ano_call ( );
             if ( erro == 3 ) {
                 Ano_call ( );
             }
             textcolor ( LIGHTRED );
             gets ( num );
             ano = atoi ( num );
             if ( Calendario ( num ) == 0 ) {
                 textcolor ( LIGHTBLUE );
                 gotoxy ( 20, 7 );
                 printf ( "Voce digitou ==> " );
                 textcolor ( LIGHTRED );
                 printf ( "%s", num );
                 textcolor ( BLACK );
                 gotoxy ( 20, 9 );
                 printf ( "\aIsto não é um ano válido !" );
                 erro = 3;
                 Pausa ( );
                 continue;
             }
             if ( ano < 1004 || ano > 2137 ) {
                 textcolor ( LIGHTBLUE );
                 gotoxy ( 20, 7 );
                 printf ( "\aO ano não pode ser menor que" );
                 textcolor ( LIGHTRED );
                 gotoxy ( 20, 8 );
                 printf ( "1004 " );
                 textcolor ( LIGHTBLUE );
                 printf ( "e nem maior que " );
                 textcolor ( LIGHTRED );
                 printf ( "2099" );
                 ano = 0;
                 erro = 3;
                 Pausa ( );
                 continue;
             }
             break;
         } while ( ( ano < 1004 || ano > 2137 ) );
    ////////////////////////////////////////////////////////////////////////
         do {
             Janela ( );
             Ano_call ( );
             if ( erro == 2 ) {
                 Ano_call ( );
             }
             Mes_call ( );
             textcolor ( LIGHTRED );
             gets ( me_s );
             mes = atoi ( me_s );
             if ( Calendario ( me_s ) == 0 ) {
                 textcolor ( LIGHTBLUE );
                 gotoxy ( 20, 9 );
                 printf ( "Você digitou ==> " );
                 textcolor ( LIGHTRED );
                 printf ( "%s", me_s );
                 textcolor ( BLACK );
                 gotoxy ( 20, 11 );
                 printf ( "\aIsto não é um mes válido !" );
                 erro = 2;
                 Pausa ( );
                 continue;
             }
             if ( mes < 1 || mes > 12 ) {
                 textcolor ( LIGHTBLUE );
                 gotoxy ( 20, 9 );
                 printf ( "\aO mes não pode ser menor que" );
                 textcolor ( LIGHTRED );
                 gotoxy ( 20, 10 );
                 printf ( "1 " );
                 textcolor ( LIGHTBLUE );
                 printf ( "e nem maior que " );
                 textcolor ( LIGHTRED );
                 printf ( "12" );
                 erro = 2;
                 Pausa ( );
                 continue;
             }
             break;
         } while ( ( mes < 1 || mes > 12 ) );
    ////////////////////////////////////////////////////////////////////////
         do {
             Janela ( );
             Ano_call ( );
             Mes_call ( );
             if ( erro == 1 ) {
                 Ano_call ( );
                 Mes_call ( );
             }
             Dia_call ( );
             textcolor ( LIGHTRED );
             gets ( di_a );
             dia = atoi ( di_a );
             dia_x = dia;
             if ( Calendario ( di_a ) == 0 ) {
                 textcolor ( LIGHTBLUE );
                 gotoxy ( 20, 11 );
                 printf ( "Voce digitou ==> " );
                 textcolor ( LIGHTRED );
                 printf ( "%s", di_a );
                 textcolor ( BLACK );
                 gotoxy ( 20, 13 );
                 printf ( "\aIsto não á um dia válido !" );
                 Pausa ( );
                 erro = 1;
                 continue;
             } else if ( dia < 1 || dia > 31 ) {
                 textcolor ( LIGHTBLUE );
                 gotoxy ( 20, 11 );
                 printf ( "\aO dia não pode ser menor que" );
                 textcolor ( LIGHTRED );
                 gotoxy ( 20, 12 );
                 printf ( "1 " );
                 textcolor ( LIGHTBLUE );
                 printf ( "e nem maior que " );
                 textcolor ( LIGHTRED );
                 printf ( "31" );
                 Pausa ( );
                 erro = 1;
                 continue;
             } else if ( ( mes == 2 ) && ( dia < 1 || dia > 29 ) ) {
                 textcolor ( LIGHTBLUE );
                 gotoxy ( 20, 11 );
                 printf ( "\aO mes de fevereiro só possui" );
                 textcolor ( LIGHTRED );
                 gotoxy ( 20, 12 );
                 printf ( "28 " );
                 textcolor ( LIGHTBLUE );
                 printf ( "ou " );
                 textcolor ( LIGHTRED );
                 printf ( "29 " );
                 textcolor ( LIGHTBLUE );
                 printf ( "dias " );
                 dia = 0;
                 Pausa ( );
                 erro = 1;
                 continue;
                 gotoxy ( 51, 9 );
                 clreol ( );
             }
             break;
         } while ( ( dia < 1 || dia > 31 ) || ( dia < 1 || dia > 29 ) );
    ////////////////////////////////////////////////////////////////////////
         gotoxy ( 20, 5 );
         clreol ( );
         gotoxy ( 20, 7 );
         clreol ( );
         gotoxy ( 20, 9 );
         clreol ( );
         textcolor ( LIGHTRED );
         gotoxy ( 20, 3 );
         printf ( "GERADOR DE CALENDÁRIOS" );
         textcolor ( LIGHTMAGENTA );
         gotoxy ( 20, 5 );
         printf ( "Abaixo os dados coletados" );
         textcolor ( LIGHTBLUE );
         gotoxy ( 20, 7 );
         printf ( "Ano " );
         textcolor ( LIGHTRED );
         printf ( "%d", ano );
         textcolor ( LIGHTBLUE );
         gotoxy ( 29, 7 );
         printf ( "mes " );
         textcolor ( LIGHTRED );
         printf ( "%d", mes );
         textcolor ( LIGHTBLUE );
         gotoxy ( 36, 7 );
         printf ( "dia " );
         textcolor ( LIGHTRED );
         printf ( "%d", dia );
    ////////////////////////////////////////////////////////////////////////
         if ( ( ano % 4 == 0 )
                 && ( ( ano % 100 != 0 ) || ( ano % 400 == 0 ) ) ) {
             textcolor ( LIGHTBLUE );
             gotoxy ( 20, 8 );
             printf ( "Este ano foi " );
             textcolor ( LIGHTRED );
             printf ( "bissexto" );
             ano_bi = 1;
         } else {
             textcolor ( LIGHTBLUE );
             gotoxy ( 20, 8 );
             printf ( "Este ano não é " );
             textcolor ( LIGHTRED );
             printf ( "bissexto" );
             ano_bi = 0;
         }
    ////////////////////////////////////////////////////////////////////////
         a = ( 14 - mes );
         a = a / 12;
         b = ano - a;
         c = mes + ( 12 * a ) - 2;
         d = dia + 31 * c / 12 + b + b / 4 + b / 400 - b / 100;
         dia_sem = ( d % 7 ) + 1;
         //Chave da semana
         textcolor ( LIGHTBLUE );
         gotoxy ( 20, 9 );
         printf ( "O dia da semana é " );
         textcolor ( LIGHTRED );
         if ( dia_sem == 1 )
             printf ( "Domingo " );
         if ( dia_sem == 2 )
             printf ( "Segunda feira " );
         if ( dia_sem == 3 )
             printf ( "Terça feira " );
         if ( dia_sem == 4 )
             printf ( "Quarta feira " );
         if ( dia_sem == 5 )
             printf ( "Quinta feira " );
         if ( dia_sem == 6 )
             printf ( "Sexta feira " );
         if ( dia_sem == 7 )
             printf ( "Sábado " );
    ////////////////////////////////////////////////////////////////////////
         //dia = 1;
         a = ( 14 - mes );
         a = a / 12;
         b = ano - a;
         c = mes + ( 12 * a ) - 2;
         d = dia + 31 * c / 12 + b + b / 4 + b / 400 - b / 100;
         dia_sem = ( d % 7 ) + 1;
    ////////////////////////////////////////////////////////////////////////
         textcolor ( LIGHTRED );
         gotoxy ( 19, 11 );
         printf ( "Abaixo o calendário do mês " );
         textcolor ( LIGHTBLUE );
         gotoxy ( 19, 13 );
         printf ( "D   S   T   Q   Q   S   S" );
         if ( mes == 2 && ano_bi == 1 )
             w = 29;
         if ( mes == 2 && ano_bi == 0 ) {
             w = 28;
         }
    ////////////////////////////////////////////////////////////////////////
         if ( mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8
                 || mes == 10 || mes == 12 ) {
             w = 31;
         } else if ( mes == 4 || mes == 6 || mes == 9 || mes == 11 ) {
             w = 30;
         }
         x = dia_sem;
         Gera_Calendario ( );
         dia = 0;
         dia_x = 0;
         ano = 0;
         ano_bi = 0;
         mes = 0;
         Pausa ( );
    } while ( 1 );
}



Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.