logo CodeStepByStep logo


Language/Type: C++ Grid collections
Related Links:
Author: Danielle Kain (on 2016/10/04)

Write a function named rotate that accepts accepts a reference to a grid of integers as a parameter and rotates the grid 90 degrees clockwise. You may assume the grid has the same number of rows as columns. For example, if a variable named g stored the grid below at left, the call of rotate(g); would alter it to give it the new grid state at right:

{{ 6,  1,  9,  4},             {{21, 14, -2,  6},
 {-2,  5,  8, 12},              {55, 39,  5,  1},
 {14, 39, -6, 18},     -->      {73, -6,  8,  9},
 {21, 55, 73, -3}}              {-3, 18, 12,  4}}
Type your solution here:

This is a function problem. Write a C++ function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.

© Marty Stepp, all rights reserved.