Topical Information

This lab will help you practice with 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 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 as would a method to advance to the next month (note that January follows December and begins the cycle anew) or 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, and 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. That means 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 there-of.

Similarly, they'd like to be able to retrieve 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, same. (There may be only one of some methods, but others may need at least two methods to offer all requested functionality.)

(Perhaps if you had a previous library that did stuff with times and/or dates, it might prove useful here?) (Or was the library over here?) (Oh! I know! I saw it right under this...) (Ooo! Here it is!)

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 Output? How can you have two methods called Input? How can your class have four constructors?! It's lunacy! (Hint: O__r_o_di_g.)

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

  4. Does your Input method prompt the user? Why should it not?

  5. Does your Output method(s) print anything besides the month number or name/abbrev. (as requested) (even an endl)? Why should it not?

  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: bool? enumeration?)

  7. What about the Input method? How can it detect what kind of form the user is using and adapt to it? (Hint: peek ahead at what's coming next from cin's buffer?)

  8. Does your driver program do one test per run or does it allow multiple tests of the class 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).


Total Level Possible

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