Ayuda con fechas en c++
Hola a todos necesito hacer un programa en el cual uno digite la fecha y le dija que dia es por ejemplo:
14 07 2004 es miercoles, e intentado pero no he podido,lo necesito lo antes posible, de antemano agradesco su ayuda,
14 07 2004 es miercoles, e intentado pero no he podido,lo necesito lo antes posible, de antemano agradesco su ayuda,
// program dias.cpp
// written in borland c++ - ver 4.5
#include <iostream.h>
#include <iomanip.h>
const char *nombres[] = {"domingo","lunes","martes","miercoles",
"jueves","viernes","sabado"};
struct Date
{
int dd,
mm,
yy;
}; // STRUCT DATE
// imprescindible agregar al programa un funcion para validar la fecha
// hay que revisar : 1 <= dd <= dia maximo del mes
// 1 <= mm <= 12
// 1600 <= yy el calendario Gregoriano desde 1582
void GetDate(Date &a)
{
cout << setw(30) << "day : ";
cin >> a.dd;
cout << setw(30) << "month : ";
cin >> a.mm;
cout << setw(30) << "year : ";
cin >> a.yy;
cout << endl;
} // GET DATE
void ShowDate(Date a)
{
cout << setw(30) << "la fecha es : " << a.dd << "/"
<< a.mm << "/" << a.yy << endl << endl;
} // SHOW DATE
int FindDayInWeek(Date a)
{
int d = a.dd,
m = a.mm - 2,
y = a.yy % 100,
c = a.yy / 100;
if(m < 0)
{
m += 12;
y--;
}
int w = d + int(2.6*m - 0.2) - 2*c + y + c/4 + y/4;
while(w < 0)
w += 7;
return w % 7;
} // FIND DAY IN WEEK
void main()
{
Date a;
GetDate(a);
ShowDate(a);
int index = FindDayInWeek(a);
cout << setw(30) << "el dia en la semana es : "
<< nombres[index] << endl << endl;
cout << "end of program - good bye ! ! ! " << endl;
} // MAIN
// written in borland c++ - ver 4.5
#include <iostream.h>
#include <iomanip.h>
const char *nombres[] = {"domingo","lunes","martes","miercoles",
"jueves","viernes","sabado"};
struct Date
{
int dd,
mm,
yy;
}; // STRUCT DATE
// imprescindible agregar al programa un funcion para validar la fecha
// hay que revisar : 1 <= dd <= dia maximo del mes
// 1 <= mm <= 12
// 1600 <= yy el calendario Gregoriano desde 1582
void GetDate(Date &a)
{
cout << setw(30) << "day : ";
cin >> a.dd;
cout << setw(30) << "month : ";
cin >> a.mm;
cout << setw(30) << "year : ";
cin >> a.yy;
cout << endl;
} // GET DATE
void ShowDate(Date a)
{
cout << setw(30) << "la fecha es : " << a.dd << "/"
<< a.mm << "/" << a.yy << endl << endl;
} // SHOW DATE
int FindDayInWeek(Date a)
{
int d = a.dd,
m = a.mm - 2,
y = a.yy % 100,
c = a.yy / 100;
if(m < 0)
{
m += 12;
y--;
}
int w = d + int(2.6*m - 0.2) - 2*c + y + c/4 + y/4;
while(w < 0)
w += 7;
return w % 7;
} // FIND DAY IN WEEK
void main()
{
Date a;
GetDate(a);
ShowDate(a);
int index = FindDayInWeek(a);
cout << setw(30) << "el dia en la semana es : "
<< nombres[index] << endl << endl;
cout << "end of program - good bye ! ! ! " << endl;
} // MAIN
