Coding Practice

An image is just a matrix of pixels. Write the struct definition for Image, which should store information about its height and width and contain a matrix of Pixels. Select the Parsonsprob tab for hints for the construction of the code.

An image is just a matrix of pixels. Write the struct definition for Image, which should store information about its height and width and contain a matrix of Pixels. Use the lines to construct the code, then go back to complete the Activecode tab.

Now let’s print an Image. Unfortunately we can’t print out the actual image to the terminal, but we can print out the Pixels in the Image matrix. Write the Image member function printImage. Separate pixels in the same row with a space and add a new line at the end of each row. Use the printPixel function we created previously. Select the Parsonsprob tab for hints for the construction of the code.

Now let’s print an Image. Unfortunately we can’t print out the actual image to the terminal, but we can print out the Pixels in the Image matrix. Write the Image member function printImage. Separate pixels in the same row with a space and add a new line at the end of each row. Use the printPixel function we created previously. Use the lines to construct the code, then go back to complete the Activecode tab.

Let’s write a swapPixel member function for Image. swapPixel takes two pairs of row indices and column indices from a matrix and swaps the two Pixels at those locations. Note that these indices are 0-indexed, unlike the previous cropIndex parameters. Select the Parsonsprob tab for hints for the construction of the code.

Let’s write a swapPixel member function for Image. swapPixel takes two pairs of row indices and column indices from a matrix and swaps the two Pixels at those locations. Note that these indices are 0-indexed, unlike the previous cropIndex parameters. Use the lines to construct the code, then go back to complete the Activecode tab.

Oops! Somehow our image came out upside down. Let’s write the Image member function flipVertical, which reverts an image to be right side up. Select the Parsonsprob tab for hints for the construction of the code.

Oops! Somehow our image came out upside down. Let’s write the Image member function flipVertical, which reverts an image to be right side up. Use the lines to construct the code, then go back to complete the Activecode tab.

Let’s return our image to the state of a clean slate. Write the function clearImage, which sets the color of every Pixel to white. Select the Parsonsprob tab for hints for the construction of the code.

Let’s return our image to the state of a clean slate. Write the function clearImage, which sets the color of every Pixel to white. Use the lines to construct the code, then go back to complete the Activecode tab.

You have attempted of activities on this page