Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

Your job is to write a class called Date that has integer data members to store the day, month and year. All...

Your job is to write a class called Date that has integer data members to store the day, month and year. All data members should be private. 

Member functions

All member functions should be public unless otherwise noted.

Write a constructor function for your class that has no parameters. The constructor should set the month to 1 (January), the day to 1 and the year to 2001.

Write a "set" member function that allows a new date to be stored in an existing Date object. The function should have 3 integer parameters - one each for the month, day and year. The purpose of these parameters is to provide the values to be stored in the data members of the object. Your set function should do validation checking on the data supplied in the parameters as follows:

  • The month should be between 1 and 12 (inclusive).
  • The day should be between 1 and 31 (inclusive). 
  • The year should be between 1950 and 2020 (inclusive).

If one or more of the parameters contains invalid values, do not update any data members of the object. Otherwise, store the information from the parameters into the corresponding data members of the object.

The prototype might look like:        void set(int theMonth, int theDay, int theYear); 

Write three "print" member functions. Each should print a Date in one of the following formats:       3/15/2012       March 15, 2012       15 March 2012Important: these are class member functions that print the date stored in a Date object.

Your prototypes might look like:        void printNumeric( );        void printAmerican( );        void printEuropean( );

Alternate implementation for "print" functions: Generally you should avoid doing any input or output in a class member functions (the application programmer should have control over input and output). Displaying an object in some standard format is an exception to this rule, but you might want to have these functions return the formatted date as a string so that the application can do the printing.

Your class should also have a private member function that returns the month name as a string. For example, if the Date object holds the date 3/15/2010, this function would return the string "March". The function prototype might look like:        string getMonthName( ); Your print functions that need to display a month name should use this function.

Testing 

Write a main function to test your class. Be sure that your output shows that each of your member functions works. And be sure that you try invalid data as well as valid data.

Other Requirements

  • Global variables are variables that are declared outside any function. Do not use global variables in your programs. Declare all your variables inside functions.
  • Use the C++ string class to represent strings in your program.
Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question