Topical Information

This lab will help you practice with libraries and classes.

Program Information

Design and code a class that represents a single month of the year. It should have a single integer-typed data member to represent the month. Make sure to provide for proper construction, access, and mutation for this member as well as input and output methods.

In addition, methods for comparing two months chronologically for ordering would be useful. (You know, to decide if the calling month is earlier, later than, or at the same time as the argument month.)

Also a method to advance to the next month would be handy. (Note that January follows December and begins the cycle anew.) You should also be able to move to a previous month. In fact, thinking about it, it might be good to be able to advance to a month an arbitrary number of whole months in the future or past: January + 5 = June; March - 5 = October.

Place your Month class in a library.

Write a test application (driver) for your class.

Oh, BTW, the programmers who commissioned this class wanted to make sure it could handle not only integer-valued representation of a month but also either whole-word names or three-letter abbreviations for the months. By this they mean that they should be able to construct a Month object from either an integer value or a string — which could be either the whole month name or a 3-letter version thereof. (The Month object would still just store a single integer to represent which month it represented, however.)

Similarly, they'd like to be able to retrieve (i.e. access) the Month's information as either an integer value or a string (of either form), mutate the Month by any of these means, display by any of the three forms, and even allow their user to enter any of the three forms at the console.

But, to keep things as simple as possible, they'd not like a whole lot of different names to remember. Please use the following names for all functions that perform such tasks: set_month, get_month, input, output, advance, before, after, and same. (There may be only one of some methods, but others will need at least two overloads to offer full functionality.)

Thought Provoking Questions

  1. Do you have any private methods? Do they help support the translation between number and letter/word name representations which occur at several places in this class' methods? Why would such functions be private? Doesn't the user of the class need to call them?

  2. How can you have two methods called set_month? How can your class have four constructors?! This is lunacy! (Hint: O__r_o_di_g.)

  3. Why didn't you need two versions of your method to advance to the next month? (Hint: What data type is returned?)

  4. Does your input method prompt the user? Why shouldn't it?

  5. Does your output method(s) print anything besides the month number or name/abbrev. (as requested) (even an endl)? Why shouldn't it?

  6. How do you know what display method the programmer desires when your output method is called (terrible pun/vocabulary clash, isn't it?)? (Hint: Is a bool enough? Or do you need an enumeration?)

  7. What about the input method? How can it detect what kind of form the user is using and adapt to it?

  8. Does your driver program do one test per run or does it allow multiple tests of the class' features during a single run? Which seems more convenient for you/the end programmer?

  9. Are the tests in your driver program hard-coded/literal or are they adaptable to the needs of the programmer running the tests? Which would be more useful?

  10. Are the tests your driver can run specifically ordered in some way or can the programmer doing the testing choose what s/he is going to test first, next, ... last? Which would be more convenient/useful?

This assignment is (Level 4).

Options

Total Level Possible

If you did all above options, this lab could be worth as much as (Level 10).