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

Date& operator++(){ //add 1 to d //tomorrow, unless we were at the end of the mo

ID: 3652336 • Letter: D

Question

Date& operator++(){
//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
// 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 function which repeatedly reads a Date with
cin >>, increments the Date with your ++, and prints "Tomorrow is" and the
new value of the Date using cout <<.

//Chrono.h

namespace Chrono {


Class Date {

public:

enum Month {

jan=1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec

};

class Invalid { }; // to throw as exception

Date(int y, Month m, int d); // check for valid date and initialize

Date(); // default constructor

// the default copy operations are fine

// non-modifying operations:

int day() const { return d; }

Month month() const { return m; }

int year() const { return y; }


// modifying operations:

void add_day(int n);

void add_month(int n);

void add_year(int n);

int y;

Month m;

int d;

};


bool is_date(int y, Date::Month m, int d); // true for valid date


bool leapyear(int y); // true if y is a leap year


bool operator==(const Date& a, const Date& b);

bool operator!=(const Date& a, const Date& b);

Date operator++(Date a);

ostream& operator<<(ostream& os, const Date& d);

istream& operator>>(istream& is, Date& dd);

const Date& default_date();

}



// Chrono


add the code for add_month and
add_day. Write a mainwhich repeatedly reads a Date with
cin >>, uses add_month and add_day to add two months and two days to the
Date, and prints "Two months and two days later will be " followed by the
new value of the Date using cout <<.

*Hint*Though inefficient, a simple way
to implement add_day is to call your ++ the right number of times.
In add_month, check for landing on February 29th in a non-leap year (like
add_year does) and check for going past December (like your ++ does).

Explanation / Answer

//Try this code.its lot simpler to understand .Just give the date as an input and others //are almot same .thnx..... #include "stdafx.h" #include #include #include using namespace std; class Date { private: int month; int day; int year; static string slash; void setMonth(int); void setDay(int, int); void setYear(int); public: void IncreaseDay(int, int, int); void setDate(int, int, int); void showDate(); }; string Date::slash = "/"; void Date::setDate(int Mon, int Da, int Yea) { setMonth(Mon); setDay(Da, Mon); setYear(Yea); IncreaseDay(Mon, Da, Yea); } void Date::setMonth(int Mon) { if(Mon > 12) month = 12; else month = Mon; } void Date::setDay(int Da, int Mon) { if(Mon = 2 && Da < 29) day = Da; else day = 28; if((Mon = 1 || 3 || 5 ||7 ||9 || 10 || 12) && (Da < 32)) day = Da; else day = 31; if((Mon = 4 || 6 || 8 || 11) && (Da < 31)) day = Da; else day = 30; } void Date::setYear(int Yea) { year = Yea; } void Date::IncreaseDay(int Mon, int Da, int Yea) { if((Mon = 2) && (Da > 28)) { month++; day = 1; } else if((Mon = 1 || 3 || 5 || 7 || 9 || 10) && (Da >= 32)) { month++; day = 1; } else if((Mon = 4 || 6 || 8 || 11) && (Da >= 31)) { month++; day = 1; } else if((Mon >= 12) && (Da >= 32)) { month = 1; day = 1; year++; } } void Date::showDate() { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote