Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Please Figure 2.8. Date UML Class Diagram Design and implement a Date class based on Figure 2.8, subject to the following restrictions and suggestions.

C++ Please

Figure 2.8. Date UML Class Diagram

image text in transcribed

Design and implement a Date class based on Figure 2.8, subject to the following restrictions and suggestions.

Each Date must be stored as a single integer equal to the number of days since the fixed base date, January 1, 1000 (or some other date if you prefer). Call that data member m_DaysSinceBaseDate.

The base year should be stored as a static int data member (e.g., 1000 or 1900).

The class has a constructor and a set function that have month, day, year parameters. These three values must be used to compute the number of days from the base date to the given date. We have specified a private member function named ymd2dsbd() to do that calculation for both.

The toString() function returns a representation of the stored date in some standard string format that is suitable for display (e.g., yyyy/mm/dd). This involves reversing the computation used in the ymd2dsbd() function described above. We have specified a private member function named getYMD() to do that calculation. We have also suggested a parameter for the toString() function (bool brief) to provide a choice of date formats.

We have specified some static utility functions (e.g., leapyear()) that are static because they do not affect the state of any Date objects.

Make sure you use the correct rule for determining whether a given year is a leap year!

Create a file named date.h to store your class definition.

Create a file named date.cpp that contains the definitions of all the functions declared in date.h.

Write client code to test your Date class thoroughly.

Your class should handle "invalid" dates in a reasonable way (e.g., year earlier than the base year, month or day out of range, etc.).

Here is the code for setToToday() that makes use of the system clock to determine today's date. You need to #include (from the C Standard Library) to use this code.

void Date::setToToday() { struct tm *tp = 0; time_t now; now = time(0); tp = localtime(&now); set(1900 + tp->tm_year, 1 + tp->tm_mon, tp->tm_mday); } 

getWeekDay() function returns the name of the week day corresponding to the stored date. Use this in the fancy version of toString(). Hint: Jan 1, 1900, was a Monday.

Date m DaysSinceBaseDate: int + Date() Date(y int, m int, d: int) +set(y: int, m: int, d: int) +toString(brief: bool): string setToToday() +getWeekDay) string + lessThan(d: const Date&): bool + equals(d: const Date&): bool + daysBetween(d: const Date&) int + addDays(days: int) Date + leapYear(vear: int) : bool + monthName(month : int): string + yearDays(year: int): int + monthDays(month : int, year: int): int ymd2dsbd(y: int, m: int, _d: int): int getYMD(y : int&, m: int&, d: int&) Date m DaysSinceBaseDate: int + Date() Date(y int, m int, d: int) +set(y: int, m: int, d: int) +toString(brief: bool): string setToToday() +getWeekDay) string + lessThan(d: const Date&): bool + equals(d: const Date&): bool + daysBetween(d: const Date&) int + addDays(days: int) Date + leapYear(vear: int) : bool + monthName(month : int): string + yearDays(year: int): int + monthDays(month : int, year: int): int ymd2dsbd(y: int, m: int, _d: int): int getYMD(y : int&, m: int&, d: int&)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2018 Dublin Ireland September 10 14 2018 Proceedings Part 1 Lnai 11051

Authors: Michele Berlingerio ,Francesco Bonchi ,Thomas Gartner ,Neil Hurley ,Georgiana Ifrim

1st Edition

3030109240, 978-3030109240

More Books

Students also viewed these Databases questions