1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#include <iostream>
#include <windows.h>
using namespace std;
char span=164;
class Date
{
private:
int day;
int month;
int year;
public:
Date() : day(20), month(9), year(2090)
{
cout << "\nconstructor current date";
}
Date(int d, int m, int y): day(d), month(m), year(y)
{
cout << "\nconstructor set date";
}
void setDate()
{
cout << "\n\nDigite la fecha en el formato dia, mes, a" << span << "o Ej: 19 06 2012.\n";
cin >> day >> month >> year ;
}
void setDate(int day, int month, int year)
{
cout<< "\nsetdate 2";
}
void showDate()
{
cout<< "\nday "<< day << " month " << month << " year " << year;
}
void showDate(char a)
{
cout<< "\n" << day << '/' << month << '/' << year ;
}
void showDateWords()
{
Date.words(Date);
}
void showDateWords(char a)
{
Date.words(Date);
}
bool validate();
void words();
};
bool Date::validate()
{
int leapYear;
leapYear=(year%4==0||(year%100==0 && year%400==0));
bool verify ((day<1 || day >31 || month<1 || month>12 ) || ((month==4 || month==6
|| month==9 || month==11 )&& day > 30 ) || ((leapYear==true && month==2 && day>29)
|| (leapYear!=true && month==2 && day>28)));
if (verify == true )
{
cout << "\n\n\terror: fecha incorrecta. " ;
}
return ( verify?true:false);
}
void Date::words()
{
static const int MAX = 12;
char months[MAX][MAX]={"Enero","Febrero","Marzo","Abril","Mayo",
"Junio","Julio","Agosto","septiembre",
"Octubre","Noviembre","Diciembre"};
cout << "\nLa fecha es "<< day << " de " << months[month-1] << " del a"<< span << "o " << year;
}
int main()
{
SYSTEMTIME t;
GetLocalTime(&t);
int cDay= t.wDay;
int cMonth= t.wMonth;
int cYear= t.wYear;
Date d1, d2;
Date d3(1, 1, 2000);
Date d4(cDay, cMonth, cYear);
do
{
d2.setDate();
}while(d2.validate()==true);
d1.showDate();
d2.showDate();
d3.showDate();
d4.showDate();
d1.showDateWords();
d2.showDateWords();
d3.showDateWords();
d4.showDateWords();
cout<< "\n\nmetodo para modificar fecha: ";
d3.setDate();
d2.setDate(31,06, 2098);
d1.setDate();
d1.showDate('a');
d2.showDate('a');
d3.showDate('a');
d4.showDate('a');
d1.showDateWords('a');
d2.showDateWords('a');
d3.showDateWords('a');
d4.showDateWords('a');
return 0;
}
|