Thread: what is pseudo-code

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    4

    what is pseudo-code

    Hi guys
    Could any one tell me what does that code do please? in pseudo-code
    Code:
    #include <fstream.h>
    #include <iostream.h>
    
    
    bool differsByOneDigit ( int , int );
    void outputResults ( ofstream & , int * , int , bool );
    
    
    void main()
    {
    
    //CHANGE THESE PATHS TO YOUR OWN !!!!!!!!!!!! ***********************
    ifstream input ( "c:\\programs\\data.txt" );
    ofstream output ( "c:\\programs\\out.txt" );
    //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
    
    if ( input.fail() || output.fail() )
    {
    cout <<"input or output file did not open!!! " << endl;
    return;
    }
    
    int first , next ; //32bit int == 2147483647
    int sequence [ 11 ];//sequence read
    int seqLength = 0; //sequence length
    int j;
    int temp;
    bool match; //matching sequence
    
    input >> temp;
    while ( ! input.eof() )
    {
    
    //read next sequence
    while ( temp != -1 )
    {
    sequence [ seqLength ++ ] = temp;
    input >> temp;
    }
    sequence [ seqLength ] = -1;
    j = 0;
    first = sequence [ j ];
    next = sequence [ j + 1 ];
    j += 2;
    match = true;
    while ( match && next != -1)
    {
    
    match = differsByOneDigit( first , next );
    first = next;
    next = sequence [ j ];
    j++;
    
    }
    outputResults ( output , sequence , seqLength , match );
    input >> temp;
    seqLength = 0;
    }
    output.close();
    input.close();
    
    
    
    }
    bool differsByOneDigit ( int first , int next )
    {
    
    int differentDigits = 0;
    
    while ( first != 0 && next != 0 && differentDigits <= 1 )
    {
    if ( first % 10 != next % 10 ) //count different digits
    differentDigits ++;
    first /= 10;
    next /= 10;
    
    }
    if ( differentDigits > 1 || first || next )
    return false;
    else
    return true;
    
    }
    void outputResults ( ofstream & output , int * sequence , int length , bool isChainedSequence )
    {
    
    int j = 0;
    
    output << "The sequence : ";
    
    while ( j < length )
    {
    output << sequence [ j ++ ] << " " ;
    if ( j % 7 == 0 )
    output << endl;
    }
    if ( isChainedSequence )
    output << endl << "Is a chained sequence " << endl;
    
    else
    output << endl << "is a not a chained sequence " << endl;;
    
    output << endl <<"****************************************************" << endl;
    
    }

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Nothing correct. You're headers are outdated and non-standards compliant and you use void main(). Other than that, all I can see is that it inputs a file, does some processing (perhaps for sentences?) and then outputs to that file.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Read this http://cboard.cprogramming.com/annou...t.php?f=3&a=39
    And then show us your attempt at pseudo-code
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Explain this C code in english
    By soadlink in forum C Programming
    Replies: 16
    Last Post: 08-31-2006, 12:48 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM