Question
Programming Assignment #2 Date Class Educational Objectives. After successfully completing this assignment, the student should be able to accomplish the following: Design a simple class
Programming Assignment #2
Date Class
Educational Objectives. After successfully completing this assignment, the student should be able to accomplish the following:
Design a simple class based on a set of functional specifications
Implement a class of your own design
Implement constructors
Implement simple methods
Implement Set and Get methods for class data
Correctly separate class definition and implementation using separate files
Create, edit, build and run multi-file projects using the Linux/Emacs/Make environment
Objective: This assignment will provide further practice with implementing classes.
Task: For this homework, you will write a class called Date, in the files date.h and date.cpp, as well as a makefile for creating and using objects that will store valid dates of the year.
This class should be portable, so it should work with any up-to-date C++ using the C11 standard compiler. Make sure that it works with g++ before you hand it in. You should write some test programs of your own to test the functionality of the class. Your files will be tested with a driver designed to meet these specifications exactly so pay careful attention to details.
Program Details and Requirements:
1) An object of type Date should represent a calendar date in terms of month, day, and year, as on a 12-month A.D. (anno Domini ) Gregorian calendar. The valid months are January through December, a valid day must correspond to a valid day for the given month, and the year must be a positive number above 1582. Your object should also store a format setting, to be used for display of dates to the screen. There will be more than one possible format. The class features (public interface) should work exactly as specified, regardless of what program might be using Date objects.
Note: For purposes of easy input (from keyboard or into functions), date values will be specified with integers. Month values will be 1 for January, 2 for February, etc... on to 12 for December. A valid day value will be an integer between 1 and the number of days in the month. Valid year values are positive numbers above 1582.
2) Your Date class must provide the following services (i.e. member functions) in its public section. These functions will make up the interface of the Date class. Make sure you use function prototypes as specified here. (You may write any other private functions you feel necessary, but the public interface must include all the functionality described here).
the constructor(s): The Date class should have a constructor that allows the user to specify the values for the month, day, and year, using integer values, when the object is declared. If any of the values would result in an invalid date, the constructor should throw out the erroneous information and initialize the object to represent 1/1/2000 (January 1, 2000) instead. Also, you should allow a Date object to be declared without specified values, in which case it should initialize to 1/1/2000 also.
Example Declarations: These declarations should be legal, and the comment gives the initialized date
Date d1; // initializes to Jan 1, 2000
Date d2(3,4,1992); // initializes to March 4, 1992
Date d3(13,30,1990); // invalid month, initializes to Jan 1, 2000 instead.
void Input() This function should prompt the user to enter a date, and then allow the user to input a date from the keyboard. User input is expected to be in the format month/day/year, where month, day, and year are integer values. Whenever the user attempts to enter an invalid date, the Input function should display an appropriate error message (like "Invalid date. Try again: ") and make the user re-enter the whole date. A few examples of some good and bad inputs:
Legal: 1/4/2000 , 2/28/1996 , 12/31/1845 Illegal: 13/12/1985 , 11/31/2002 , 8/30/-2000
You may assume that the user entry will always be of the form: M/D/Y where M, D, and Y are integers, and the slash characters are always present with no embedded spaces.
void Show() This function should simply output the date to the screen. There will be more than one possible format for this output, however, and your class will need to store a format setting. The Show function should use the format setting to determine the output. (There will be a member function that allows the setting to be changed). When a Date object is created, the format setting should start out at the "Default" setting. The possible formats are shown in the following table:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started