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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#include <iostream>
using namespace std;
class date{
private:
int day;
int month;
int year;
static int days_in_month[];
bool leapyear(int);
public:
date(int u=0,int day=1,int month=1,int year=2012);
void setdate(int,int,int,int);
void display();
};
void date::display()
{
cout<<day<<"-"<<month<<"-"<<year<<endl;
cout<<endl;
cout<<endl;
}
int date::days_in_month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
date::date(int u,int d,int m,int y)
{
cout<<"Current Date"<<endl;
cout<<endl;
cout<<endl;
cout<<'\t'<<d<<'\t'<<m<<'\t'<<y<<endl;
cout<<endl;
cout<<endl;
cout<<"Days You want To jump IS = "<<u<<endl;
cout<<endl;
cout<<endl;
setdate(u,d,m,y);
}
void date::setdate(int u,int d,int m,int y)
{
if(d>31)
{
cout<<"wrong day :"<<d<<": i'm setting to 31 "<<endl;
cout<<endl;
cout<<endl;
d = 31;
}
year = y;
if((m>=1) && (m<=12))
{
month = m;
}
else
{
cout<<"month IS incorrect so i'm setting it to 1"<<endl;
cout<<endl;
cout<<endl;
month = 1;
}
if(m == 4 || m == 5 || m == 9 || m == 11)
{
if(d>30)
{
cout<<"The month "<<m<<" cannot have 31 days so i'm setting it to 30"<<endl;
cout<<endl;
cout<<endl;
d = 30;
}
}
if(d<=31)
{
for(int i =1;i<=u;i++)
{
if( month == 2 && leapyear(y))
{
if(d> 29 || d== 28)
{
cout<<"The month is feb and the year is leap So it cannot have :"<<d<<": days"<<" I'm setting it to 29"<<endl;
cout<<endl;
cout<<endl;
days_in_month[2] = 29;
}
days_in_month[2] = 29;
}
else
{
days_in_month[2] = 28;
}
if(d < days_in_month[month])
{
d++;
}
else
{
if(month >= 12)
{
year++;
month = 0;
}
month++;
d=0;
d++;
}
}
day = d ;
}
else
{
cout<<"day is incorrect so I'm setting it to 0;"<<endl;
cout<<endl;
cout<<endl;
day = 0;
}
}
bool date::leapyear(int y)
{
if (y % 400 == 0 || y%100 != 0 && y%4 == 0)
{
return true;
}
else
{
return false ;
}
}
int main()
{
char c;
do{
int jump,day,month,year = 0;
cout<<"Please enter the current date with spaces: ";
cin>>day>>month>>year;
cout<<"Please enter days you want to jump from the date you enter: "<<endl;
cin>>jump;
date d1(jump,day,month,year);
d1.display();
cout<<"do you want to continu: ";
cin>>c;
system("cls");
}while(c == 'y' || c=='Y');
}
|