hi,im trying to solve as many exersizes as i can
and iv stoped in the last part of the aquestion i couldnt develop the algorithm
for it.may any one guide me
this is the question:
i have class call dateType
there are many operations shuch :
1-return number of days of the month
2-return number of days passed in thr year for agiven date.
3-return number of days remaning in thr year for agiven date. 4-calculating the new date by adding a fixed number of days
exp:3-18-2009 + 25 days will be 4-12-2009...
the forth function is the part were i got stucked in..
int day, month, year;//note that counting starts from 0 here
int increase;
day += increase;
while(day >= days_in_month(month)){//may happen if increase > 0
day -= days_in_month(month);
month++;
}
while(day < 0){//may happen if increase < 0
month--;
day += days_in_month(month);
}
while(month >= 12){//I do the same here. number of months in year is constant,
// so I could do this with % and /, but I figured this way it would be more clear
//what happened with days.
month -= 12;
year++;
}
while(month < 0){
year--;
month += 12;
}