Question: C++ Program. Please read the entire question before answering. Create a C++ class called myDate. It should have the following operations: myDate() default constructor. This

C++ Program. Please read the entire question before answering.

Create a C++ class called myDate. It should have the following operations:

  • myDate() default constructor. This will set the date to May 11, 1959
  • myDate(int M, int D, int Y) overloaded constructor. This will set the date to the values passed in through the parameter list represented by Month, Day and Year.
  • void display() display the date in the following format (May 11, 1959) Do NOT print a linefeed after the date.
  • void increaseDate(int N) increment the date by N days.
  • void decreaseDate(int N) decrement the date by N days.
  • int daysBetween(myDate D) return the number of days between this date and the date D. If date D is a future date, the return value will be a positive int. If date D is in the past, the return value will be a negative int.
  • int getMonth() return the month in integer form
  • int getDay() return the day of the month
  • int getYear() return the year
  • int dayOfYear() - return the number of days since the current year began. Example Jan 1 is 1, Feb 1 is 32.
  • string dayName() returns Monday, Tuesday, etc according to the day of the week.

Write a driver program that tests each operation.

Note:

You can never have a date that is invalid. The only opportunity for this to happen will be with the overloaded constructor. Therefore if any invalid data is passed to this constructor, ignore all data and set the values to the default date.

I have included an explanation of Julian dates. You can make your life much easier by using this formula. The example code is written in FORTRAN.

You will need to use pass by reference for some of the functions in the Julian date converter.

Create 2 functions that are NOT class members. Locate these function in the top portion of the myDate.cpp file. Here are the prototypes for these 2 functions:

int Greg2Julian(int month, int day, int year); // pass in the Month, Day, Year and return Julian number

void Julian2Greg(int JD, int & month, int & day, int & year); // pass in the Julian Date, and get the correct Month, Day and Year through the parameter list pass by reference

conversion from a Gregorian calendar date to a Julian date.

Valid for any Gregorian

calendar date pro

producing a Julian date greater than zero:

INTEGER FUNCTION JD (YEAR,MONTH,DAY)

C

C---COMPUTES THE JULIAN DATE (JD) GIVEN A GREGORIAN CALENDAR

C DATE (YEAR,MONTH,DAY).

C

INTEGER YEAR,MONTH,DAY,I,J,K

C

I= YEAR

J= MONTH

K= DAY

C

JD= K-32075+1461*(I+4800+(J-14)/12)/4+367*(J-2-(J-14)/12*12)

2 /12-3*((I+4900+(J-14)/12)/100)/4

C

RETURN

END

Conversion from a Julian date to a Gregorian calendar date.

SUBROUTINE GDATE (JD, YEAR,MONTH,DAY)

C

C---COMPUTES THE GREGORIAN CALENDAR DATE (YEAR,MONTH,DAY)

C GIVEN THE JULIAN DATE (JD).

C

INTEGER JD,YEAR,MONTH,DAY,I,J,K

C

L= JD+68569

N= 4*L/146097

L= L-(146097*N+3)/4

I= 4000*(L+1)/1461001

L= L-1461*I/4+31

J= 80*L/2447

K= L-2447*J/80

L= J/11

J= J+2-12*L

I= 100*(N-49)+I+L

C

YEAR= I

MONTH= J

DAY= K

C

RETURN

END

Example

: YEAR = 1970, MONTH = 1, DAY = 1, JD = 2440588.

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!