// **********************************************
// Kathleen Williams
// September 19th, 2001
// Checkerboard assignment 
// Work with exercise 2.8.  Modify the solution 
// to include a border around the entire 
// checkerboard, no matter what size it is.  
// Use an underscore character for the top 
// and bottom border, and a '|" character 
// (vertical bar) for the two sides.
// p02_08.cpp A generalized chessboard
// Reads the small positive integers n and k,
// and uses these to display a board of nXn 
// squares, similar to a chessboard. The white 
// squares are blank and the black ones consist
// of kXk asterisks (*). There must be a black
// square in the lower left corner.
// *********************************************
#include <iostream>
using namespace std;

int main() {
 int n, k;
 const char white = ' ', black = '*', bar1 = '_', bar2 = '|';
 cout << "Chessboard of n X n squares; each black square\n"
      << "consists of k X k asterisks.\n"
      << "Enter n and k: ";
 cin >> n >> k;
 int nk = n*k + 2;
 for (int I=0; I < nk; ++I) {      // Line number I (0, ....., nk-1) 
  int i = (I-1)/k;                 // Row number i (0, ...., n-1)
  for (int J=0; J < nk; ++J) {     // Positon J (0, ......, nk-1)
   int j = (J-1)/k;                // Column number (0, ...., n-1)
   // If n is even, the upper-left square (i = j = 0) is
   // white, while it is black if n is odd
   if (((J == 0) || (J == (nk-1))) || (I == 0) || (I == (nk-1))) {
    if ((I == 0) || (I == (nk-1))) 
     cout << bar1;
    else  
     cout << bar2;
   }
   else {
    if ((i + j) % 2 == n % 2) cout << white;
    else cout << black;
   }
  }
  cout << endl;
 }
return 0;
}

