Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Enhancing class Date) Modify the Date class of Figs. 9.17-9.18 to perform error

ID: 3631384 • Letter: #

Question

(Enhancing class Date)
Modify the Date class of Figs. 9.17-9.18 to perform error checking on the initializer values for data members month, day and year. Also, provide a member function nextDay to increment the day by one. Write a program that tests function nextDay in a loop that prints the date during each iteration to illustrate that nextDay works correctly. Be sure to test the following cases:

a)incrementing into the next month.
b)incrementing into the next year.

(Also, provide screenshot when uploading answer.)

Explanation / Answer

please rate - thanks

don't have the book, message me if any problems. you should be able to use this

#include <iostream>
#include <string>
using namespace std;
int validdate(int,int,int);
class Date
{

private: int month,day,year;

public:
Date(int m, int d, int y)
{int max=28;
bool good=true;
    if (d<= 0)
        good=false;;
    switch(m)
    {
        case 1 :
        case 3 :
        case 5 :
        case 7 :
        case 8 :
        case 10:
        case 12: if (d > 31)
                    good=false;
                    break;
        case 4 :
        case 6 :
        case 9 :
        case 11: if (d > 30)
                      good=false;
                      break;
        case 2 : if((y%4==0&&y%100!=0)|| y%400==0)
                        max=29;
                 if (d >max) good=false;
             
    }
if(good)
{
month=m;
day=d;
year=y;
}
else
   {cout<<"invalid date-default date 1-1-2000 used ";
    month=1;
    day=d;
    year=y;
    }
}

void Date::nextDay()
{int max=28;
   switch(month)
    {
        case 1 :
        case 3 :
        case 5 :
        case 7 :
        case 8 :
        case 10:
        case 12: max=31;
                 break;
        case 4 :
        case 6 :
        case 9 :
        case 11: max=30;
                 break;
        case 2 : if((year%4==0&&year%100!=0)|| year%400==0)
                        max=29;
        }
day++;
if(day>max)
     {month++;
     day=1;
     if(month>12)
         {year++;
          month=1;
          }         
    }
}
void Date::printday()
{string mth[]={"January","February","March","April","May","June","July","August",
"September","October","November","December"};
cout<<day<<" "<<mth[month-1]<<" "<<year<<endl;
}



int Date::getmonth()
{
return month;
}
int getday()
{
return day;
}
int Date::getyear()
{
return year;
}
void Date::setmonth(int m)
{month=m;}
void Date::setday(int d)
{day=d;
}
void Date::setyear(int y)
{year=y;
}
};
int main()
{
int m,d,y,i;

cout<<"Enter month: ";
cin>>m;
cout<<"Enter day: ";
cin>>d;
cout<<"Enter year: ";
cin>>y;
cout<<endl;

Date dd(m,d,y);
dd.printday();
for(i=0;i<100;i++)
     {dd.nextDay();
     dd.printday();
     }
system("pause");
return 0;
}