COSC 1337 - Programming Fundamentals II
Bob Comer, Professor of Computer Studies
Assignment 4 - Date class
Be sure to read through Chapter 7 Structured Data and Classes before starting this assignment. 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 parameter is to provide the values to be stored in the data members of the obbject. The function should do validation checking on the data supplied in the parameters as follows:
Write three "print" member functions. Each should print a Date in one of the following formats:
3/15/2010
March 15, 2010
15 March 2010
Your class should also have a private member function that returns the month name as a string. For example, if the date is 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.
Note: As noted in the textbook, generally it is best not to do any input or output in member functions. One exception is when a member function is designed to perform a specific output operation, such as printing an object in a standard format.
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
Return to Programming Fundamentals II Home Page
Copyright: ©2013 by the Austin Community College
Department of Computer Studies. All rights reserved.
Comments to: Bob Comer
Last updated: January 1, 2013