Generate the Norwegian equivalent to social security numbers - follow-up First of, here is my previous post.

That should explain a fair bit. The reason I'm posting one more time, is I have changed a lot. Using more classes, let them do all the work, and the overall structure. 

#include &lt;iostream&gt;

const int DATE_LENGTH = 6;

class Date {
    private:
        char *ans;
    protected:
        int date[DATE_LENGTH];
        int year;
    public:
        Date() {
            askForDate();
        }

        ~Date() {
            if(ans) { delete ans; }
        }

        void askForDate() {
            using namespace std;
            ans = new char[DATE_LENGTH];
            cout &lt;&lt; "Date of Birth (DDMMYY): ";         cin.getline(ans, DATE_LENGTH + 1);
            while (!validDate(ans)) {
                cin.getline(ans, DATE_LENGTH + 1);
            }

            for (int i = 0; i &lt; DATE_LENGTH; i++) { date[i] = int(ans[i] - '0'); }
            year = 1900 + date[4] * 10 + date[5];
        }

        bool validDate(const char *d) {
            return strlen(d) == 6;
        }
};

class IndividSiffer : public Date {
    protected:
        int i1, i2, i3; 
    public:
        IndividSiffer(int ii1, int ii2, int ii3) : i1(ii1), i2(ii2), i3(ii3) {}

        void individSiffer() {
            static int individ = -1;
            if(year &gt;= 1900 &amp;&amp; year &lt;= 1999 ){
                individ++;
                i1 = i2 = i3 = 0;
            }
            i3 = individ % 10;
            if(individ &lt; 100){
                i1 = 0;
                i2 = individ / 10 % 10;
            }else if(individ &lt; 10){
                i1 = i2 = 0;
            }else{
                i1 = individ / 100 % 10;
                i2 = individ / 10 % 10;
            }
        }
};

class KontrollSiffer : public IndividSiffer {
    protected:
        int k1, k2;
    public:
        KontrollSiffer(int kk1 = 0, int kk2 = 0, int i1 = 0, int i2 = 0, int i3 = 0) : IndividSiffer(i1, i2, i3), k1(kk1), k2(kk2) {
            for (int index = 0; index &lt; 500; index++) {
                individSiffer();
                generate();
            }
        }

        void generate() {
            using namespace std;
            k1 = 11 - ((3*date[0] + 7*date[1] + 6*date[2] + 1*date[3] + 8*date[4] + 9*date[5] + 4*i1 + 5*i2 + 2*i3) % 11); 
            if(k1 == 11){ k1 = 0; }
            k2 = 11 - ((5*date[0] + 4*date[1] + 3*date[2] + 2*date[3] + 7*date[4] + 6*date[5] + 5*i1 + 4*i2 + 3*i3 + 2*k1) % 11);
            if(k2 == 11){ k2 = 0; }
            if((i3 != 0 &amp;&amp; i3 != 2 &amp;&amp; i3 !=4 &amp;&amp; i3 !=6 &amp;&amp; i3 !=8) &amp;&amp; (k1 != 10 &amp;&amp; k2 !=10)){
                for (int i = 0; i &lt; DATE_LENGTH; i++) { cout &lt;&lt; date[i]; }
                cout &lt;&lt; i1 &lt;&lt; i2 &lt;&lt; i3 &lt;&lt; k1 &lt;&lt; k2 &lt;&lt; endl;
            }   
        }
};

int main(int argc, char *argv[]) {
    KontrollSiffer k;
    return 0;
}


I'd really like some input on how I structured it, or if things should be done differently.
Here are some suggestions which may help you improve your code.

Don't abuse using namespace std

Putting using namespace std within your program is generally a bad habit that you'd do well to avoid.  

Use the appropriate #includes

The code uses the strlen() function a number of places but does not #include &lt;cstring&gt; which is where that library function is defined.

Eliminate unused variables

This code declares main with arguments argc and argv in the usual way, but neither argc nor argv are actually used.  This could be addressed by either declaring int main() or by modifying the code to actually use the variables.  There is a third way, which is to declare it as int main(int, char *[]) but this is not recommended because it's a bit confusing to read.

Separate I/O from object creation

The Date class should not do I/O directly to std::cout and std::cin.  Better design would be to create a custom inserter and custom extractor for the class to allow but not to force I/O operations for the creation of an object.  For example, your Date class might have the following two definitions:

std::ostream &amp;operator&lt;&lt;(std::operator &amp;out, const Date &amp;d);
std::istream &amp;operator&gt;&gt;(std::operator &amp;in, Date &amp;d);


The same is true of the KontrollSiffer class.

Perform better error checking for user input

As it is currently written, one can type in "Norway" as the Date and the code proceeds to proces that input as though it were a valid date, producing invalid results.  Better would be to include more checking beyond just whether the string is 6 characters long.

Prefer std::string to raw char *

The Date class uses a raw char * but would probably be better served by using std::string in this context.  

Use aggregation rather than inheritance for composition

The inheritance mechanism is generally suited for "is-a" relationships.  For example, if one had a Birthday class, it might reasonably be derived from a Date base class, since a Birthday is a Date.  However, an IndividSiffer is not really a Date, but is rather constructed from one, so a better design might either have a Date as a private instance variable with the IndividSiffer class or to simply accept a const Date &amp; variable as an argument to an IndividSiffer constructor.

Don't keep variables you don't need

The ans variable is only actually used within the askForDate() routine, so there's no reason to keep it as part of the Date class.  Better would be to declare it as a local variable within the askForDate() function.

Prefer to avoid using new and delete directly

The ans variable within the Date::askForDate() function is small enough to easily fit on the stack, so rather than using new to allocate it, better would be to declare it locally within the askForDate function as:

char ans[DATE_LENGTH];


That way, it is automatically created with the correct length and then discarded when the function is complete.  

Think carefully about static variables

The code for IndividSiffer::individSiffer() uses a static variable individ which is a problem.  When you create two IndividSiffer instances in the same program, only the first one will have the variable initialized.  That is because a static variable only gets initialized once before the program is run.  This very greatly limits the use of these classes.

Consider using a standard container

The effect of the KontrollSiffer class is to create and print 500 individual numbers.  Rather than simply print and discard them, it might be more sensible for general use to create a collection of them, perhaps in a std::vector&lt;IndividSiffer&gt; for example.

Omit return 0

If your program completes successfully, the return 0 at the end of main() will be generated automatically, so it's not needed in C++ programs.