126,036 views
1 vote
1 vote
Assume you have created a mechanical arm that can hold a pen. The arm can perform the following tasks: • Lower the pen to a piece of paper. • Raise the pen from the paper. • Move the pen 1 inch along a straight line. (If the pen is lowered, this action draws a 1-inch line from left to right; if the pen is raised, this action just repositions the pen 1 inch to the right.) • Turn 90 degrees to the right. • Draw a circle that is 1 inch in diameter. Draw a structured flowchart or write structured pseudocode describing the logic that would cause the arm to draw or write the following. Have a fellow student act as the mechanical arm and carry out your instructions. a. a 1-inch square b. a 2-inch by 1-inch rectangle c. a string of three beads d. a short word (for example, "cat"). Do not reveal the word to your partner until the exercise is over.

User Cajwine
by
3.1k points

1 Answer

5 votes
5 votes

Answer:

For easier reading, lets name each action with a single word:

LOWER = Lower the pen to a piece of paper.

RAISE = Raise the pen from the paper.

MOVE = Move the pen 1 inch along a straight line.

TURN = Turn 90 degrees to the right.

CIRCLE = Draw a circle that is 1 inch in diameter.

Now we will write in pseudocode, all the actions needed for each drawing, and then if possible, we will write the same using loops.

In all cases we will assume the arm starts from a RAISED state.

a. a 1-inch square

/start/

LOWER, MOVE, (draws top side from left to right)

TURN, MOVE, (draws right side)

TURN, MOVE, (draws bottom side)

TURN, MOVE, (draws left side)

RAISE

/end/

Using loops:

/start/

LOWER,

Repeat_4_times { MOVE, TURN }

RAISE,

/end/

b. a 2-inch by 1-inch rectangle

/start/

LOWER, MOVE, MOVE, (draws a long top side from left to right)

TURN, MOVE, (draws a short right side)

TURN, MOVE, MOVE, (draws a long bottom side)

TURN, MOVE, (draws a short left side)

RAISE

/end/

Using loops:

/start/

LOWER,

Repeat_2_times { MOVE, MOVE, TURN, MOVE, TURN }

RAISE,

/end/

c. a string of three beads

/start/

LOWER, CIRCLE, RAISE, (draws first bead)

MOVE, LOWER, CIRCLE, RAISE, (draws second bead to the left)

MOVE, LOWER, CIRCLE, RAISE, (draws third bead to the left)

/end/

Using loops:

/start/

Repeat_3_times { LOWER, CIRCLE, RAISE, MOVE }

/end/

d. a short word (for example, "cat")

/start/

//This part will draw a C letter//

LOWER,

TURN, TURN, (rotates, so next line is right to left)

MOVE, TURN, (draws a horizontal line, right to left, on the bottom)

MOVE, MOVE, TURN, (draws two consecutive vertical lines from the bottom upwards)

MOVE, TURN, (draws a horizontal line, left to right, on the top)

RAISE,

//This part will draw an A letter//

MOVE, TURN, MOVE, MOVE (positionates on next letter space, on the lower left)

TURN, TURN, (rotates, so next line is from the bottom upwards)

LOWER, MOVE, MOVE, (draws two consecutive vertical lines from the bottom upwards)

TURN, MOVE, (draws an horizontal line, left to right, on the top)

TURN, MOVE, MOVE (draws two consecutive vertical lines from top to bottom)

RAISE, TURN, MOVE, TURN, MOVE, TURN, (positionates on the middle left side of the letter)

LOWER, MOVE, (draws an horizontal line, left to right, on the middle)

RAISE,

//This part will draw a T letter//

MOVE, TURN, TURN, TURN, MOVE, TURN, (positionates on next letter space, on the upper left)

LOWER, MOVE, MOVE, (draws two consecutive horizontal lines from left to right)

RAISE, TURN, TURN, MOVE, TURN, TURN, TURN, (positionates on the upper middle side of the letter)

LOWER, MOVE, MOVE, (draws two consecutive vertical lines from top to bottom)

RAISE

/end/

User Jacopo
by
3.3k points