69. Generating social security numbers

The formats for both countries are very similar, although several details are different:

  • The value of the digit for the sex
  • The length of the random part, and therefore the length of the entire number
  • The number the checksum must be a multiple of

This problem can be solved using the template method design pattern, which defines the skeleton of an algorithm and lets subclasses redefine particular steps:

social_number_generator is a base class that has a public method called generate() that produces a new social security number for a specified sex and birth date. This method internally calls several protected ...

Get The Modern C++ Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.