//
//
//  grid.cc
//
//      AUTHOR: Russell Lowke
//         T.F: Francis Crick
//  CSCIE-s111: Unit Four, Hard Supp - question 7 [worth 3pts],  7/12/2002
//
//  Using the graphics library unxgraph.cc, draw a 5x5 grid on the screen
//  and fill the cells with randomly-generated upper-case letters.
//

#include <iostream>
#include <iomanip>
#include <cstdlib>              // To use rand()
#include <ctime>				// To use time()
#include "unxgraph.cc" 			// To enable special graphic effects 

screen scr;

//
// random seed according to time
//
void randomizer()
{
	time_t      timeval;
	
	time(&timeval);
	srand(timeval);
}


//
// Random generator
//
int randomInt(int min, int max)
{
	static bool seed = false;
	int range = (max+1) - min;
	    
	if (! seed) {
		randomizer();
		seed = true;
	}
	
    return (int) (( rand() / (double) RAND_MAX ) * range + min);
}


//
//  draw a 5x5 grid on the screen
//  and fill the cells with randomly-generated upper-case letters
// 
void drawSquare()
{

    scr.HomeAndClear();     				// erase the video display screen
 
	int top      = 5;						// init vars
	int left     = 5;
	int gridSize = 5;
	
	for (int i = 0; i < gridSize; i++) {
		scr.Position (top + i, left);
		for (int j = 1; j <= gridSize; j++) {        // print top horizontal part
        	cout << (char) randomInt('A', 'Z');
   		}
	}
	
	// move down screen
	scr.Position (gridSize*3, left);
	cout << endl;

}


void main()
{
    drawSquare();
    scr.CursorOff();
}