Question: In the file Spirals / main . cpp , write a function Counting _ Spiral ( ) which generated a 2 D vector of
In the file "Spiralsmaincpp write a function CountingSpiral which generated a D vector of characters representing a spiral of numbers as show below.
The numbers will start at the center of the spiral and spiral outwards in the manner shown above.
The parameter length is the side length of the square and will always be an odd number, therefore there is always center.
The numbers will be modded by to ensure they are single digits.
Here is an example with length without the mod Not what your function should output
And here is the same example with the mod Desired Output
Here is what your vector indexes should look like for length
Algorithms
The starting point of every spiral is the in the center
Always initialize vectors to the final size of the spiral
You should assume youre done when you hit the bounds of the vectors
Use a xy plane to visualize the algorithms first
Focus on creating some small spirals x & x first
There are two algorithms to generate the spiral:
Imagine line segments spiraling out from the center. Each line segment bellow is identified by a different letter, and their direction rotates through the cardinal directions up down, left right Every segments the length increases by
h h h h g
i d d c g
i e a b g
i e f f f
i j j j j j
b right f right
c up g up
d left h left
e down i down
j right
Define bounds within the xy plane to create a small portion of the spiral fill it in and then increase the bounds by one in each direction and repeat. When filling in add numbers in a direction until you hit a bound, then change direction.
xxx
x x x x x x x x x x
x x x x x x x
x x x x x x NxN
x x x x x x x
x x x x x x x x x x
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
