Draw a Box: Code

6.5. Draw a Box: Code#

Write a program that asks the user for an integer \(n\) and then prints a square box where the edges of the box are of length \(n\) (as shown in the examples below).

You should implement the algorithms you designed during the previous exercises by basing your code on the pseudocode.

Example 1: \(n=1\)

n: 1
+ - +
|   |
+ - +

Example 2: \(n=2\)

n: 2
+ - - +
|     |
|     |
+ - - +

Example 3: \(n=5\)

n: 5
+ - - - - - +
|           |
|           |
|           |
|           |
|           |
+ - - - - - +

Note:

  • There is a space between each - in the top and bottom edge. This means there are \(n\) dashes and \(n+1\) spaces between each + on the top and bottom edges, i.e. \(2n+1\) characters.

  • There are \(2n+1\) spaces between each | for the vertical edges.