In C++ 3. (20 points) Start with Chrono.h and Chrono cpp in section 9.8: for now
ID: 3825785 • Letter: I
Question
In C++
3. (20 points) Start with Chrono.h and Chrono cpp in section 9.8: for now put a dummy return Sunda or "return d in the last 3 functions on pages 337-338. Add a prefix operator to the Date class by putting the declaration in the Date class in Chrono.h and the definition in Chrono.cpp operator should change a date to "tomorrow" using the following pseudocode Date& operator++01 //add 1 to d //tomorrow, unless we were at the end of the month //if is date is false //need to change to first of next month set d to 1 /L if m is December //need to change to next year too set m to January increment y else increment m return this; Write a main in hw4pr3.cpp which repeatedly reads a Date with cin in a while statement, increments the Date with your and prints "Tomorrow is" and the new value of the Date using cout Zip hw4pr3.cpp, Chrono.h, and Chrono.cpp into one zip file according to your TA's instructions and submit that to CSNETExplanation / Answer
This is the program for printing tomorrow's date after knowing todays date. Hope it helps !!!!
#include<iostream.h>
#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 << "Enter day (dd - 23 ) : ";
cin >> day;
cout << "Enter Month (mm - 04 ) : ";
cin >> month;
cout << "Enter year (yyyy - 2007 ) : ";
cin >> 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 ){
cerr << year << " is not a valid year" << endl;
exit(1);
}
if ( exceedsDaysInMonth() ){
if ( month == 2 && day == 29 ){
if ( ! isLeapYear() ){
cerr << year << " is not a leap year, so Feb doesn't have 29 days" << endl;
exit(1);
}
}
else
{
cerr << "Bad day value month - " << month << " (" << month2string();
cerr << ") doesn't have " << day << " days "<< endl;
exit(1);
}
}
// calculate tommorow
td=day;
tm=month;
ty=year;
td++;
if ( td > days[month-1]){
td=1;
tm++;
if ( tm > 12 )
{ ty++; tm=1; }
}
cout << "Valid date, found and tommorow is " << td << "/" << tm << "/" << ty << endl;
}
// main
int main(){
mydate date;
date.readdate();
date.tommorow();
return 0;
}