Forum Replies Created

Viewing 15 posts - 1 through 15 (of 93 total)
  • Author
    Posts
  • in reply to: can we make program without header files? #3645
    GWILouisaxwzkla
    Participant

    You could do this if you choose to write everything from scratch ( you will need to write your own input / output functions in assembly language for DOS I’m not sure if you can do this for Windows , though ). I’ll see if I can write an example latter…..

    in reply to: Lvalue and Rvalue #3650
    GWILouisaxwzkla
    Participant

    For an R-value violation you could do this:


    void func ( int i );

    int main()
    {
    int i = func ( 3 );

    }

    pretty sure that would constitute a R-value violation…….

    in reply to: Lvalue and Rvalue #3648
    GWILouisaxwzkla
    Participant

    An L-value violation is easy , just put a constant on the left hand side of an equation:


    const int myInt = 9;

    ..
    myInt = 3; // need an L-value here

    You need something that is assignable for a L-value. R-value violations are tougher , I’ll have to look into this…….

    in reply to: C++ Data files #3641
    GWILouisaxwzkla
    Participant

    Could you post your data file?

    in reply to: plzzz help…….it doesn’t evaluate right……! #3642
    GWILouisaxwzkla
    Participant

    Heres a postfix to infix program I have on my drive ( hope this helps….. ):

    #include < conio.h >
    #include < math.h >
    #include < string.h >
    #include < stdlib.h >
    #include < stdio.h >

    enum Boolean { False = 0 , True = 1 } ;
    const int GREATER = 1 ;
    const int NOTGREATER = 0 ;
    int cnt = 0 , cntcol = 0 , postcnt = 0 ;

    //
    struct Stack
    {
    int info ;
    Stack * previous;
    } * top;

    //
    void Push ( int number )
    {
    Stack * current;
    current = new ( Stack ) ;
    if ( current == 0 )
    {
    printf ( "n allocation error!!!!! " );
    return;
    }
    current -> info = number ;
    current -> previous = top ;
    top = current ;
    }

    //
    int Pop ()
    {
    int temp ;
    Stack * current = top;
    temp = current -> info ;
    top = top -> previous ;
    delete current ;
    return temp ;
    }

    //
    int StackTop ()
    {
    return top -> info ;
    }

    //
    Boolean isEmpty()
    {
    if ( top == NULL )
    return True;
    else
    return False ;
    }

    //
    Boolean isOperand ( char ch )
    {
    if ( ch >= '0' && ch <= '9' ) //if is a number
    return True;
    else
    return False ;
    }

    //
    void Infix ( char infix[][10])
    {
    char c ;
    while ( c != 13 )
    {
    c = getch() ;
    putch(c);
    if ( c >= '0' && c <= '9' )
    {
    infix [cnt][cntcol] = c ;
    cntcol++ ;
    }
    else if ( c == '+'|| c == '-'|| c == '*'|| c == '/')
    {
    infix [cnt][cntcol] = '' ;
    cnt++ ;
    infix [cnt][0] = c ;
    infix [cnt][1] = '' ;
    cnt++ ;
    cntcol = 0 ;
    }
    else if ( c == 13 )
    infix[cnt][cntcol] = '' ;
    }
    }


    //
    int Calculate (int op1, char opr, int op2)
    {
    int ans ;
    switch ( opr )
    {
    case '+' : ans = op1 + op2 ; break ;
    case '-' : ans = op1 - op2 ; break ;
    case '*' : ans = op1 * op2 ; break ;
    case '/' : ans = op1 / op2 ; break ;
    case '^' : ans = pow(op1, op2) ;
    }
    return ans ;
    }
    //
    int Evaluate ( char postfix[][10] )
    {
    for ( int i = 0 ; i <= cnt ; i ++ )
    {
    char ch = postfix[0] ;
    char ch1[10] ;
    strcpy ( ch1 ,postfix
    ) ;
    // cout < if ( isOperand ( ch ) == True )
    Push ( atoi(ch1) );
    else
    {
    int op2 = Pop () ;
    int op1 = Pop () ;
    int ans = Calculate ( op1, ch, op2 ) ;
    // cout << ans << endl ;
    Push ( ans ) ;
    }
    }
    int ans = Pop () ;
    return ans ;
    }

    //

    int CheckP (char cur, char st)
    {
    int a = NOTGREATER ;

    if ( cur == '(' )
    a = GREATER ;
    else if ( cur != '(' && st == '(' )
    a = GREATER ;
    else if ( cur != '(' && st != '(' )
    {
    if ( ( cur == '*' || cur == '/' ) && ( st == '+' || st == '-' ) )
    a = GREATER ;
    }
    return a ;

    }


    //
    void infixToPostfix ( char infix[][10], char postfix[][10] )
    {
    int postcol = 0 ;
    for ( int i = 0 ; i <= cnt ; i ++ )
    {
    // strcpy(postfix, infix ) ;
    // cout << postfix
    ;
    char ch;
    ch = infix
    [0] ;
    if ( isOperand ( ch ) == True )
    strcpy ( postfix [postcnt++] , infix
    ) ;
    else
    {
    if ( isEmpty() == True )
    Push ( int(ch) ) ;
    else
    {
    while ( CheckP( ch, StackTop() ) != GREATER && isEmpty() != True )
    {
    char c ;
    if ( ch == ')' )
    {
    do
    {
    c = char ( Pop() ) ;
    if ( c != '(')
    {
    postfix [postcnt][postcol] = c ;
    postfix [postcnt][postcol+1] = '' ;
    postcnt++ ;
    }
    }while ( c != '(' && isEmpty() != True);
    break ;
    }
    else
    c = char ( Pop() ) ;
    if ( c != '(' && c != ')' )
    {
    postfix [postcnt][postcol] = c ;
    postfix [postcnt][postcol+1] = '' ;
    postcnt++ ;
    }
    }
    if ( ch != ')' )
    Push ( int(ch) ) ;
    }
    }
    }

    while ( isEmpty () != True )
    {
    char c = char ( Pop () ) ;
    postfix [postcnt][postcol] = c ;
    postfix [postcnt][postcol+1] = '';
    postcnt++ ;
    }
    // postfix[postcnt][postcol] = '';
    }

    //

    void Postfix ( char postfix[][10] )
    {
    char ch[10] ;
    for ( int i = 0; i <= postcnt; i++ )
    {
    strcpy(ch , postfix ) ;
    printf ( "%c" ,ch );
    }
    }

    //

    void main()
    {
    //clrscr();
    top = NULL ;

    char infix [ 50 ][ 10 ] ;
    char postfix [ 50 ][ 10 ] ;

    //gotoxy ( 5, 8 ) ;
    printf ( "Enter Arithematic Expression ...................... : " );
    Infix ( infix ) ;

    infixToPostfix ( infix, postfix ) ;
    //gotoxy ( 5, 10 ) ;
    printf ( "Arithematic Expression in Postfix Notation......... : " );
    Postfix ( postfix ) ;
    int ans = Evaluate ( postfix ) ;
    //gotoxy (5, 11 ) ;
    printf ( "The Answer of Expression .......................... : " );
    printf ( "%i", ans );

    getch();
    }
    //
    in reply to: plzz help me out ……….. #3636
    GWILouisaxwzkla
    Participant

    Could do this:


    /****************************************************************
    * File Name : c:programstempCG.cpp
    * Date : February 21 , 2010
    * Comments : new project
    * Compiler/Assembler : Visual C++ 6.0
    * Modifications :
    *
    *
    *
    *
    *
    * Program Shell Generated At: 1:00:53 a.m.
    =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/


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

    using namespace std;

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

    int main ( )
    {

    char ch;
    int i;
    char newline = 10;
    float decimalEquivalent = 0;
    float multiplier = .5;

    cout << "enter a binary fraction: " ;

    ch = cin.get(); //get decimal point
    ch = cin.get() ; //get first digit of number

    while ( ch != newline ) //while not at the end of input
    {
    decimalEquivalent = decimalEquivalent + ( ch - '0' ) * multiplier;
    multiplier = multiplier * .5;
    ch = cin.get() ; // get next digit
    }

    cout << endl << endl;
    cout << "decimal equivalent is : " << decimalEquivalent << endl;
    }




    in reply to: Array Problem #3639
    GWILouisaxwzkla
    Participant

    Unless theres a new C++ standard , you cannot declare arrays of an arbitrary length ( the length must be declared as a constant so the compiler knows how to set up the function’s stack frame at compile time ). So you can’t do this ( I’m suprised this compiled, what compiler are you using ?):


    int array [ g + 1 ];

    If you want a arbitrary length array you have to allocate it at run time , like:


    int * array = new int [ g + 1 ];

    make sure to check allocation of this statement and delete the memory when your done with it ( by the end of the function call )………

    in reply to: clrscr(), window(), textcolor() etc. not in conio.h? #3635
    GWILouisaxwzkla
    Participant

    Theres a seperate debugging utility called “turbo debugger” or something. Its a small DOS box utility that debugs object files made with Turbo C++ , as I remember. Heres a link to some info on this http://www.winprog.org/tutorial/bcpp.html

    in reply to: clrscr(), window(), textcolor() etc. not in conio.h? #3633
    GWILouisaxwzkla
    Participant

    I haven’t used this compiler for a looong time , but as I remember you have to do a few small things to configure it or it will not work properly. Heres a link that shows how to configure it http://edn.embarcadero.com/article/21205 , you can also google set up Borland command line tools .

    in reply to: clrscr(), window(), textcolor() etc. not in conio.h? #3631
    GWILouisaxwzkla
    Participant

    The functions clrscr(), ect. are exclusive to the Borland Turbo Compiler. I think the easiest way to compile the code would be to download the free Borland Command Line Tools Package ( I think you can find it here: http://edn.embarcadero.com/article/20633 ) or just google free Borland Command Line Tools Package download. You could also write your own replacement functions and add them to the one of the VC++ library ( could code these using Windows API calls for 32-bit Windows applications ).

    in reply to: Assistance with Question #3629
    GWILouisaxwzkla
    Participant

    Could you perhaps post the input file for your program?

    in reply to: Assistance with Question #3627
    GWILouisaxwzkla
    Participant

    What does your input file look like? What criteria is used to select samples ( randomly ).

    in reply to: Structures and Algorithms in C++ #3624
    GWILouisaxwzkla
    Participant

    Not sure what your doing. Does this relate to linked lists?

    in reply to: Structures and Algorithms in C++ #3622
    GWILouisaxwzkla
    Participant

    Heres a simple version ( the items are entered into the list from the back )


    /****************************************************************
    * File Name : c:programstempCG.cpp
    * Date : January,8,2010
    * Comments : new project
    * Compiler/Assembler : Visual C++ 6.0
    * Modifications :
    *
    *
    *
    *
    *
    * Program Shell Generated At: 4:13:24 p.m.
    =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/


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

    using namespace std;

    //node for the list
    struct node
    {
    int data;
    node * next;
    };



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

    int main ( )
    {

    cout << "enter numbers ( 0 to stop ) " << endl << endl;

    node * front = NULL; //front of the linked list
    node * temp = NULL;
    node * back = NULL;

    int input;

    cout << "enter number: ";
    cin >> input;

    //######### READ THE LIST FROM THE KEYBOARD

    while ( input != 0 )
    {
    temp = new node; //make a new node in the list
    if ( temp == NULL ) //check that node was allocated properly
    {
    cout << "allocation error , node not stored! " << endl;
    continue;
    }
    temp -> data = input;//copy data
    temp -> next = NULL; //new item has no next item
    if ( front == NULL ) //if the list is empty add a new node
    {
    front = temp; //front of list points to temp
    back = temp; //back of list pointer points to temp
    }
    else //add the item to the back of the list
    {
    back -> next = temp;//next item in the list is the item read
    back = temp; //new item is the new last item
    }
    cout << "enter number: "; //get the next number
    cin >> input;
    }


    cout << "Printed list: " << endl << endl;

    temp = front; //start at the front of the list

    //############ PRINT THE LIST

    while ( temp ) //while not at the end of the list
    {
    cout << temp -> data << " " ; //output data in list item
    temp = temp -> next; //go to next item in the list
    }

    //######## DELETE THE LIST

    while ( front )
    {
    temp = front; //save the address of the front node
    front = front -> next; //make the next item first
    delete temp; //deallocate memory for the old front node
    }


    return 0 ;
    }




    in reply to: Structures and Algorithms in C++ #3620
    GWILouisaxwzkla
    Participant

    could try:


    /****************************************************************
    * File Name : cgt.cpp
    * Date : April,10,2007
    * Comments : new project
    * Compiler/Assembler : VC++ 6.0
    *
    *
    *
    *
    *
    * Program Shell Generated At: 2:59:58
    =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/


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

    using namespace std;

    struct node
    {

    int data;
    node * next;
    node * back;

    };


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

    void readList ( node ** list );
    bool listsAreEqual ( node * left , node * right );
    node * copyList ( node * list );
    void printList ( node * list );
    void destroyList ( node ** list );
    bool listsContainEqualMembers ( node * left , node * right );

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

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

    int main ( )
    {

    node * head1 = 0;
    node * head2 = 0;

    cout << "enter first list :" << endl;
    readList ( & head1 );
    cout << "enter second list: " << endl;
    readList ( & head2 );

    if ( listsAreEqual ( head1 , head2 ) )
    cout << endl << "The lists are equal" << endl;
    else
    cout << endl << "The lists are not equal" << endl;

    cout << endl;
    if ( listsContainEqualMembers ( head1 , head2 ) )
    cout << endl << "lists contain equal members" << endl;
    else
    cout << endl << "lists do not contain equal members " << endl;


    node * copy = copyList ( head1 );
    cout << endl << "copy of first list is: ";
    printList ( copy );
    destroyList ( & head1 );
    destroyList ( & head2 );
    destroyList ( & copy );
    return 0 ;
    }


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

    Name : readList
    Parameters :



    Returns: Void type
    Comments:



    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    void readList ( node ** list )
    {

    cout << "enter an integer ( -1 to stop ) ";
    int i;
    cin >> i;
    node * temp = 0;

    while ( i != -1 )
    {

    temp = new node;
    if ( temp == 0 )
    {
    cout << " allocation error" ;
    ( * list ) = 0;
    return;
    }
    temp -> data = i ;
    if ( ( * list ) == 0 )
    {
    ( * list ) = temp;
    temp -> next = 0;
    temp -> back = temp;

    }
    else
    {
    ( * list ) -> back -> next = temp;
    temp -> next = temp -> back = 0;
    ( * list ) -> back = temp;
    }
    cout << "enter a number ( -1 to stop ) ";
    cin >> i;
    }

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

    Name : listsAreEqual
    Parameters :



    Returns: user defined type , bool

    Comments:



    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    bool listsAreEqual ( node * left , node * right )
    {

    bool matches = true;

    while ( left != 0 && right != 0 && matches )
    {

    if ( left -> data != right -> data )
    matches = false;
    else
    {
    left = left -> next;
    right = right -> next;
    }
    }
    if ( ! left && ! right && matches )
    return true;

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

    Name : copyList
    Parameters :



    Returns: user defined type , node *

    Comments:



    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    node * copyList ( node * list )
    {

    node * temp = 0;
    node * newList = 0;

    while ( list )
    {

    temp = new node;
    if ( ! temp )
    {
    cout << "allocation error! ";
    return 0;
    }
    if ( newList == 0 )
    {
    newList = temp;
    temp -> data = list -> data;
    newList -> next = 0;
    newList -> back = temp;
    }
    else
    {
    temp -> data = list -> data;
    newList -> back -> next = temp;
    newList -> back = temp;
    temp -> next = temp -> next = 0;
    }
    list = list -> next;
    }
    return newList;
    }
    void printList ( node * temp )
    {


    cout << "list read is " ;
    while ( temp )
    {
    cout << temp -> data << " ";
    temp = temp -> next;
    }
    cout << endl;
    }
    /******************************* FUNCTION DEFINITION ******************************

    Name : destroyList
    Parameters :



    Returns: user defined type , void

    Comments:



    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    void destroyList ( node ** list )
    {


    node * temp = ( * list );
    node * temp2 = 0;
    while ( temp )
    {

    temp2 = temp;
    temp = temp -> next;
    delete temp2;
    }

    ( * list ) = 0;
    }
    /******************************* FUNCTION DEFINITION ******************************

    Name : listsContainEqualMembers
    Parameters :



    Returns: Void type
    Comments:



    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    bool listsContainEqualMembers ( node * left , node * right )
    {


    node * temp1 = left;
    node * temp2 = right;
    bool matches ;
    int length1 = 0 , length2 = 0;
    int numItems1 = 0 , numItems2 = 0;

    while ( temp1 && matches )
    {
    temp2 = right;
    matches = false;
    length1 ++; //get length of first list
    while ( temp2 && ! matches )
    {
    if ( temp1 -> data == temp2 -> data )
    matches = true;
    if ( ! matches )
    temp2 = temp2 -> next;
    }
    if ( matches )
    temp1 = temp1 -> next;
    }
    temp2 = right;
    while ( temp2 )
    {
    length2 ++ ;
    temp2 = temp2 -> next;
    }
    if ( length1 == length2 && matches )
    return true;
    return false;
    }

Viewing 15 posts - 1 through 15 (of 93 total)