SOURCE FILE: checksLev2.cpp



#include <iostream>
using namespace std ;

  /* function prototype */
int GetDim (void) ;
   /* return a positive value from the user */

  /* function prototype */
void MakePattern(int the_width, int the_height) ;
   /* write a checker pattern to the screen,
      the_width checks wide and the_height checks high. */

int main (void)
{
   int width, height ;

   width = GetDim() ; // We don't need to write virtually the same
   height = GetDim() ; // code twice - instead we call the function twice.

   MakePattern(width, height) ;

   return 0;
}

  /* function definition */
int GetDim() 
{
   int dimension ;
   cout << "Enter a positive integer: " ;
   cin >> dimension ;
   return dimension ;
}

  /* function prototype */
void MakeOddCourse (int a_width) ;
  /* This function makes one 'course' of a 'check' pattern.  The argument
      a_width denotes how many checks there are, running from left to right.

      This function makes the leftmost 'check' using asterisks - eight
      asterisks wide and four lines high.  The idea is that this is a 'black'
      check.

      The checks in a course alternate from left to right.  Numbering the
      checks starting from 1, the odd-numbered checks are 'black' and the
      even-numbered checks are 'white'.  The 'white' checks are just made out
      of blank characters.
  */

  /* function prototype */
void MakeEvenCourse (int a_width) ;
  /* This function is just like MakeOddCourse, except that it makes the
     leftmost check a 'white' check.
  */

  /* function definition */
void MakePattern(int the_width, int the_height) 
{
   cout << endl ;
   for (int i=1; i<=the_height; i++)
   {
     if (i%2 == 1) MakeOddCourse(the_width) ;
     else MakeEvenCourse (the_width) ;
   }
   cout << endl ;
}

  /* function definition */
void MakeOddCourse (int a_width)
{
     /* STUB CODE */
   cout << "BLACK starts this course of " << a_width << " checks.\n" ;
}

  /* function definition */
void MakeEvenCourse (int a_width) 
{
     /* STUB CODE */
   cout << "WHITE starts this course of " << a_width << " checks.\n" ;
}