154 lines
4.3 KiB
C
154 lines
4.3 KiB
C
// header files
|
|
#include "Console_IO_Utility.h"
|
|
#include "File_Output_Utility.h"
|
|
#include "File_Input_Utility.h"
|
|
|
|
// global constants
|
|
const int TOTAL_ROWS = 2;
|
|
const int TOTAL_COLUMNS = 3;
|
|
const int TOTAL_CHARS = 6;
|
|
const int INPUT_ARRAY_SIZE = 2;
|
|
const char PRESENCE_CHAR = 'X';
|
|
const char ABSENCE_CHAR = 'O';
|
|
const char PIPE_CHAR = '|';
|
|
enum tablePositions{ROW, COLUMN} ;
|
|
enum tableIsFull{FULL, NOTFULL} ;
|
|
|
|
// functions prototype
|
|
/*
|
|
Name: printProgramTitle
|
|
Process: displays program title
|
|
Function Input/Parameters: none
|
|
Function Output/Parameters: none
|
|
Function Output/Returned: none
|
|
Device Input/Keyboard: none
|
|
Device Output/Monitor: title displayed as specified
|
|
Dependencies: printf
|
|
*/
|
|
void printProgramTitle();
|
|
/*
|
|
Name: displayResults
|
|
Process: displays resulted table as specified in example
|
|
Function Input/Parameters: 2D array of characters
|
|
Function Output/Parameters: none
|
|
Function Output/Returned: none
|
|
Device Input/Keyboard: none
|
|
Device Output/Monitor: 2D array of characters as specified
|
|
Dependencies: printf
|
|
*/
|
|
void displayResults( char characterMatrix[ TOTAL_ROWS ][ TOTAL_COLUMNS ] );
|
|
|
|
// NOTE: THERE IS NO PROCESSING PART IN THIS TASK
|
|
int main()
|
|
{
|
|
|
|
// initialize program
|
|
// define variables
|
|
char characterMatrixValue[TOTAL_ROWS][TOTAL_COLUMNS];
|
|
int rows, columns, userRow, userColumn, count;
|
|
int tableFull = NOTFULL;
|
|
char userCharacter;
|
|
count = 0;
|
|
|
|
// initialize matrix of presense filled with absence characters
|
|
for(rows = 0; rows < TOTAL_ROWS; rows++)
|
|
{
|
|
// row for loop for incrementing through the rows
|
|
for(columns = 0; columns < TOTAL_COLUMNS; columns++)
|
|
{
|
|
// column for loop for incrementing through the columns
|
|
characterMatrixValue[rows][columns] = ABSENCE_CHAR;
|
|
}
|
|
}
|
|
|
|
printProgramTitle();
|
|
|
|
// get input
|
|
// need to use a while loop to check to see if the table is full.
|
|
while (tableFull != FULL)
|
|
{
|
|
userCharacter = promptForCharacter("\nEnter your character: ");
|
|
count += 1;
|
|
userRow = promptForInteger("\nPick Row to enter value: ");
|
|
while (userRow < TOTAL_ROWS - TOTAL_ROWS || userRow >= TOTAL_ROWS)
|
|
{
|
|
printf("The Value must be between %d and %d\n",
|
|
TOTAL_ROWS - TOTAL_ROWS, TOTAL_ROWS - 1);
|
|
userRow = promptForInteger("\nPick Row to enter value: ");
|
|
}
|
|
userColumn = promptForInteger("Pick Column to enter value: ");
|
|
while (userColumn < TOTAL_COLUMNS - TOTAL_COLUMNS
|
|
|| userColumn >= TOTAL_COLUMNS)
|
|
{
|
|
printf("The Value must be between %d and %d\n",
|
|
TOTAL_COLUMNS - TOTAL_COLUMNS, TOTAL_COLUMNS - 1);
|
|
userColumn = promptForInteger("Pick Column to enter value: ");
|
|
}
|
|
characterMatrixValue[userRow][userColumn] = userCharacter;
|
|
// check to see if any values are still equal to ABSENCE_CHAR.
|
|
if (count >= TOTAL_CHARS)
|
|
{
|
|
for(rows = 0; rows < TOTAL_ROWS; rows++)
|
|
{
|
|
// row iterator
|
|
for(columns = 0; columns < TOTAL_COLUMNS; columns++)
|
|
{
|
|
// column iterator
|
|
if(characterMatrixValue[rows][columns] != ABSENCE_CHAR)
|
|
{
|
|
tableFull = FULL;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// display results
|
|
displayResults(characterMatrixValue);
|
|
|
|
// end prgoram
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
// supportive functions
|
|
|
|
void printProgramTitle()
|
|
{
|
|
// initialize variables
|
|
// none
|
|
|
|
// get user input
|
|
// none
|
|
|
|
// display results
|
|
printf("\nFILLING IN ARRAY\n");
|
|
printf("==================\n");
|
|
|
|
// end function
|
|
}
|
|
|
|
void displayResults(char characterMatrix[TOTAL_ROWS][TOTAL_COLUMNS])
|
|
{
|
|
// initialize variables
|
|
int row_val, column_val;
|
|
|
|
// get user input
|
|
// input is passed in through parameters.
|
|
|
|
// display results
|
|
for(row_val = 0; row_val < TOTAL_ROWS; row_val++)
|
|
{
|
|
// row iterator
|
|
printf("|");
|
|
for(column_val = 0; column_val < TOTAL_COLUMNS; column_val++)
|
|
{
|
|
// column iterator
|
|
printf("%c|", characterMatrix[row_val][column_val]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
// end function
|
|
}
|