Modeling a pair of dice using composition in C++ I've written a program all by myself, but I just want to make sure I did it right and if anybody has any suggestions on improving it in any way.


Define and implement the Die class depicted by the following UML diagram to create an ADT for one die (singular of dice) with faces showing values between 1 and the numberOfFaces on the die. Define a two-parameter constructor with defaults of 6 faces and 1 for face value. Define and implement a roll() method to simulate the rolling of the die by generating a random number between 1 and numberOfFaces and storing that number in faceValue. Provide an accessor to return the die’s face value and a print() method to print the die’s face value.
Use composition to design a PairOfDice class, composed of two six-sided Die objects. Create a driver program with a main() function to rolls a PairDice object 1000 times, counting then displaying the number of snake eyes (i.e. two ones) and box cars (i.e. two sixes) that occur.


die.h

#ifndef DIE_H
#define DIE_H

class die {

private:
    int numberOfFaces;
    int faceValue;
public:
    die();
    die(int, int);
    int roll();
    void print();
};
#endif


die.cpp

#include "die.h"
#include&lt;iostream&gt;
#include&lt;ctime&gt;
#include&lt;random&gt;
using namespace std;

die::die()
{
    numberOfFaces=6;
    faceValue=1;
}

die::die(int numOfFaces, int faceVal)
{
    numberOfFaces=numOfFaces;
    faceValue=faceVal;
}

int die::roll()
{
    faceValue=rand()%numberOfFaces;
    return faceValue;
}

void die::print()
{
    cout &lt;&lt; faceValue &lt;&lt; endl;
}


pairOfDice.h

#include "die.h"
#ifndef PAIROFDICE_H
#define PAIROFDICE_H

class pairOfDice :
    public die
{
private:
    die die1;
    die die2;
    int value1;
    int value2;
    int total;
public:
    pairOfDice();
    int roll();
};

#endif


pairOfDice.cpp

#include "pairOfDice.h"

pairOfDice::pairOfDice()
    :die(6,1)
{
    value1=1;
    value2=1;
    total=value1+value2;
}

int pairOfDice::roll()
{
    value1=die::roll();
    value2=die::roll();
    total=value1+value2;
    return total;
}


main.cpp

#include"pairOfDice.h"
#include&lt;iostream&gt;
using namespace std;

int main()
{
    int rolls=0, total=0, snakeEyes=0, boxCars=0;
    pairOfDice dice;

    while(rolls&lt;1000)
    {
        total = dice.roll();

        if(total==2)
            snakeEyes++;
        else if(total==6)
            boxCars++;
        else
            rolls++;
    }

    cout &lt;&lt; rolls &lt;&lt; " " &lt;&lt; snakeEyes &lt;&lt; " " &lt;&lt; boxCars &lt;&lt; endl;
    system("pause");
    return 0;
}
Some miscellaneous remarks unrelated to object-oriented design:


Die face numbering: Your die face values are 0, 1, 2, 3, 4, 5.  That's not how most people expect a six-sided die to be labeled.  It also makes an exceptionally weird definition of rolling snake eyes!
Biased die: Since 6 is not a power of 2, if you just do rand() % 6 then you have a slightly biased die.
Roll miscount: You aren't rolling a pair of dice 1000 times.  You're rolling a pair of dice until you get 1000 results other than 2 or 6.  You could probably have avoided this bug if you had used a for-loop instead of a while-loop, since for-loops impose a standard structure on your code.
Variable declaration: In main(), the variable total is only used within the while-loop, so it should be declared at the point of use: int total = dice.roll();
Seeding: You didn't actually call srand().
Portability: system("pause") is unportable.
ostream support: Consider implementing std::ostream &amp;operator&lt;&lt;(std::ostream &amp;out, ...) for printing.