Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Function Name: geoffCollins Inputs: 1. (char) A 5x10 character array representing a football field and associated players Outputs: (char) An updated 5x10 character array representing

Function Name: geoffCollins Inputs:

1. (char) A 5x10 character array representing a football field and associated players

Outputs:

  1. (char) An updated 5x10 character array representing the field, players, and path of the football after the play is run

  2. (char) A statement describing the outcome of the play

Topics: (control flow), (nested conditionals) , (masking) , ( RHS and LHS indexing)

Background:

4th quarter. 12 seconds left on the clock. It's 4th and goal for the College Football Playoff National Championship against Alabama. Geoff scans his playbook one last time and then looks up, a mischievous twinkle in his eyes. He knows what to do.

JK. It's 4th and 26, halfway down the field, and Tech is facing the Citadel, hoping to pull out a single win for the year. Geoff pulls his 404 The CultureTM cap further over his eyes and crosses his arms over his playbook. No amount of preparation can save the Jackets now. He summons the spirit of Paul Johnson, smacks his quarterback's bum as the offense takes the field, and crosses his fingers.

Function Description:

You are given a football field represented by a 5x10 character array. The quarterback (the starting position of the football) is represented by the character 'Q'. Any receivers that exist will be represented by the character 'R'. Any defenders that exist will be represented by the character 'D'. Any open spaces will be represented by the space character. The 'Q' is guaranteed to be in the first row of the array. The objective is to move the ball to the bottom row of the array.

There are two potential plays you can make, prioritized in this order:

  1. The quarterback can throw the ball to a receiver. The receiver must be located

    EXACTLY 4 indices away from the quarterback, exclusive, either straight down, towards the bottom-left diagonal, or towards the bottom-right diagonal. If a receiver is located in one of these positions, the play is successful. However, if one or more defenders are located directly adjacent to the receiver, not including diagonals (left one index, right one index, or "down" one index (up the array)), the play is blocked. If no receivers are located exactly 4 indices away, this play cannot be used.

  2. The quarterback can run straight down the field. The quarterback moves down the column he was originally located in until reaching the bottom row or encountering a defender. If he reaches the bottom row, the play is successful. If a defender is located in the quarterback's path once he begins running, the play is blocked. If a defender is located in the index position directly below the starting position of the quarterback, this play cannot be used.

If you are able to use the throwing play, you must use it, even if the play will be blocked later on. For example, if you are able to throw the ball, you must do so, even if a defender is located next to the receiver - you may not run the ball, even if this play would be successful.

If both of the plays cannot be used (no receivers are in the correct range and the quarterback cannot run straight down at all), the play fails.

As the play progresses, the path of the football must be marked. Including the starting index of the quarterback, change each index that the ball passes through to an 'X'. If the ball is thrown, these indices may be open spaces, defenders, or other receivers. If the ball is thrown and blocked, still change the path the ball would take to 'X'. If the ball is run and blocked, change all of the empty spaces between the quarterback (inclusive) and the defender (exclusive) to an 'X'. The defender that blocks the play should not be changed to an 'X', but the quarterback should be. If the play fails, still change the quarterback starting position to an 'X'. Output the updated character array. Additionally, output a statement describing the outcome of the play.

  • If the play does not fail, output:

    'The quarterback the ball and the play was .'

  • If the play fails, output:

Examples:

field1= 'Even Paul Johnson can't face impossible odds.'

' Q ' ' D ' '' 'R' ' DR '

[out1, sent1] = geoffCollins(field1)

out1 ' X ' ' DX ' ' X' ' R X ' ' DX '

sent1 'The quarterback threw the ball and the play was blocked.'

field2= ' DQ ' '' '' 'R' 'DD'

[out2, sent2] = geoffCollins(field2)

out2 ' DX ' 'X' 'X' ' XR ' ' DXD '

sent2 'The quarterback ran the ball and the play was successful.'

Notes:

  • If there are multiple receivers on the field, a maximum of one is guaranteed to be

    located at the correct throwing range.

  • You do not have to worry about indexing out of bounds when checking for the locations

    of the potential receivers, or the defenders potentially blocking the receivers.

  • You do not have to worry about changing a defender potentially blocking a receiver to an 'X' before checking if the play was successful or blocked (this would only occur if the ball was thrown straight down and a defender was located exactly above the receiver).

    This situation will not be included.

  • A receiver will never block the path of a running quarterback.

Please solve using MATLAB and do not use iterations in the solution code.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Cornerstones Of Managerial Accounting

Authors: Maryanne M. Mowen, Don R. Hansen, Dan L. Heitger

4th Edition

978-0538473460, 0538473460

More Books

Students also viewed these Accounting questions

Question

Factor completely. p(p + 2) + p(p + 2) - 6(p + 2)

Answered: 1 week ago

Question

What is the purpose of a submittal?

Answered: 1 week ago

Question

How is the NDAA used to shape defense policies indirectly?

Answered: 1 week ago

Question

What is a lobbyist in US? How did this term emerge?

Answered: 1 week ago