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
|
void Date::addDay()
{
int DaysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string months [12] = {"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"};
for(int i=0;i<12;i++)
{
if(mth == months[i])
count = i;
}
bool flag;
int theDays;
cout<<"Enter how many days to be added"<<endl;
cin>>theDays;"\n";
if(isLeapYear())
DaysInMonth[1] = 29;
int tempDays = day;
tempDays += theDays;
do
{
flag = false;
if(tempDays>DaysInMonth[count])
{
tempDays-=DaysInMonth[count];
count++;
flag = true;
}
if(count > 12)
{
count=1;
year++;
}
}
while(flag);
day = tempDays;
cout<<year<<"/"<<day<<"/";
switch(count)
{
case 0 : cout<<"jan"<<endl;
break;
case 1 : cout<<"feb"<<endl;
break;
case 2 : cout<<"mar"<<endl;
break;
case 3 : cout<<"apr"<<endl;
break;
case 4 : cout<<"may"<<endl;
break;
case 5 : cout<<"jun"<<endl;
break;
case 6 : cout<<"jul"<<endl;
break;
case 7 : cout<<"aug"<<endl;
break;
case 8 : cout<<"sep"<<endl;
break;
case 9 : cout<<"oct"<<endl;
break;
case 10 : cout<<"nov"<<endl;
break;
case 11 : cout<<"dec"<<endl;
break;
}
}
void Date::returnDate() const
{
cout<<"date is "<<day<<"-"<<mth<<"-"<<year<<endl;
}
|