Write a main function in CPP that performs the following function: repeatedly re
ID: 3651264 • Letter: W
Question
Write a main function in CPP that performs the following function:repeatedly reads a Date with cin >>, increments the Date with your ++, and prints "Tomorrow is" and the
new value of the Date using cout <<.
We have the operator operator++ which is the following:
Date& Date::operator++()
{
d++;
if(!is_date())
{
m++;
d=1;
}
if(m>12)
{
m=1;
y++;
}
else
{
m++;
}
return *this;
}
We also put in the input year, month, day as specified by our header, Chrono.h and our cpp file which defines the operator++ Chrono.cpp.
Explanation / Answer
#include #define TRUE 1 #define FALSE 0 using namespace std; class mydate{ int day; int month; int year; public: void readdate(); int isLeapYear(); string month2string(); int exceedsDaysInMonth(); void tommorow(); }; // Input date from user void mydate::readdate(){ cout > day; cout > month; cout > year; } // make sure month days are correct // return TRUE if days exceeds in a month int mydate::exceedsDaysInMonth(){ int days[] = {31,28,31,30,31,30,31,31,30,31,30,31}; if ( month < 1 || month > 12 || day > days[month-1]) return TRUE; else return FALSE; } // convert numeric month into string string mydate::month2string(){ char *months[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; if ( exceedsDaysInMonth() ) { if ( ! (month < 1 || month > 12) ) return months[month-1]; else return "Unknown month"; } else return "Unknown month"; } // return TRUE if a year is leap int mydate::isLeapYear(){ if ( (year % 4) != 0 ){ return FALSE; } else if ( (year % 400) != 0 ){ return TRUE; } else if ( (year % 100) == 0 ){ return FALSE; } else { return FALSE; } } // validate and calculate tommorows date void mydate::tommorow(){ int td, tm, ty; int days[] = {31,28,31,30,31,30,31,31,30,31,30,31}; if ( year < 0 ){ cerrRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.