Created
November 10, 2013 12:39
-
-
Save juanfal/7397761 to your computer and use it in GitHub Desktop.
Práctica de enumerados. Mediante la Congruencia de Zeller averiguar. qué día de la semana es cualquier fecha posterior al 4 de octubre de 1582.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // zeller.cpp | |
| // juanfc 2012-10-22 | |
| // Mediante la Congruencia_de_Zeller averiguar | |
| // qué día de la semana es cualquier fecha posterior al | |
| // 4 de octubre de 1582 | |
| // Usa: http://es.wikipedia.org/wiki/Congruencia_de_Zeller | |
| // y http://es.wikipedia.org/wiki/Calendario_gregoriano | |
| // | |
| #include <iostream> | |
| using namespace std; | |
| // tipos | |
| enum TDiaSem {LUNES, MARTES, MIERCOLES, JUEVES, VIERNES, SABADO, DOMINGO}; | |
| // prototipos | |
| TDiaSem diaSemana(const unsigned d, const unsigned m, const unsigned y); | |
| void escribeDiaSem(TDiaSem ds); | |
| unsigned Menu(); | |
| // principal | |
| int main() | |
| { | |
| bool seguir = true; | |
| do { | |
| switch (Menu()) { | |
| case 0: | |
| seguir = false; | |
| break; | |
| case 1: | |
| do { | |
| unsigned day, month, year; | |
| cout << "\nIntroduzca día mes año:? "; | |
| cin >> day; if (day == 0) break; | |
| cin >> month; if (month == 0) break; | |
| cin >> year; | |
| cout << "la fecha " << day << "/" << month << "/" << year | |
| << " cae en "; | |
| // hacer llamada y con el resultado, switch | |
| escribeDiaSem( diaSemana(day, month, year) ); | |
| } while (true); | |
| break; | |
| } | |
| } while ( seguir ); | |
| return 0; | |
| } | |
| // procedimientos | |
| unsigned Menu() | |
| { | |
| unsigned opc; | |
| do { | |
| cout << "\n --MENU--\n"; | |
| cout << "0) Salir.\n"; | |
| cout << "1) Dia de la semana.\n\n"; | |
| cout << "-Introduzca la opcion que desee: "; | |
| cin >> opc; | |
| cin.ignore(1000, '\n'); | |
| } while (opc > 3); | |
| return opc; | |
| } | |
| TDiaSem diaSemana (const unsigned d, const unsigned m, const unsigned y) | |
| { | |
| unsigned z, a, b, c; | |
| if (m <= 2) { | |
| a = m + 10 ; | |
| b = (y - 1) % 100; | |
| c = (y - 1) / 100; | |
| } else { | |
| a = m - 2; | |
| b = y % 100; | |
| c = y / 100; | |
| } | |
| z = (700 + (26 * a - 2) / 10 + d + b + b / 4 + c / 4 - 2 * c - 1) % 7; | |
| return TDiaSem(z); | |
| } | |
| void escribeDiaSem(TDiaSem ds) | |
| { | |
| switch (ds) { | |
| case LUNES: cout << "LUNES\n"; break; | |
| case MARTES: cout << "MARTES\n"; break; | |
| case MIERCOLES: cout << "MIÉRCOLES\n"; break; | |
| case JUEVES: cout << "JUEVES\n"; break; | |
| case VIERNES: cout << "VIERNES\n"; break; | |
| case SABADO: cout << "SÁBADO\n"; break; | |
| case DOMINGO: cout << "DOMINGO\n"; break; | |
| default: cout << "** ERROR **\n"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment