coins/TwelveCoins.cpp
/**
 * @brief: Generates an input and answer file. The input file contains 12 numbers all being the same
 *           apart from one which may be any number between 0 and 20. The answer file specifies which
 *           number was different by writing it's index value and it's integer value.
 * 
 * @return:Returns 0 if completed successfully.
 */
@brief: Generates an input and answer file. The input file contains 12 numbers all being the same
apart from one which may be any number between 0 and 20. The answer file specifies which
number was different by writing it's index value and it's integer value.

@return:Returns 0 if completed successfully.
@brief : Generates an input and answer file . The input file contains 12 numbers all being the same apart from one which may be any number between 0 and 20 . The answer file specifies which number was different by writing it ' s index value and it ' s integer value . @return : Returns 0 if completed successfully .
int TwelveCoins::generate(int size)
{
    std::ofstream myinput, myanswer;
    myinput.open (COINSINPUTFILE);
    myanswer.open (COINSANSWERFILE);
    srand(time(NULL));
    myinput << "# Generate input of size: " << size << "\n";
    myanswer << "# Generate answer of size: " << size << "\n";
    for (int i = 0;i < size; i++) {
        int randIndex = -1;
        int randWeight = normalWeight;
            randWeight = std::rand() % 21; 
        randIndex = std::rand() % 12; 
        for (int i = 0; i < 12; i++) {
            if (i == randIndex)
                myinput << randWeight << " ";
            else
                myinput << "10 ";
        }
        myinput << "\n";
        if (randWeight == normalWeight)
            randIndex = -1;
        myanswer << randIndex << " " << randWeight << "\n";
    }
    myinput.close();
    myanswer.close();
    return 0;
}
int TwelveCoins :: generate ( int size ) { std :: ofstream myinput , myanswer ; myinput . open ( COINSINPUTFILE ) ; myanswer . open ( COINSANSWERFILE ) ; srand ( time ( NULL ) ) ; myinput << " " << size << " \n " ; myanswer << " " << size << " \n " ; for ( int i = 0 ; i < size ; i ++ ) { int randIndex = -1 ; int randWeight = normalWeight ; randWeight = std :: rand ( ) % 21 ; randIndex = std :: rand ( ) % 12 ; for ( int i = 0 ; i < 12 ; i ++ ) { if ( i == randIndex ) myinput << randWeight << " " ; else myinput << " " ; } myinput << " \n " ; if ( randWeight == normalWeight ) randIndex = -1 ; myanswer << randIndex << " " << randWeight << " \n " ; } myinput . close ( ) ; myanswer . close ( ) ; return 0 ; }
@brief: Generates an input and answer file.
@brief : Generates an input and answer file .
//while (randWeight == normalWeight) // range from 0 to 20 0,1,2,3,4,5,6,7,8,9 11,12,13,14,15,16,17,18,19,20 // 0,1,2,3,4,5,6,7,8,9,10,11