Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Chris Myhalsky
- // prog1.cpp
- // 2-16-2011
- // Program Description: This program aims to create a
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int row, col, count, sp, end, step;
- void getGridSize (int &row, int &col);
- void printInitialBoard (int row, int col);
- void printFinalBoard (int row, int col, int sp, int end, int step);
- // This function is to allow the user to input the rows and columns.
- void getGridSize (int &row, int &col)
- {
- cout <<"Enter the board size. (rows X columns): ";
- cin >> row;
- cin >> col;
- cout << endl;
- }
- // This function displays the board with all squares numbered.
- void printInitialBoard (int row, int col)
- {
- int i,j,count;
- count = 0;
- getGridSize (row, col);
- for (int i=0; i< row; i++)
- {
- for (int j=0; j<col; j++)
- {
- cout << setw(2) << setfill('0') << count << " ";
- count++;
- }
- cout << endl;
- }
- }
- // This function gets the user to input the start position for the
- // board.
- int getStartPosition ()
- {
- cout <<"Enter the start position: ";
- cin >> sp;
- while(sp < 0)
- {
- cout <<"The start position must be non-negative, enter again: ";
- cin >> sp;
- }
- }
- // This funtion prompts the user to input the end position to be used.
- int getEndPosition ()
- {
- cout <<"Enter the end position: ";
- cin >> end;
- }
- // This function prompts the user for the step.
- int getStep ()
- {
- cout <<"Enter the step: ";
- cin >> step;
- while (step < 0)
- {
- cout <<"The step must be non-negative, enter again: ";
- cin >> step;
- }
- }
- // This function prints the final board.
- void printFinalBoard (int row, int col, int sp, int end, int step)
- {
- int count;
- for (int i=0; i< row; i++)
- {
- for (int j=0; j<col; j++)
- {
- if ((count == sp) || (((count % step) - (sp % step)) == 0))
- cout << setw(2) << setfill('0') << count << " ";
- else
- cout << "** ";
- count++;
- }
- cout << endl;
- }
- }
- //
- int main ()
- {
- printInitialBoard (row, col);
- getStartPosition();
- getEndPosition();
- getStep ();
- printFinalBoard (row, col, sp, end, step);
- system ("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement