473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

what is pseudo-code

2
Hi guys
Could any one tell me what does that code do please? in pseudo-code
Expand|Select|Wrap|Line Numbers
  1. #include <fstream.h>
  2. #include <iostream.h>
  3.  
  4.  
  5. bool differsByOneDigit ( int , int );
  6. void outputResults ( ofstream & , int * , int , bool );
  7.  
  8.  
  9. void main()
  10. {
  11.  
  12. //CHANGE THESE PATHS TO YOUR OWN !!!!!!!!!!!! ***********************
  13. ifstream input ( "c:\\programs\\data.txt" );
  14. ofstream output ( "c:\\programs\\out.txt" );
  15. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  16.  
  17.  
  18. if ( input.fail() || output.fail() )
  19. {
  20. cout <<"input or output file did not open!!! " << endl;
  21. return;
  22. }
  23.  
  24. int first , next ; //32bit int == 2147483647
  25. int sequence [ 11 ];//sequence read
  26. int seqLength = 0; //sequence length
  27. int j;
  28. int temp;
  29. bool match; //matching sequence
  30.  
  31. input >> temp;
  32. while ( ! input.eof() )
  33. {
  34.  
  35. //read next sequence
  36. while ( temp != -1 )
  37. {
  38. sequence [ seqLength ++ ] = temp;
  39. input >> temp;
  40. }
  41. sequence [ seqLength ] = -1;
  42. j = 0;
  43. first = sequence [ j ];
  44. next = sequence [ j + 1 ];
  45. j += 2;
  46. match = true;
  47. while ( match && next != -1)
  48. {
  49.  
  50. match = differsByOneDigit( first , next );
  51. first = next;
  52. next = sequence [ j ];
  53. j++;
  54.  
  55. }
  56. outputResults ( output , sequence , seqLength , match );
  57. input >> temp;
  58. seqLength = 0;
  59. }
  60. output.close();
  61. input.close();
  62.  
  63.  
  64.  
  65. }
  66. bool differsByOneDigit ( int first , int next )
  67. {
  68.  
  69. int differentDigits = 0;
  70.  
  71. while ( first != 0 && next != 0 && differentDigits <= 1 )
  72. {
  73. if ( first % 10 != next % 10 ) //count different digits
  74. differentDigits ++;
  75. first /= 10;
  76. next /= 10;
  77.  
  78. }
  79. if ( differentDigits > 1 || first || next )
  80. return false;
  81. else
  82. return true;
  83.  
  84. }
  85. void outputResults ( ofstream & output , int * sequence , int length , bool isChainedSequence )
  86. {
  87.  
  88. int j = 0;
  89.  
  90. output << "The sequence : ";
  91.  
  92. while ( j < length )
  93. {
  94. output << sequence [ j ++ ] << " " ;
  95. if ( j % 7 == 0 )
  96. output << endl;
  97. }
  98. if ( isChainedSequence )
  99. output << endl << "Is a chained sequence " << endl;
  100.  
  101. else
  102. output << endl << "is a not a chained sequence " << endl;;
  103.  
  104. output << endl <<"****************************************************" << endl;
  105.  
  106. }
Dec 9 '06 #1
1 2858
DeMan
1,806 1GB
Expand|Select|Wrap|Line Numbers
  1. If we have problem with either input or output file
  2. {
  3.   display adequate message
  4. }
  5. Initialise our variables;
  6. get some input
  7. while(input hasn't reached end of file)
  8. {
  9.   while(temporary variable has good value)
  10.   {
  11.     add temp to sequence array, and move pointer;
  12.     get another input (stored in temp); 
  13.   }
  14.   put -1 in the last element of the array;
  15.   set counter to 0;
  16.   set pointer to first element (and second element)
  17.   increment counter beyond second element;
  18.   set match flag to true;
  19.   while we have a match, and haven't reached the end of the array
  20.   {
  21.     check whether the current elements differ by one element
  22.     move onto the next element;
  23.   }
  24.   output results;
  25.   remove residual input from buffer;
  26.   reset counter;
  27. }
  28. close our input and output streams;
  29.  
then the methods mean

Expand|Select|Wrap|Line Numbers
  1. differsbyone:
  2.  
  3. initiate vars
  4. while(firast number is good and there is les than 1 digit different)
  5. {
  6.   if(both numbers don't finish with the same number)
  7.   {  
  8.     increment differentDigits; 
  9.   }
  10.   remove the last digit off both values;
  11. }
  12. if(we had more than 1 digit different or one of our numbers has more digits)
  13. {
  14.   return a fail
  15. }
  16. All is good, so return a pass
  17.  
and finally
Expand|Select|Wrap|Line Numbers
  1. outputResults:
  2.  
  3. display introduction;
  4. while we have more to print
  5. {
  6.   print the current element;
  7.   if we have printed 8 characters ??
  8.   {
  9.     put a newline
  10.   }
  11.   if these numbers are chained
  12.   {
  13.     let the user know they are
  14.   }
  15.   otherwise
  16.   {
  17.     let the user know they're not
  18.   }
  19. }
  20. print a nioce decoration;
  21.  
That expalins the code. In short (similar to other posts) the program basically analyses/decides whether a given sequence is chained or not.
Dec 9 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Zhang Weiwu | last post by:
Hello. I am working with a php software project, in it (www.egroupware.org) Chinese simplified locate is "zh" while Traditional Chinese "tw". I wish to send correct language attribute in http...
4
by: Stephen Poley | last post by:
The issue of the focus pseudo-class came up a few weeks ago, and I finally got around to trying it out (better late than never ...) The recommended order given for the pseudo-classes is link,...
8
by: Kerberos | last post by:
As you might know, IE doesn't support the :hover pseudo-class on every tag (just the "a" tag AFAIK) Is there a simple JavaScript that would solve the problem? I have images that have a light blue...
1
by: Steven T. Hatton | last post by:
ISO/IEC 14882:2003: "5.2.4 Pseudo destructor call The use of a pseudo-destructor-name after a dot . or arrow -> operator represents the destructor for the non-class...
6
by: Fungii | last post by:
Hello, I have a stylesheet that sets p:first-letter to a certain size and colour. I was playing around with Javascript to change paragraph stylesheets using an array like this: var paras =...
70
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like...
13
by: Stephen Walch | last post by:
Error C2392 is hitting me hard! I have a managed C++ library that implements a bunch of fixed interfaces. For example, one interface is: public abstract interface IDbCommand { public...
3
by: yawnmoth | last post by:
I've seen a few webpages that use the javascript pseudo-protocol with event handlers. eg. <input onkeyup="javascript: ..." /> Correct me if I'm wrong, but isn't onkeyup always supposed to be...
0
by: Kevin Frey | last post by:
WebControl contains properties such as ControlStyle and Style for controlling the style of a web-control. In particular the Style property is a CssStyleCollection that simply comprises key-value...
4
by: k3pp0 | last post by:
Hey. I've got a very basic newbie question, I hope you can understand me. Sorry for asking it, first of all. I see a lot of sites (e.g. communities) with a url-structure like this:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.