Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

November 2, 2011 was an interesting date. When viewed in the MMDDYYYY format it was a palindrome: 11/02/2011. How often does this happen? We will

November 2, 2011 was an interesting date. When viewed in the MMDDYYYY format it was a palindrome: 11/02/2011. How often does this happen? We will write a C program to find every AD date that is a palindrome: 01/01/0001 (there was no year zero) until 12/31/6000. And we will find the next time a palindrome date will occur.

We will store our dates as an unsigned number that has been typedefed as Date. For example, the number 12312018 will represent Dec 31, 2018. The number 1012019 will represent Jan 1, 2019. Notice that when this Date is stored as an unsigned, the leading zero in the month is not stored. A well-formed Date will be an unsigned number between 1010001 (January 1, 0001) to 12319999 (December 31, 9999). Numbers out of this range are not well-formed Dates.

You must write and use the following functions.

unsigned numDigits ( unsigned num );

This function returns the number of digits in num. This must work on any number.

int nthDigit ( unsigned num, unsigned nth );

This function returns the nth digit of num. The number in the ones place is the zeroth digit. As an example: if num = 12345678 and nth = 0, this function returns 8. If nth is too big, the function returns -1. This must work on any numbers.

Date makeDate ( unsigned m, unsigned d, unsigned y )

This function returns a Date using the month(m), day(d) and year(y) passed in. For example, if m=10, d=31, and y=2019, it would return 10312019

void displayDate (const Date& date, ostream& = cout, DATE_STYLE = MM_DD_YYYY );

This function inserts date into an ostream formatted with one of two DATE_STYLES. Declare an enum DATE_STYLE {MM_DD_YYYY, MON_DD_YYYY}; If the function receives MM_DD_YYYY it will display the date 12312018 as 12/31/2018. Leading zeros, though not stored, will be displayed. 1052019 will be displayed as 01/05/2019. If it receives MON_DD_YYYY it will be displayed as Dec 31, 2018. In this format, all months will be three characters.

Date incrementDate (const Date& date );

This functions increments date to the next day and returns that new Date. Note that you cannot just add one to date and get to the next day.

bool wellFormed (const Date& date );

This function returns true if date is between 1010001 and 12319999. Use global const, MIN_DATE and MAX_DATE to store these values. Notice that a well-formed date is not necessarily a good date. 14321234 (14/32/1234) would be well formed, but not a valid date. Every function that takes a Date as a parameter must check to see if that this Date is well-formed and give an error message if it is not.

unsigned month (const Date& date );

unsigned day (const Date& date);

unsigned year (const Date& date);

These functions return the number of the month, the day, and the year from a date. For an example, if date = 12312018, month would return 12, day would return 31 and year would return 2018.

bool isLeapYear (const Date& date );

This function returns true if the date is in a leap year, false otherwise.

unsigned monthLength(const Date& date );

This function returns the number of days in the month from date. For example, if date = 8122018, month_length returns 31.

bool lessThan (const Date& date1, const Date& date2 );

This function returns true if date1 comes before date2, false otherwise. Note that the number 12312018 is larger than the number 1012019, but the date 12312018 comes before the date 1012019.

bool isPalindrome (const Date& date);

This function returns true if date is a palindrome in MMDDYYYY format, false otherwise. We do not store leading zeros, but will consider them when calculating this. For example, 01/02/2010 is a palindrome even though it is stored as 1022010.

Use standard C file formatting for this assignment.

Name your file: Project1.cpp

You must not convert any number to a string

Do not use any built-in librarys other than iostream

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 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions