Topical Information

This program should help clarify to you the use of inheritance (and possibly polymorphism -- see the options below).

Program Information

You recently visited a clock shop and it started you thinking about a virtual clock shop -- perhaps for internet clock sales. Folks could come in (connect to the site) and see how the clocks behaved (alarms, ticking, etc.). Hmm...how to do it?

Aha! All clocks share common attributes, you realize. The different clocks behaviours can be implemented as different methods in each particular clock sub-class. The common attributes in super-classes. It's a tremendous idea!

Hmm...what kinds of attributes do clocks have? Well, they all have a type of power source (battery, solar, pendulum, etc.) and a 'name' (grandfather, alarm, sundial, watch, clock-radio, etc.). They all tell the time (hour, minute, second). They all have a 'face' where they display this time.

And then there are sub-groups of clocks which share attributes. All alarm clocks have a time at which the alarm will go off (at least one). All grandfather clocks chime some tune. All watches have some sort of band or chain to connect them to the person wearing them.

And finally the lowest level groupings like clock-radios, CD-clocks, cuckoo clocks, etc.

Other features which might be more sporadically supplied are: military/12-hour switchability, multiple alarms, temperature, date, sleep timer, etc.


Remember, don't try to do graphics and sound here. Think display a message to get my information across. Perhaps a 'tick-tock' message to show a clock is working. Perhaps a line from a song for the grandfather or clock-radio. Perhaps a 'beep-beep-beep' or 'clang-clang' for an older alarm. Or maybe a 'Ask NOT for whom the bell tolls! It tolls for thee!' for a themed alarm clock.

Visitors to your shop could play with individual clocks to see the feature list, set the alarm and see what it 'sounds' like, see how it displays its time (and date?), etc.


Randomly create clocks to fill your shop. Then let the user search through them with a simple menu interface. Place the clock hierarchy in a library (clocks?) for easy re-use.

Hint: For much of the data above, you can use arrays of C-strings which you randomly index as you create (constructor form of new) or re-assign (call set methods) each clock. Numeric data (all the clocks in even a single house -- much less clock store -- are hardly ever on the same time) can simply be randomized as you've done previously.

Thought Provoking Questions

  1. How many classes are in the hierarchy? How many levels does this hierarchy have?

  2. What members did you make protected? Private?

  3. What kind of inheritance mode(s) did you use for your inheritance?

  4. Have you used any composition? Or is your entire program dependant on inheritance?

  5. How many arrays do you have to hold your shop's inventory of clocks? How 'weildy' is this (how many arrays must you pass to the menu functions, for instance)?

This assignment is (Level 4).

Options

Add (Level 2) to extract the common interfaces and make the hierarchy polymorphic.

More Thought Provoking Questions

  1. How many arrays will you now need to store all of the clocks in your store?

  2. What methods did you make virtual?