Question: In the code below, add the following: PLEASE NOTE EVERY ADDITION TO THE CODE for example: //added method 1. Add another member method named convert()

In the code below, add the following:

PLEASE NOTE EVERY ADDITION TO THE CODE for example: //added method

1. Add another member method named convert() to the Date Class program above that does the following: The method should access the month, year, and day data members and display and then return an integer calculated as year 10000 + month 100 + day. For example, if the date is 4/1/2014, the returned value is 20140401. Then sdd a call to the convert() member function in the main function

2. Add to the Date class definition an additional member method named leapyr() that returns a true if the year is a leap year and a false if its not a leap year. A leap year is any year thats evenly divisible by 4 but not by 100, with the exception that all years evenly divisible by 400 are leap years. For example, the year 1996 is a leap year because its evenly divisible by 4 and not evenly divisible by 100. Then add a call to the leapyr() method in the main() function. The main() function should display the message The year is a leap year or the message The year is not a leap year (depending on the Date objects year value).

3. Add a member method named dayOfWeek() to Date class definition that determines the day of the week for any Date object. An algorithm for determining the day of the week is the following: If mm is less than 3 mm = mm + 12 and yyyy = yyyy - 1 Endif Set century = int(yyyy/100) Set year = yyyy % 100 Set T = dd + int(26 * (mm + 1)/10) + year + int(year / 4) int(century / 4) - 2 * century Set DayOfWeek = T % 7 If DayOfWeek is less than 0 DayOfWeek = DayOfWeek + 7 Endif Using this algorithm, the variable DayOfWeek has a value of 0 if the date is a Saturday, 1 if a Sunday, and so forth. Add a call to the dayOfWeek() member function. The main() function should display the name of the day (Sun, Mon, Tue, and so on) for the Date object being tested

4. Modify the Date class to include a nextDay() method that increments a date by one day and modify the Date class to include a priorDay() method that decrements a date by one day.

5. Modify the Date class to contain a method that compares two Date objects and returns the larger of the two. The method should be written according to the following algorithm: Accept two Date values as parameters Determine the later date by using the following procedure: Convert each date into an integer value having the form yyyymmdd (This can be accomplished with the formula year * 10000 + month * 100 + day) Compare the corresponding integers for each date The larger integer corresponds to the later date Return the later date

THIS IS THE CODE

#include #include using namespace std;

//class declaration section class Date { private: int month; int day; int year; public: Date(int = 4, int = 7, int = 2018); //constructor with default values void setDate(int, int, int); //member function to copy a date void showDate(); //member function display a date };

// class implementation section Date::Date(int mm, int dd, int yyyy) { month = mm; day = dd; year = yyyy; }

void Date::setDate(int mm, int dd, int yyyy) { month = mm; day = dd; year = yyyy; return; }

void Date::showDate() { cout << "The date is "; cout << setfill('0') << setw(2) << month << '/' << setw(2) << day << '/' << setw(2) << year % 100; // extract the last 2 year digits cout << endl; return; }

int main() { Date a, b, c(2,1,2019); b.setDate(12,25,2018); a.showDate(); b.showDate(); c.showDate(); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!