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; }



LinkBack URL
About LinkBacks


