Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ This system of programs implements and tests a class that encapsulates various functions related to dates. Here are the specifications: 1. Store the month,

C++

This system of programs implements and tests a class that encapsulates various functions related to dates. Here are the specifications:

1. Store the month, day, and year in separate private integer variables.

2. Your MyDate class will have two constructors. The first one takes no arguments and sets the date to March 27, 2017. The second takes a string in the form MM/DD/YYYY and sets the date to that.

3. Provide accessor functions for the month, day, and year. The mutator functions do not do error checking, since that is beyond the scope of this assignment. Your driver program, described below, will do limited error checking.

4. Provide a function called SetDate that takes a string in the form MM/DD/YYYY and sets the new date. This will return true if the date is valid and false if it is not. However, you can assume that the string will always be in the correct format, with slashes between the components. For example, the function should return false for 3/32/2017.

5. Provide a function ToString() that takes no parameters and returns the date as a string in the form MM/DD/YYYY.

6. Provide an add function that takes an integer as its parameter and adds that number of days to the given date. It returns a string in the form MM/DD/YYYY with the new date.

7. Provide a subtract function that takes an integer as its parameter and subtracts that number of days from the given date.

8. Provide another subtract function that takes a MyDate object and returns the number of days between the two dates.

9. Overload the + operator such that when you add an integer to the MyDate object it functions exactly like the add function.

10. Overload the operator such that when you subtract one MyDate object from another, it returns the integer number of days between the two dates.

Your class should work for dates between 1901 and 2100. Remember that leap years are years that are evenly divisible by 4, and that 2000 was a leap year.

Divide your class into a header file (.h) that has your definitions, and a .cpp file that has your implementation.

Write a program that tests your class. Upon initialization, it will create two MyDate objects. The first will use the default constructor. For the second, your program will ask the user for a date and call the second constructor. It will have a menu with the following options. Your program should request the function number, execute the function, then return to the menu. Invalid menu options should display a message, then return to the menu. Use switch/case for this, not a sequence of if statements:

1. Modify the first date object. When this option is chosen, ask which component, month, day, or year, to modify, and set the value accordingly. Make sure the values are within the range allowed by the object. For example, you can set the day to 29 only if the month is February and the year is a leap year. Thus your program will have to call accessors to make sure you cannot have a bad date.

2. Modify the first date by requesting a string in the form MM/DD/YYYY from the user and asking which date to modify. Set the appropriate MyDate object to have the new date.

3. Display both MyDate objects as strings using your ToString function. Sample output might look like this: Date 1: 3/27/2017 Date 2: 1/1/2000

4. Ask the user for an integer and add that to the first date object using the add function. Display the old and new dates. Test with integers in the range of 1 through 1500. You dont have to test every integer in that range, but certainly test with both ends of the range.

5. Test the overloaded + operator in the same was as shown in (4).

6. Ask the user for an integer and subtract that from the first date object using the subtract function. Display the old and new dates. Test with integers in the range of 1 through 1500. You dont have to test every integer in that range, but certainly test with both ends of the range.

7. Test the overloaded - operator in the same was as shown in (6).

8. Ask the user for two dates and show the number of days between them. That is, subtract the second one from the first one. This will not use the two built-in date objects; you should create new ones for this.

9. Menu option 9 exits the program.

To hand in: Submit three files: MyDate.h, MyDate.cpp, and your driver program

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

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago