SOURCE FILE: checksLev4.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 prototype */
void MakeOddLayer (int w_width) ;
/* This function simply makes a pattern like this:
******** ********
i.e. alternating series of eight asterisks and eight blanks.
It writes the pattern to standard output.
(By default, standard output is the computer screen).
The argument w_width determines the number of series of eight.
For example, the pattern above is what you get from this call:
MakeOddLayer(3) ;
*/
/* function prototype */
void MakeEvenLayer (int w_width) ;
/*
This function is just like MakeOddLayer above, except that this function
starts by writing eight blanks, then eight asterisks, and so on.
*/
/* function definition */
void MakeOddCourse (int a_width)
{
for (int i=0; i<4; i++)
{
MakeOddLayer(a_width) ;
}
}
/* function definition */
void MakeEvenCourse (int a_width)
{
for (int i=0; i<4; i++)
{
MakeEvenLayer (a_width) ;
}
}
/* function definition */
void MakeOddLayer (int a_width)
{
for (int j=1; j <= a_width; j++)
{
if (j%2==1)
cout << "********" ;
else cout << " " ;
}
cout << endl ;
}
/* function definition */
void MakeEvenLayer (int a_width)
{
for (int j=1; j <= a_width; j++)
{
if (j%2==1)
cout << " " ;
else cout << "********" ;
}
cout << endl ;
}