// carrot_harvest.c // // Written by YOUR-NAME (YOUR-ZID) // on TODAYS-DATE // // Harvests every row of a vegetable patch that is entirely carrots. #include // Constants #define MAX_SIZE 20 enum vegetable { CARROT, TURNIP, POTATO, EMPTY }; // Function prototypes void carrot_harvest(enum vegetable patch[MAX_SIZE][MAX_SIZE], int rows, int cols); void read_patch(enum vegetable patch[MAX_SIZE][MAX_SIZE], int rows, int cols); void print_patch(enum vegetable patch[MAX_SIZE][MAX_SIZE], int rows, int cols); // ----------------------------------------------------------------------------- //////////////// DO NOT CHANGE THE MAIN FUNCTION /////////////////////////////// int main(void) { enum vegetable patch[MAX_SIZE][MAX_SIZE]; int rows; int cols; printf("Enter the size of the patch: "); scanf("%d %d", &rows, &cols); printf("Enter the contents of the patch:\n"); read_patch(patch, rows, cols); carrot_harvest(patch, rows, cols); printf("\nThe patch after harvesting:\n"); print_patch(patch, rows, cols); return 0; } // ----------------------------------------------------------------------------- // YOUR FUNCTIONS // ----------------------------------------------------------------------------- // Harvest every row of the patch that consists entirely of carrots, by // setting each cell in that row to EMPTY. All other rows are unchanged. void carrot_harvest(enum vegetable patch[MAX_SIZE][MAX_SIZE], int rows, int cols) { // TODO: Complete this function } // ----------------------------------------------------------------------------- // PROVIDED FUNCTIONS // ----------------------------------------------------------------------------- // DO NOT CHANGE ANY OF THE CODE BELOW HERE // Read the contents of the patch from stdin void read_patch(enum vegetable patch[MAX_SIZE][MAX_SIZE], int rows, int cols) { for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { char plot; scanf(" %c", &plot); if (plot == 'c') { patch[i][j] = CARROT; } else if (plot == 't') { patch[i][j] = TURNIP; } else if (plot == 'p') { patch[i][j] = POTATO; } else { patch[i][j] = EMPTY; } } } } // Print the contents of the patch void print_patch(enum vegetable patch[MAX_SIZE][MAX_SIZE], int rows, int cols) { for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { if (patch[i][j] == CARROT) { printf("c"); } else if (patch[i][j] == TURNIP) { printf("t"); } else if (patch[i][j] == POTATO) { printf("p"); } else { printf("."); } } printf("\n"); } }