Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ code Please use QString and QTextStream instead of string and iostream for this program Thanks, i always give thumbs up! 8. Design and implement

C++ code
Please use QString and QTextStream instead of string and iostream for this program
Thanks, i always give thumbs up!
image text in transcribed
image text in transcribed
8. Design and implement a Date class based on Figure 2.8, subject to the follow- ing restrictions and suggestions. Date m_DaysSinceBase Date: int + Date() + Dately:int, m:int, dint) + setly:int, m:int, dint) + toString(brief : bool) + set To Today() + getWeekDay(): string + lessThand: const Date): bool + equals(d: const Date&): bool + daysBetween(d: const Date&): int + addDays(days : int) : Date + leapYear year int) bool + monthName month : int): string + yearDays year intint + monthDays month: int year: int): int ymd2dsbdlyint, mint Rintint - getYMDyint, mint&, d:int) FIGURE 2.8 Date UML Class Diagram 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 year, month, day 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 mem- ber 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 ymd2 dsbd () function described earlier. 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 statie 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 func- tions 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 uses the system clock to deter- mine 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 (1 + tp->tm_mon, tp->tm_mday, 1900 + tp->tm year); } The getWeekDay() function returns the name of the week day corre- sponding to the stored date. Use this in the fancy version of tostring(). Hint: Jan 1, 1900, was a Monday

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

Step: 3

blur-text-image

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 2015 Porto Portugal September 7 11 2015 Proceedings Part 1 Lnai 9284

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Carlos Soares ,Joao Gama ,Alipio Jorge

1st Edition

3319235273, 978-3319235271

More Books

Students also viewed these Databases questions

Question

3 The distinction between microeconomics and macroeconomics.

Answered: 1 week ago