I have one more last question for those who would like to proofread code. I have almost finished my date class except for the increment function. I am sure that everyone here knows how to increment the date but I don't know what I am doing wrong in my code. Here are my function.(PLease pay particular attention to Date::Increment()
Code:
// This function should set the date to the specified values. If resulting date is invalid
// the existing date should not be changed
bool Date::Set(int m, int d, int y){
if (y > 0){
if ((m == 2) && (d > 0 && d <= 28)){ // handle the anomaly month February first!
month = m;
day = d;
year = y;
return true;
};
// handles the months January, March, May, July, August, October, December
if (((m == 1)||(m == 3)||(m == 5)||(m == 7)||(m == 8)||(m == 10)||(m==12)) && (d>0 && d<=31)){
month = m;
day = d;
year = y;
return true;
}
// handles the months April, June, September, November
if (((m == 4)||(m == 6)||(m == 9)||(m == 11)) && (d>0 && d<=30)){
month = m;
day = d;
year = y;
return true;
}
// catch - all statement
return false;
}
else {
return false;// if year < 0
}
}
Code:
// This function should move the date forward one calendar day.
void Date::Increment()
{
int m = GetMonth();
int d = GetDay();
if ((m == 1)||(m == 3)||(m == 5)||(m == 7)||(m == 8)||(m == 10)||(m == 10) && (d == 31)){
int new_month, new_day, new_year;
if (m == 12){
new_month = 1;
new_day = 1;
new_year = GetYear() + 1;
// Set new date
Set(new_month, new_day, new_year);
}
if (m != 12){
new_month = GetMonth() + 1;
new_day = 1;
new_year = GetYear();
// Set new date
Set(new_month, new_day, new_year);
}
}
if ((m == 4)||(m == 6)||(m == 9)||(m == 11) && (d == 30)){
int new_month, new_day, new_year;
new_month = GetMonth() + 1;
new_day = 1;
new_year = GetYear();
// Set new date
Set(new_month, new_day, new_year);
}
if ((m == 2) && (d == 28)){
int new_month, new_day, new_year;
new_month = GetMonth() + 1;
new_day = 1;
new_year = GetYear();
// Set new Date
Set(new_month, new_day, new_year);
}
}
Code:
// Accessor function shtat returns the month
int Date::GetDay(){
return day;
}
// Accessor function shtat returns the month
int Date::GetYear(){
return year;
}
// This function allows the user to change the format setting
bool Date::SetFormat(char f){
if ((f == 'D')||(f == 'd')||(f == 'T')||(f == 't')||(f == 'L')||(f == 'l')){ // if the format codes are either 'D' or 'T' or 'L'
format = f;
return true;
}
else {
return false;
}
}
I believe that everything except for my Increment() is working correctly. Thank you everybody!