Input:
Text File Values: 1 1 A 2 2 B 3 3 C 0 0 X
Output:
3 TILES on Scrabble Board
ROW COL LETTER
=== === ======
1 1 A
2 2 B
3 3 C
=== === ======
4 x 4 SCRABBLE BOARD
1 2 3 4
+ - - - - +
row1=> | A |
row2=> | B |
row3=> | C |
row4=> | |
+ - - - - +
1 2 3 4
(1) Store all board characters into array
char Board[9][9]; // Capacity is 9x9 = 81.
RULE: A board cell can contain at most one value; Display error message when: - the cell already contains a mark - the mark is not a letter - the row is outside the range [1,boardsize] - the col is outside the range [1,boardsize]
ERROR: REJECTED CELL <row> <col> <symbol> CELL MARKED
ERROR: REJECTED CELL <row> <col> <symbol> NOT A LETTER
ERROR: REJECTED CELL <row> <col> <symbol> BAD ROW
ERROR: REJECTED CELL <row> <col> <symbol> BAD COL
(2) After the input file has been read, display the Board array.
(3) Display the words on the scrable board (illustration only):
HORIZONTAL: xxxx yyyyyyy zzzzz 3 WORDS
VERTICAL: aaa bbb ccc ddd 4 WORDS
7 SCRABBLE WORDS
QUESTION: How do I input the file values ex: 1 1 A into char Board[9][9]? I want 1 1 to represent row and col and the symbol A to be associated with 1 1.
Example:
Board[1][1] = A
Board[2][2] = B
New Code:
int main()
{
//-------------------------------------------- --------------------------
// Declare variables
//----------------------------------------------------------------------
char filename[80];
int boardsize, row, col;
char symbol;
char Board[9][9];
ifstream inF;
//-| ----------------------------------------------------------------------
//-| Print the copyright notice declaring authorship.
//-| ----------------------------------------------------------------------
cout << endl << "(c) 2017, twilson" << endl << endl;
//-| ----------------------------------------------------------------------
//-| 1. Get file name and open file.
//-| ----------------------------------------------------------------------
cout << "Enter name of input file: ";
cin >> filename;
cout << endl;
inF.open(filename);
if (inF.fail())
{
cout << "FATAL ERROR: Can not open file " << "'" << filename << "'" << endl;
exit(1);
}
//-| ----------------------------------------------------------------------
//-| 2. Get board size.
//-| ----------------------------------------------------------------------
cout << "Enter board size [1-9]: ";
cin >> boardsize;
cout << endl;
//-| ----------------------------------------------------------------------
//-3. Read in file values and output ROW, COL, and LETTER on scrabble board.
//-| ----------------------------------------------------------------------
int T = 0;
int nextLine = 0;
int Tiles = 0;
// Read in file and count each tile
int a = 0;
while(inF >> row >> col >> symbol)
{
if(row > 0 && col > 0)
{
if( row == row && col == col)
{
cout << "REJECTED CELL " << row << " " << col << " "
<< symbol << " CELL MARKED" << endl;
}
else if(!isalpha(symbol))
{
cout << "REJECTED CELL " << row << " " << col << " "
<< symbol << " NOT A LETTER" << endl;
}
else if(row > boardsize)
{
cout << "REJECTED CELL " << row << " " << col << " "
<< symbol << " BAD ROW" << endl;
}
else if(col > boardsize)
{
cout << "REJECTED CELL " << row << " " << col << " "
<< symbol << " BAD COL" << endl;
}
else
Tiles++;
}
}