Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1.  
  2. // Chris Myhalsky
  3. // prog1.cpp
  4. // 2-16-2011
  5. // Program Description: This program aims to create a
  6.  
  7. #include <iostream>
  8. #include <iomanip>
  9. using namespace std;
  10.  
  11. int row, col, count, sp, end, step;
  12. void getGridSize (int &row, int &col);
  13. void printInitialBoard (int row, int col);
  14. void printFinalBoard (int row, int col, int sp, int end, int step);
  15.  
  16.  
  17. // This function is to allow the user to input the rows and columns.
  18. void getGridSize (int &row, int &col)
  19. {
  20. cout <<"Enter the board size. (rows X columns): ";
  21. cin >> row;
  22. cin >> col;
  23. cout << endl;
  24. }
  25.  
  26.  
  27. // This function displays the board with all squares numbered.
  28. void printInitialBoard (int row, int col)
  29. {
  30. int i,j,count;
  31. count = 0;
  32. getGridSize (row, col);
  33. for (int i=0; i< row; i++)
  34. {
  35. for (int j=0; j<col; j++)
  36. {
  37. cout << setw(2) << setfill('0') << count << " ";
  38. count++;
  39. }
  40. cout << endl;
  41. }
  42. }
  43.  
  44.  
  45. // This function gets the user to input the start position for the
  46. // board.
  47. int getStartPosition ()
  48. {
  49. cout <<"Enter the start position: ";
  50. cin >> sp;
  51. while(sp < 0)
  52. {
  53. cout <<"The start position must be non-negative, enter again: ";
  54. cin >> sp;
  55. }
  56. }
  57.  
  58.  
  59. // This funtion prompts the user to input the end position to be used.
  60. int getEndPosition ()
  61. {
  62. cout <<"Enter the end position: ";
  63. cin >> end;
  64. }
  65.  
  66.  
  67. // This function prompts the user for the step.
  68. int getStep ()
  69. {
  70. cout <<"Enter the step: ";
  71. cin >> step;
  72. while (step < 0)
  73. {
  74. cout <<"The step must be non-negative, enter again: ";
  75. cin >> step;
  76. }
  77. }
  78.  
  79.  
  80. // This function prints the final board.
  81. void printFinalBoard (int row, int col, int sp, int end, int step)
  82. {
  83. int count;
  84. for (int i=0; i< row; i++)
  85. {
  86. for (int j=0; j<col; j++)
  87. {
  88. if ((count == sp) || (((count % step) - (sp % step)) == 0))
  89. cout << setw(2) << setfill('0') << count << " ";
  90. else
  91. cout << "** ";
  92. count++;
  93. }
  94. cout << endl;
  95. }
  96. }
  97.  
  98.  
  99. //
  100. int main ()
  101. {
  102. printInitialBoard (row, col);
  103. getStartPosition();
  104. getEndPosition();
  105. getStep ();
  106. printFinalBoard (row, col, sp, end, step);
  107.  
  108. system ("pause");
  109. return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement