Forum Replies Created

Viewing 3 posts - 91 through 93 (of 93 total)
  • Author
    Posts
  • in reply to: ENHANCEMENTS IN C HELP?! #3461
    GWILouisaxwzkla
    Participant

    Which operation system ( Windows , DOS , ect. ) ?

    in reply to: coin toss #3459
    GWILouisaxwzkla
    Participant

    Small change:

    /****************************************************************
    * File Name : c:programshelppermutations.cpp
    * Date : August,1,2002
    * Comments : new project
    * Compiler/Assembler :
    *
    *
    *
    *
    *
    * Program Shell Generated At: 5:59:12 p.m.
    =-=-=-=-=-=-=-=–=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

    #include < iostream >
    //#include < string.h >
    //#include < conio.h >
    //#include < math.h >
    //#include < iomanip >
    //#include < ctype.h >

    using namespace std;

    //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@

    void coinPermutations ( int flips , char * permutations );
    void coinPermutations ( char face , int flips , char * permutations );

    //##################################################################################

    //main function ******************************

    int main ( )
    {
    int numberOfFlips;

    cout << "enter number of flips: ";
    cin >> numberOfFlips;
    cout << "permutations: " << endl;
    char * permutations = new char [ numberOfFlips + 1 ];
    coinPermutations ( numberOfFlips , permutations );
    delete [] permutations;

    return 0 ;
    }

    /******************************* FUNCTION DEFINITION ******************************

    Name : coinPermutatins
    Parameters :

    face a(n) char

    Returns: Void type
    Comments:

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    void coinPermutations ( int flips , char * permutations )
    {

    permutations [ flips ] = 0;
    coinPermutations ( ‘h’ , flips – 1, permutations );
    coinPermutations ( ‘t’ , flips – 1, permutations );

    return;
    }
    /******************************* FUNCTION DEFINITION ******************************

    Name : coinPermutatins
    Parameters :

    face a(n) char

    Returns: Void type
    Comments:

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    void coinPermutations ( char face , int flips , char * permutations )
    {

    if ( flips == 0 )
    {
    permutations [ flips ] = face;
    cout << permutations << endl;
    return;
    }

    permutations [ flips ] = face;
    coinPermutations ( ‘t’ , flips – 1 , permutations ) ;
    coinPermutations ( ‘h’ , flips – 1 , permutations );

    return;
    }

    in reply to: coin toss #3458
    GWILouisaxwzkla
    Participant

    This seems to work:

    /****************************************************************
    * File Name : c:programshelppermutations.cpp
    * Date : August,1,2002
    * Comments : new project
    * Compiler/Assembler :
    *
    *
    *
    *
    *
    * Program Shell Generated At: 5:59:12 p.m.
    =-=-=-=-=-=-=-=–=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

    #include < iostream >
    //#include < string.h >
    //#include < conio.h >
    //#include < math.h >
    //#include < iomanip >
    //#include < ctype.h >

    using namespace std;

    //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@

    void coinPermutations ( int flips , char * permutations );
    void coinPermutations ( char face , int flips , char * permutations );
    //##################################################################################

    //main function ******************************

    int main ( )
    {
    int numberOfFlips;

    cout << "enter number of flips: ";
    cin >> numberOfFlips;
    cout << "permutations: " << endl;
    char * permutations = new char [ numberOfFlips ];
    coinPermutations ( numberOfFlips , permutations );
    delete permutations;

    return 0 ;
    }

    /******************************* FUNCTION DEFINITION ******************************

    Name : coinPermutatins
    Parameters :

    face a(n) char

    Returns: Void type
    Comments:

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    void coinPermutations ( int flips , char * permutations )
    {

    permutations [ flips ] = 0;
    coinPermutations ( ‘h’ , flips – 1, permutations );
    coinPermutations ( ‘t’ , flips – 1, permutations );

    return;
    }
    /******************************* FUNCTION DEFINITION ******************************

    Name : coinPermutatins
    Parameters :

    face a(n) char

    Returns: Void type
    Comments:

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    void coinPermutations ( char face , int flips , char * permutations )
    {

    if ( flips == 0 )
    {
    permutations [ flips ] = face;
    cout << permutations << endl;
    return;
    }

    permutations [ flips ] = face;
    coinPermutations ( ‘t’ , flips – 1 , permutations ) ;
    coinPermutations ( ‘h’ , flips – 1 , permutations );

    return;
    }

    output:

    enter number of flips: 4
    permutations:
    ttth
    htth
    thth
    hhth
    tthh
    hthh
    thhh
    hhhh
    tttt
    httt
    thtt
    hhtt
    ttht
    htht
    thht
    hhht
    Press any key to continue

Viewing 3 posts - 91 through 93 (of 93 total)