2012年2月21日 星期二

Exercise #10


This assignment will give you practice with overloaded operator functions.
Create a Date class to represent calendar dates. 
The class should contain the following members:
  • Three unsigned short data members to represent day, month, and year.
  • A static const unsigned short 12-element array containing the number of days in each month.
  • A constructor that initializes the three unsigned short members.
It should contain the following overloaded operator member functions:
  1. A ! operator that prints a Date object using the format mm/dd/yy.
  2. A prefix ++ operator that adds a day to a Date object. It should return the object by reference.
  3. A postfix ++ operator that adds a day to a Date object. It should return the object by value.
  4. A prefix -- operator that subtracts a day from a Date object. It should return the object by reference.
  5. A binary + operator with an unsigned short argument. This function should add a number of days to a date object. Use call(s) to the prefix ++ operator in your function definition. It should return a Date object by value.
  6. A binary - operator with an unsigned short argument. This function should subtract a number of days from a date object. Use call(s) to the prefix -- operator in your function definition. It should return a Date object by value.
  7. A += operator with with an unsigned short argument. This function should add a number of days to a date object. Use call(s) to the prefix ++ operator in your function definition. It should return a Date object by reference.
  8. A == operator that determines if two Date objects are equal. This function should return a bool.
  9. A != operator that determines if two Date objects are not equal. This function should return a bool.
  10. A > operator that determines if the "current" Date object is greater than another Date object. One Date object is greater than another Date object if it occurs after the other object. For example, "03/15/02" > "12/25/01". This function should return a bool.
  11. A binary – operator with a const Date& argument. This function should determine the number of days between two Dates. The function should return an int. For example, "01/03/02" – "12/30/01" . 4 and "12/30/01" – "01/03/02" . -4.
Appropriate member functions should be defined as const member functions

Assumptions
It is not necessary to make leap year corrections for this assignment. Assume that February always has 28 days and that a year is exactly 365 days.
A year value between 0 and 49 represents the years 2000 to 2049. A value between 50 and 99 represents the years 1950 to 1999.

Write a main() that demonstrates each of the overloaded member functions. Your output should demonstrate the validity of each function. 

沒有留言:

張貼留言